-
Notifications
You must be signed in to change notification settings - Fork 322
/
CMakeLists.txt
357 lines (309 loc) · 11.8 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
cmake_minimum_required (VERSION 3.13)
if (POLICY CMP0068)
cmake_policy(SET CMP0068 NEW)
endif ()
# Define file(GENERATE) behavior for relative paths.
if (POLICY CMP0070)
cmake_policy(SET CMP0070 NEW)
endif ()
# target_sources: use absolute path for INTERFACE_SOURCES.
if (POLICY CMP0076)
cmake_policy(SET CMP0076 NEW)
endif ()
# SWIG: use standard target name.
if (POLICY CMP0078)
cmake_policy(SET CMP0078 NEW)
endif ()
# SWIG: use SWIG_MODULE_NAME property.
if (POLICY CMP0086)
cmake_policy(SET CMP0086 NEW)
endif ()
list(APPEND CMAKE_MODULE_PATH
"${CMAKE_SOURCE_DIR}/cmake-modules"
"${CMAKE_SOURCE_DIR}/cmake")
project(openmldb)
if (CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif ()
if (NOT DEFINED CMAKE_PREFIX_PATH)
if (DEFINED ENV{THIRD_PARTY_DIR})
set(CMAKE_PREFIX_PATH $ENV{THIRD_PARTY_DIR})
else()
set(CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/.deps/usr")
endif()
endif()
message (STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")
message (STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
set(OPENMLDB_VERSION_MAJOR 0)
set(OPENMLDB_VERSION_MINOR 9)
set(OPENMLDB_VERSION_BUG 3)
function(get_commitid CODE_DIR COMMIT_ID)
find_package(Git REQUIRED)
execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:%h
OUTPUT_VARIABLE COMMIT_ID_TMP
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
WORKING_DIRECTORY
${CODE_DIR}
)
set("${COMMIT_ID}" ${COMMIT_ID_TMP} PARENT_SCOPE)
endfunction()
# strip the given target
function(strip_exe TARGET_NAME)
add_custom_command(TARGET ${TARGET_NAME} POST_BUILD
COMMAND ${CMAKE_STRIP}
ARGS $<TARGET_FILE:${TARGET_NAME}>)
endfunction()
get_commitid(${PROJECT_SOURCE_DIR} OPENMLDB_COMMIT_ID)
configure_file (
"${PROJECT_SOURCE_DIR}/src/version.h.in"
"${PROJECT_SOURCE_DIR}/src/version.h"
)
add_definitions('-g')
add_definitions('-Wall')
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
add_definitions(-Wreorder)
add_definitions(-Wno-unused-private-field)
add_definitions(-Wno-unused-function)
add_definitions(-Wno-overloaded-virtual)
add_definitions(-Wno-inconsistent-missing-override)
add_definitions(-Wno-deprecated-declarations)
add_definitions(-Wno-null-dereference)
add_definitions(-Wno-deprecated-register)
add_definitions(-Wno-c++17-extensions)
add_definitions(-Wno-defaulted-function-deleted)
add_definitions(-Wno-pessimizing-move)
add_definitions(-Wno-unused-value)
add_definitions(-Wno-\#pragma-messages)
endif ()
add_definitions(-DHAVE_STDBOOL_H=1)
# TODO(#1528): more strict flags
# Specifically enable checking null pointers for nonnull functions
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnonnull -Werror=nonnull")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
option(TESTING_ENABLE "Enable test" OFF)
option(TCMALLOC_ENABLE "Enable TCMALLOC" ON)
option(SQL_PYSDK_ENABLE "Enable sql pysdk" OFF)
option(SQL_JAVASDK_ENABLE "Enable sql javasdk" OFF)
option(INSTALL_CXXSDK "Enable sql cxxsdk install" OFF)
option(MAC_TABLET_ENABLE "Enable Table on Mac OS" ON)
option(COVERAGE_ENABLE "Enable Coverage" OFF)
option(COVERAGE_NO_DEPS "Coverage without test deps, should ensure test built" OFF)
option(SANITIZER_ENABLE "Enable AddressSanitizer in Debug mode" OFF)
# add_library can reply on this variable
# see https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html#variable:BUILD_SHARED_LIBS
option(BUILD_SHARED_LIBS "Enable build shared Libraries instead static" OFF)
option(TESTING_ENABLE_STRIP "Strip test binary that may help reduce storage space" OFF)
message (STATUS "MAC_TABLET_ENABLE: ${MAC_TABLET_ENABLE}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
if (MAC_TABLET_ENABLE)
add_compile_definitions(__mac_tablet__=1)
endif ()
set(SWIG_DIR ${CMAKE_PREFIX_PATH}/share/swig/4.0.1)
find_package(SWIG REQUIRED)
include(UseSWIG)
find_package(OpenSSL REQUIRED)
set(Protobuf_USE_STATIC_LIBS ON)
find_package(Protobuf 3.6 EXACT REQUIRED)
message(STATUS "Found Protobuf Libraries: ${Protobuf_LIBRARIES}")
find_library(UNWIND_LIBRARY unwind)
find_library(LEVELDB_LIBRARY leveldb)
find_library(Z_LIBRARY z)
find_library(SNAPPY_LIBRARY snappy)
find_package(RocksDB)
if (RocksDB_FOUND)
set(RocksDB_LIB RocksDB::rocksdb)
else()
find_library(RocksDB_LIBRARY rocksdb)
set(RocksDB_LIB ${RocksDB_LIBRARY})
endif()
set(FETCHCONTENT_QUIET OFF)
# contrib libs
add_subdirectory(contrib EXCLUDE_FROM_ALL)
if (BUILD_SHARED_LIBS)
# For shared build, gflags/glog requires shared lib,
# in case runtime problem arrise from java, a common issue is #3407:
# > ERROR: something wrong with flag 'logtostderr' in file 'src/logging.cc'. One possibility: file 'src/logging.cc' is being linked both statically and dynamically into this executable.
set(GLOG_LIBRARY glog::glog)
get_target_property(gflags_real gflags::gflags ALIASED_TARGET)
message(STATUS "link with gflags library: ${gflags_real}")
set(GFLAGS_LIBRARY gflags::gflags)
else()
# 'CONFIG' is mandatory: pre-compiled thirdparty skip a Findgflags.cmake not work well
find_package(gflags REQUIRED COMPONENTS static CONFIG)
set(GFLAGS_LIBRARY ${gflags_LIBRARIES})
find_library(GLOG_LIBRARY NAMES libglog.a REQUIRED)
endif()
find_library(BRPC_LIBRARY NAMES libbrpc.a REQUIRED)
message(STATUS "Found GFLAGS LIBRARY: ${GFLAGS_LIBRARY}")
message(STATUS "Found GLOG LIBRARY: ${GLOG_LIBRARY}")
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(OS_LIB ${CMAKE_THREAD_LIBS_INIT} rt)
set(BRPC_LIBS ${BRPC_LIBRARY} ${Protobuf_LIBRARIES} ${GLOG_LIBRARY} ${GFLAGS_LIBRARY} ${UNWIND_LIBRARY} ${OPENSSL_LIBRARIES} ${LEVELDB_LIBRARY} ${Z_LIBRARY} ${SNAPPY_LIBRARY} dl pthread ${OS_LIB})
elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(OS_LIB
${CMAKE_THREAD_LIBS_INIT}
"-framework CoreFoundation"
"-framework CoreGraphics"
"-framework CoreData"
"-framework CoreText"
"-framework Security"
"-framework Foundation"
"-Wl,-U,_MallocExtension_ReleaseFreeMemory"
"-Wl,-U,_ProfilerStart"
"-Wl,-U,_ProfilerStop")
set(BRPC_LIBS ${BRPC_LIBRARY} ${Protobuf_LIBRARIES} ${GLOG_LIBRARY} ${GFLAGS_LIBRARY} ${OPENSSL_LIBRARIES} ${LEVELDB_LIBRARY} ${Z_LIBRARY} ${SNAPPY_LIBRARY} dl pthread ${OS_LIB})
endif ()
if (SANITIZER_ENABLE)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
message(STATUS "Enabled AddressSanitizer")
endif()
# add default option to ctest
# - --output-on-failure: print log for tests that fail
list(APPEND CMAKE_CTEST_ARGUMENTS --output-on-failure)
if (TESTING_ENABLE)
enable_testing()
endif ()
set(test_list "")
if (COVERAGE_ENABLE)
if (NOT CMAKE_COMPILER_IS_GNUCXX)
message(FATAL_ERROR "Coverage is only supported on linux")
endif ()
find_program(LCOV_EXE NAMES lcov DOC "coverage requires lcov installed" REQUIRED)
message(STATUS "include CodeCoverage, if file not found, please git submodule update --init to get file")
include(CodeCoverage)
APPEND_COVERAGE_COMPILER_FLAGS()
endif ()
if (DEFINED ENV{CI})
# suppress useless maven log (e.g download log) on CI environment
set(MAVEN_FLAGS --batch-mode)
endif()
add_subdirectory(hybridse)
set(Boost_NO_BOOST_CMAKE ON)
set(BOOST_ROOT "${CMAKE_PREFIX_PATH}")
find_package(Boost COMPONENTS filesystem date_time regex REQUIRED)
set(VM_LIBS hybridse_sdk hybridse_core ${Boost_LIBRARIES})
set(LLVM_DIR "${CMAKE_PREFIX_PATH}/lib/cmake/llvm")
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
llvm_map_components_to_libnames(LLVM_LIBS support core irreader orcjit nativecodegen)
message(STATUS "Using LLVM components: ${LLVM_LIBS}")
add_definitions(${LLVM_DEFINITIONS})
find_package(absl REQUIRED)
# modify absl::time_zone INTERFACE_LINK_LIBRARIES
set_target_properties(absl::time_zone PROPERTIES INTERFACE_LINK_LIBRARIES "\$<\$<PLATFORM_ID:Darwin>:-framework CoreFoundation>")
find_package(GTest REQUIRED)
# TODO(hw): dup with hybridse root cmake, need cleanup
list(
APPEND
ABSL_LIBS
absl::algorithm
absl::base
absl::cord
absl::debugging
absl::flat_hash_map
absl::flags
absl::flags_parse
absl::memory
absl::meta
absl::numeric
absl::random_random
absl::strings
absl::strings_internal
absl::str_format
absl::synchronization
absl::time
absl::status
absl::statusor)
find_package(ICU COMPONENTS i18n io uc data)
if (NOT ICU_FOUND)
message(STATUS "ICU find_package failed, try to use `find_library()` to find")
find_library(ICU_I18N icui18n)
find_library(ICU_IO icuio)
find_library(ICU_UC icuuc)
find_library(ICU_DATA icudata)
set(ICU_LIBRARIES ${ICU_I18N} ${ICU_IO} ${ICU_UC} ${ICU_DATA})
endif ()
message(STATUS "Found ICU Libraries: ${ICU_LIBRARIES}")
find_library(zetasql_LIB zetasql)
find_library(re2_LIB re2)
set(ZETASQL_LIBS
${zetasql_LIB}
${ABSL_LIBS}
${re2_LIB}
${ICU_LIBRARIES}
)
find_library(zookeeper_mt_LIB zookeeper_mt)
if (TCMALLOC_ENABLE)
set(CMAKE_EXE_LINKER_FLAGS "-fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free ${CMAKE_EXE_LINKER_FLAGS}")
endif()
configure_file(
"${PROJECT_SOURCE_DIR}/src/config.h.in"
"${PROJECT_SOURCE_DIR}/src/config.h")
include_directories(
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/hybridse/include
${CMAKE_SOURCE_DIR}/hybridse/src
${CMAKE_BINARY_DIR}/hybridse/src
${LLVM_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
${CMAKE_PREFIX_PATH}/include
${PROJECT_SOURCE_DIR}/contrib/rapidjson/include
)
link_directories(
${LLVM_LIBRARY_DIRS}
${Boost_LIBRARY_DIRS}
${CMAKE_PREFIX_PATH}/lib
${CMAKE_PREFIX_PATH}/lib64)
add_subdirectory(src)
if (COVERAGE_ENABLE AND CMAKE_COMPILER_IS_GNUCXX)
if (COVERAGE_NO_DEPS)
SETUP_TARGET_FOR_COVERAGE_LCOV(NAME coverage
EXECUTABLE ctest --force-new-ctest-process --output-on-failure -E "api_server_test")
else ()
# FIXME(aceforeverd): api_server_test failed to run on debug mode, skip temporarily
SETUP_TARGET_FOR_COVERAGE_LCOV(NAME coverage
EXECUTABLE ctest --force-new-ctest-process --output-on-failure -E "api_server_test"
DEPENDENCIES ${test_list})
endif ()
endif ()
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
# CMAKE_INSTALL_PREFIX default to /usr/local on unix.
# At current phase we'd like to change it to a customized directory by default
set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/openmldb" CACHE PATH "OpenMLDB install directory" FORCE)
endif()
message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
FILE(GLOB OPENMLDB_BINS "${CMAKE_SOURCE_DIR}/release/bin/*")
FILE(GLOB OPENMLDB_SBINS "${CMAKE_SOURCE_DIR}/release/sbin/*")
FILE(GLOB OPENMLDB_CONFS "${CMAKE_SOURCE_DIR}/release/conf/*")
set(OPENMLDB_TOOLS "${CMAKE_SOURCE_DIR}/tools/")
install(
FILES ${OPENMLDB_BINS}
TYPE BIN
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ
)
install(
FILES ${OPENMLDB_SBINS}
DESTINATION sbin
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ
)
install(FILES ${OPENMLDB_CONFS} DESTINATION conf)
install(
DIRECTORY ${OPENMLDB_TOOLS}
DESTINATION tools
FILE_PERMISSIONS
OWNER_READ OWNER_EXECUTE OWNER_WRITE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
DIRECTORY_PERMISSIONS
OWNER_READ OWNER_EXECUTE OWNER_WRITE
GROUP_READ GROUP_EXECUTE GROUP_WRITE
WORLD_READ WORLD_EXECUTE
)
install(DIRECTORY DESTINATION udf)