Skip to content

Commit 555077f

Browse files
authored
build: support generate project with cmake 3.18 (#1885)
* fix(#1374): support build over cmake 3.18 * fix(#1091): move proto gen file into build/src/proto
1 parent 4cda032 commit 555077f

File tree

3 files changed

+32
-18
lines changed

3 files changed

+32
-18
lines changed

CMakeLists.txt

+8-7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ project(openmldb)
2626
if (CMAKE_BUILD_TYPE STREQUAL "")
2727
set(CMAKE_BUILD_TYPE RelWithDebInfo)
2828
endif ()
29+
30+
if (NOT DEFINED CMAKE_PREFIX_PATH)
31+
set(CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/.deps/usr")
32+
endif()
33+
2934
message (STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
3035
set(OPENMLDB_VERSION_MAJOR 0)
3136
set(OPENMLDB_VERSION_MINOR 5)
@@ -49,7 +54,6 @@ configure_file (
4954
"${PROJECT_SOURCE_DIR}/src/version.h.in"
5055
"${PROJECT_SOURCE_DIR}/src/version.h"
5156
)
52-
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
5357
add_definitions('-g')
5458
add_definitions('-Wall')
5559
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
@@ -90,9 +94,9 @@ if (MAC_TABLET_ENABLE)
9094
add_compile_definitions(__mac_tablet__=1)
9195
endif ()
9296

93-
if (NOT DEFINED CMAKE_PREFIX_PATH)
94-
set(CMAKE_PREFIX_PATH ${CMAKE_SOURCE_DIR}/.deps/usr)
95-
endif()
97+
set(SWIG_DIR ${CMAKE_PREFIX_PATH}/share/swig/4.0.1)
98+
find_package(SWIG REQUIRED)
99+
include(UseSWIG)
96100

97101
find_package(OpenSSL REQUIRED)
98102
find_library(BRPC_LIBRARY brpc)
@@ -178,9 +182,6 @@ llvm_map_components_to_libnames(LLVM_LIBS support core orcjit nativecodegen)
178182
message(STATUS "Using LLVM components: ${LLVM_LIBS}")
179183
add_definitions(${LLVM_DEFINITIONS})
180184

181-
set(SWIG_DIR ${CMAKE_PREFIX_PATH}/share/swig/4.0.1)
182-
find_package(SWIG REQUIRED)
183-
include(UseSWIG)
184185
find_package(absl REQUIRED)
185186
# modify absl::time_zone INTERFACE_LINK_LIBRARIES
186187
set_target_properties(absl::time_zone PROPERTIES INTERFACE_LINK_LIBRARIES "\$<\$<PLATFORM_ID:Darwin>:-framework CoreFoundation>")

hybridse/CMakeLists.txt

+11-5
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ option(BENCHMARK_ENABLE "Enable Benchmark" OFF)
4747
option(EXAMPLES_ENABLE "Enable examples" ON)
4848
option(LLVM_EXT_ENABLE "Enable llvm ext sources" OFF)
4949

50-
set(DEPS_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/.deps/usr" CACHE PATH "Path prefix for finding dependencies")
5150
if (NOT DEFINED CMAKE_PREFIX_PATH)
52-
set(CMAKE_PREFIX_PATH ${DEPS_PREFIX})
51+
set(CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/.deps/usr")
5352
endif()
5453

5554
if (CMAKE_BUILD_TYPE STREQUAL "")
@@ -62,7 +61,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
6261
set(CMAKE_CXX_EXTENSIONS OFF)
6362
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
6463

65-
set(SWIG_DIR ${CMAKE_PREFIX_PATH}/share/swig/4.0.1)
6664
# llvm dependency
6765
if (NOT DEFINED LLVM_DIR)
6866
set(LLVM_DIR "${CMAKE_PREFIX_PATH}/lib/cmake/llvm")
@@ -162,8 +160,16 @@ set(yaml_libs yaml-cpp)
162160

163161
add_definitions('-g')
164162
add_definitions(${LLVM_DEFINITIONS})
165-
find_package(SWIG REQUIRED)
166-
include(UseSWIG)
163+
164+
# parent project may already found swig, skip if so.
165+
# the check is added because the find may failed on cmake < 3.20
166+
if (NOT SWIG_FOUND)
167+
set(SWIG_DIR ${CMAKE_PREFIX_PATH}/share/swig/4.0.1)
168+
find_package(SWIG REQUIRED)
169+
include(UseSWIG)
170+
else()
171+
message(STATUS "SWIG already found: ${SWIG_EXECUTABLE}:${SWIG_VERSION}")
172+
endif()
167173

168174
include_directories(
169175
${PROJECT_SOURCE_DIR}/../include

src/CMakeLists.txt

+13-6
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,28 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
include_directories(${INCLUDE_DIRECTORIES} ${PROJECT_SOURCE_DIR}/src)
15+
include_directories(
16+
${INCLUDE_DIRECTORIES}
17+
${PROJECT_SOURCE_DIR}/src
18+
${CMAKE_BINARY_DIR}/src)
1619

1720
add_subdirectory(statistics)
1821

22+
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/src/proto)
23+
24+
set(PROTO_FILES "")
1925
function(compile_proto proto_name project_dir)
20-
add_custom_command(OUTPUT ${project_dir}/src/proto/${proto_name}.pb.cc
26+
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/src/proto/${proto_name}.pb.cc
2127
COMMAND ${Protobuf_PROTOC_EXECUTABLE} -I ${PROJECT_SOURCE_DIR}/src/proto
22-
--cpp_out=${project_dir}/src/proto/
28+
--cpp_out=${CMAKE_BINARY_DIR}/src/proto
2329
--java_out=${project_dir}/java/openmldb-native/src/main/java
2430
--java_out=${project_dir}/java/openmldb-import/src/main/java
2531
--java_out=${project_dir}/java/openmldb-taskmanager/src/main/java
2632
--java_out=${project_dir}/java/openmldb-common/src/main/java
2733
${project_dir}/src/proto/${proto_name}.proto
28-
DEPENDS ${project_dir}/src/proto/${proto_name}.proto
29-
)
34+
DEPENDS ${project_dir}/src/proto/${proto_name}.proto)
35+
list(APPEND PROTO_FILES ${CMAKE_BINARY_DIR}/src/proto/${proto_name}.pb.cc)
36+
set(PROTO_FILES ${PROTO_FILES} PARENT_SCOPE)
3037
endfunction(compile_proto)
3138

3239
function(compile_lib LIB_NAME DIR DEPEND_FILE_LIST)
@@ -103,7 +110,7 @@ compile_lib(log log "flags.cc")
103110
compile_lib(openmldb_sdk sdk "")
104111
compile_lib(apiserver apiserver "")
105112

106-
add_library(openmldb_proto STATIC proto/type.pb.cc proto/common.pb.cc proto/tablet.pb.cc proto/name_server.pb.cc proto/sql_procedure.pb.cc proto/api_server.pb.cc proto/taskmanager.pb.cc proto/name_server.pb.cc)
113+
add_library(openmldb_proto STATIC ${PROTO_FILES})
107114

108115
add_library(openmldb_flags STATIC flags.cc)
109116

0 commit comments

Comments
 (0)