cloudflare/ClickHouse
Publicmirrored fromhttps://github.com/cloudflare/ClickHouse
dbms/CMakeLists.txt
248lines · modecode
| 1 | if (USE_INCLUDE_WHAT_YOU_USE) |
| 2 | set (CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${IWYU_PATH}) |
| 3 | endif () |
| 4 | |
| 5 | include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/find_vectorclass.cmake) |
| 6 | |
| 7 | set (CONFIG_VERSION ${CMAKE_CURRENT_BINARY_DIR}/src/Common/config_version.h) |
| 8 | set (CONFIG_COMMON ${CMAKE_CURRENT_BINARY_DIR}/src/Common/config.h) |
| 9 | set (CONFIG_BUILD ${CMAKE_CURRENT_BINARY_DIR}/src/Common/config_build.cpp) |
| 10 | |
| 11 | include (cmake/version.cmake) |
| 12 | message (STATUS "Will build ${VERSION_FULL}") |
| 13 | configure_file (${CMAKE_CURRENT_SOURCE_DIR}/src/Common/config.h.in ${CONFIG_COMMON}) |
| 14 | configure_file (${CMAKE_CURRENT_SOURCE_DIR}/src/Common/config_version.h.in ${CONFIG_VERSION}) |
| 15 | |
| 16 | get_property (BUILD_COMPILE_DEFINITIONS DIRECTORY ${ClickHouse_SOURCE_DIR} PROPERTY COMPILE_DEFINITIONS) |
| 17 | get_property (BUILD_INCLUDE_DIRECTORIES DIRECTORY ${ClickHouse_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES) |
| 18 | string (TIMESTAMP BUILD_DATE "%Y-%m-%d" UTC) |
| 19 | configure_file (${CMAKE_CURRENT_SOURCE_DIR}/src/Common/config_build.cpp.in ${CONFIG_BUILD}) |
| 20 | |
| 21 | if (NOT MSVC) |
| 22 | set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra") |
| 23 | endif () |
| 24 | |
| 25 | if (NOT NO_WERROR) |
| 26 | set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") |
| 27 | set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") |
| 28 | endif () |
| 29 | |
| 30 | find_package (Threads) |
| 31 | |
| 32 | add_subdirectory (src) |
| 33 | |
| 34 | set(dbms_headers) |
| 35 | set(dbms_sources) |
| 36 | |
| 37 | include(${ClickHouse_SOURCE_DIR}/cmake/dbms_glob_sources.cmake) |
| 38 | |
| 39 | add_headers_and_sources(clickhouse_common_io src/Common) |
| 40 | add_headers_and_sources(clickhouse_common_io src/Common/HashTable) |
| 41 | add_headers_and_sources(clickhouse_common_io src/IO) |
| 42 | |
| 43 | add_headers_and_sources(dbms src/Analyzers) |
| 44 | add_headers_and_sources(dbms src/Core) |
| 45 | add_headers_and_sources(dbms src/DataStreams) |
| 46 | add_headers_and_sources(dbms src/DataTypes) |
| 47 | add_headers_and_sources(dbms src/Databases) |
| 48 | add_headers_and_sources(dbms src/Dictionaries) |
| 49 | add_headers_and_sources(dbms src/Dictionaries/Embedded) |
| 50 | add_headers_and_sources(dbms src/Dictionaries/Embedded/GeodataProviders) |
| 51 | add_headers_and_sources(dbms src/Interpreters) |
| 52 | add_headers_and_sources(dbms src/Interpreters/ClusterProxy) |
| 53 | add_headers_and_sources(dbms src/Columns) |
| 54 | add_headers_and_sources(dbms src/Storages) |
| 55 | add_headers_and_sources(dbms src/Storages/Distributed) |
| 56 | add_headers_and_sources(dbms src/Storages/MergeTree) |
| 57 | add_headers_and_sources(dbms src/Client) |
| 58 | add_headers_only(dbms src/Server) |
| 59 | |
| 60 | list (APPEND clickhouse_common_io_sources ${CONFIG_BUILD}) |
| 61 | list (APPEND clickhouse_common_io_headers ${CONFIG_VERSION} ${CONFIG_COMMON}) |
| 62 | |
| 63 | list (APPEND dbms_sources src/Functions/IFunction.cpp src/Functions/FunctionFactory.cpp src/Functions/FunctionHelpers.cpp) |
| 64 | list (APPEND dbms_headers src/Functions/IFunction.h src/Functions/FunctionFactory.h src/Functions/FunctionHelpers.h) |
| 65 | |
| 66 | list (APPEND dbms_sources |
| 67 | src/AggregateFunctions/AggregateFunctionFactory.cpp |
| 68 | src/AggregateFunctions/AggregateFunctionCombinatorFactory.cpp |
| 69 | src/AggregateFunctions/AggregateFunctionState.cpp |
| 70 | src/AggregateFunctions/FactoryHelpers.cpp |
| 71 | src/AggregateFunctions/parseAggregateFunctionParameters.cpp) |
| 72 | |
| 73 | list (APPEND dbms_headers |
| 74 | src/AggregateFunctions/IAggregateFunction.h |
| 75 | src/AggregateFunctions/IAggregateFunctionCombinator.h |
| 76 | src/AggregateFunctions/AggregateFunctionFactory.h |
| 77 | src/AggregateFunctions/AggregateFunctionCombinatorFactory.h |
| 78 | src/AggregateFunctions/AggregateFunctionState.h |
| 79 | src/AggregateFunctions/FactoryHelpers.h |
| 80 | src/AggregateFunctions/parseAggregateFunctionParameters.h) |
| 81 | |
| 82 | list (APPEND dbms_sources src/TableFunctions/ITableFunction.cpp src/TableFunctions/TableFunctionFactory.cpp) |
| 83 | list (APPEND dbms_headers src/TableFunctions/ITableFunction.h src/TableFunctions/TableFunctionFactory.h) |
| 84 | |
| 85 | add_library(clickhouse_common_io ${SPLIT_SHARED} ${clickhouse_common_io_headers} ${clickhouse_common_io_sources}) |
| 86 | |
| 87 | if (ARCH_FREEBSD) |
| 88 | target_compile_definitions (clickhouse_common_io PUBLIC CLOCK_MONOTONIC_COARSE=CLOCK_MONOTONIC_FAST) |
| 89 | endif () |
| 90 | |
| 91 | add_subdirectory(src/Common/ZooKeeper) |
| 92 | add_subdirectory(src/Common/Config) |
| 93 | |
| 94 | if (MAKE_STATIC_LIBRARIES) |
| 95 | add_library(dbms ${dbms_headers} ${dbms_sources}) |
| 96 | else () |
| 97 | add_library(dbms SHARED ${dbms_headers} ${dbms_sources}) |
| 98 | set_target_properties (dbms PROPERTIES SOVERSION ${VERSION_MAJOR} VERSION ${VERSION_SO} OUTPUT_NAME clickhouse) |
| 99 | install (TARGETS dbms LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT clickhouse) |
| 100 | endif () |
| 101 | |
| 102 | |
| 103 | if (CMAKE_BUILD_TYPE_UC STREQUAL "RELEASE" OR CMAKE_BUILD_TYPE_UC STREQUAL "RELWITHDEBINFO" OR CMAKE_BUILD_TYPE_UC STREQUAL "MINSIZEREL") |
| 104 | # Won't generate debug info for files with heavy template instantiation to achieve faster linking and lower size. |
| 105 | set_source_files_properties( |
| 106 | src/Dictionaries/FlatDictionary.cpp |
| 107 | src/Dictionaries/HashedDictionary.cpp |
| 108 | src/Dictionaries/CacheDictionary.cpp |
| 109 | src/Dictionaries/TrieDictionary.cpp |
| 110 | src/Dictionaries/RangeHashedDictionary.cpp |
| 111 | src/Dictionaries/ComplexKeyHashedDictionary.cpp |
| 112 | src/Dictionaries/ComplexKeyCacheDictionary.cpp |
| 113 | src/Dictionaries/ComplexKeyCacheDictionary_generate1.cpp |
| 114 | src/Dictionaries/ComplexKeyCacheDictionary_generate2.cpp |
| 115 | src/Dictionaries/ComplexKeyCacheDictionary_generate3.cpp |
| 116 | src/Dictionaries/ODBCBlockInputStream.cpp |
| 117 | src/Dictionaries/HTTPDictionarySource.cpp |
| 118 | src/Dictionaries/LibraryDictionarySource.cpp |
| 119 | src/Dictionaries/ExecutableDictionarySource.cpp |
| 120 | src/Dictionaries/ClickHouseDictionarySource.cpp |
| 121 | PROPERTIES COMPILE_FLAGS -g0) |
| 122 | endif () |
| 123 | |
| 124 | if (NOT ARCH_ARM) |
| 125 | set (LINK_LIBRARIES_ONLY_ON_X86_64 cpuid) |
| 126 | endif() |
| 127 | |
| 128 | target_link_libraries (clickhouse_common_io |
| 129 | common |
| 130 | string_utils |
| 131 | ${LINK_LIBRARIES_ONLY_ON_X86_64} |
| 132 | ${LZ4_LIBRARY} |
| 133 | ${ZSTD_LIBRARY} |
| 134 | ${ZOOKEEPER_LIBRARY} |
| 135 | ${DOUBLE_CONVERSION_LIBRARIES} |
| 136 | ${Poco_Net_LIBRARY} |
| 137 | ${Poco_Data_LIBRARY} |
| 138 | ${ZLIB_LIBRARIES} |
| 139 | ${EXECINFO_LIBRARY} |
| 140 | ${Boost_SYSTEM_LIBRARY} |
| 141 | ${CMAKE_DL_LIBS} |
| 142 | ) |
| 143 | |
| 144 | target_link_libraries (dbms |
| 145 | clickhouse_parsers |
| 146 | clickhouse_common_config |
| 147 | clickhouse_common_io |
| 148 | ${MYSQLXX_LIBRARY} |
| 149 | ${FARMHASH_LIBRARIES} |
| 150 | ${METROHASH_LIBRARIES} |
| 151 | ${RE2_LIBRARY} |
| 152 | ${RE2_ST_LIBRARY} |
| 153 | ${OPENSSL_CRYPTO_LIBRARY} |
| 154 | ${BTRIE_LIBRARIES} |
| 155 | ) |
| 156 | |
| 157 | if (NOT USE_INTERNAL_RE2_LIBRARY) |
| 158 | target_include_directories (dbms BEFORE PRIVATE ${RE2_INCLUDE_DIR}) |
| 159 | endif () |
| 160 | |
| 161 | if (NOT USE_INTERNAL_ZOOKEEPER_LIBRARY) |
| 162 | target_include_directories (clickhouse_common_io BEFORE PUBLIC ${ZOOKEEPER_INCLUDE_DIR}) |
| 163 | endif () |
| 164 | |
| 165 | if (NOT USE_INTERNAL_BOOST_LIBRARY) |
| 166 | target_include_directories (clickhouse_common_io BEFORE PUBLIC ${Boost_INCLUDE_DIRS}) |
| 167 | endif () |
| 168 | |
| 169 | if (Poco_DataODBC_FOUND) |
| 170 | target_link_libraries (dbms ${Poco_DataODBC_LIBRARY}) |
| 171 | target_include_directories (dbms PRIVATE ${ODBC_INCLUDE_DIRECTORIES}) |
| 172 | endif() |
| 173 | |
| 174 | if (Poco_MongoDB_FOUND) |
| 175 | target_link_libraries (dbms ${Poco_MongoDB_LIBRARY}) |
| 176 | endif() |
| 177 | |
| 178 | if (Poco_NetSSL_FOUND) |
| 179 | target_link_libraries (clickhouse_common_io ${Poco_NetSSL_LIBRARY}) |
| 180 | endif() |
| 181 | |
| 182 | target_link_libraries (dbms ${Poco_Foundation_LIBRARY}) |
| 183 | |
| 184 | if (USE_ICU) |
| 185 | target_link_libraries (dbms ${ICU_LIBS}) |
| 186 | target_include_directories (dbms PRIVATE ${ICU_INCLUDE_DIR}) |
| 187 | endif () |
| 188 | |
| 189 | if (USE_CAPNP) |
| 190 | target_link_libraries (dbms ${CAPNP_LIBRARY}) |
| 191 | if (NOT USE_INTERNAL_CAPNP_LIBRARY) |
| 192 | target_include_directories (dbms BEFORE PRIVATE ${CAPNP_INCLUDE_DIR}) |
| 193 | endif () |
| 194 | endif () |
| 195 | |
| 196 | if (USE_RDKAFKA) |
| 197 | target_link_libraries (dbms ${RDKAFKA_LIBRARY}) |
| 198 | if (NOT USE_INTERNAL_RDKAFKA_LIBRARY) |
| 199 | target_include_directories (dbms BEFORE PRIVATE ${RDKAFKA_INCLUDE_DIR}) |
| 200 | endif () |
| 201 | endif () |
| 202 | |
| 203 | target_link_libraries (dbms |
| 204 | Threads::Threads |
| 205 | ) |
| 206 | |
| 207 | target_include_directories (dbms BEFORE PRIVATE ${DIVIDE_INCLUDE_DIR}) |
| 208 | target_include_directories (dbms BEFORE PRIVATE ${SPARCEHASH_INCLUDE_DIR}) |
| 209 | |
| 210 | if (NOT USE_INTERNAL_LZ4_LIBRARY) |
| 211 | target_include_directories (dbms BEFORE PRIVATE ${LZ4_INCLUDE_DIR}) |
| 212 | endif () |
| 213 | if (NOT USE_INTERNAL_ZSTD_LIBRARY) |
| 214 | target_include_directories (dbms BEFORE PRIVATE ${ZSTD_INCLUDE_DIR}) |
| 215 | endif () |
| 216 | |
| 217 | target_include_directories (dbms PUBLIC ${DBMS_INCLUDE_DIR}) |
| 218 | target_include_directories (clickhouse_common_io PUBLIC ${DBMS_INCLUDE_DIR}) |
| 219 | target_include_directories (clickhouse_common_io PUBLIC ${PCG_RANDOM_INCLUDE_DIR}) |
| 220 | target_include_directories (clickhouse_common_io BEFORE PUBLIC ${DOUBLE_CONVERSION_INCLUDE_DIR}) |
| 221 | |
| 222 | # also for copy_headers.sh: |
| 223 | target_include_directories (clickhouse_common_io BEFORE PRIVATE ${COMMON_INCLUDE_DIR}) |
| 224 | |
| 225 | add_subdirectory (tests) |
| 226 | |
| 227 | if (ENABLE_TESTS) |
| 228 | include (${ClickHouse_SOURCE_DIR}/cmake/find_gtest.cmake) |
| 229 | |
| 230 | if (USE_INTERNAL_GTEST_LIBRARY) |
| 231 | # Google Test from sources |
| 232 | add_subdirectory(${ClickHouse_SOURCE_DIR}/contrib/googletest/googletest ${CMAKE_CURRENT_BINARY_DIR}/googletest) |
| 233 | # avoid problems with <regexp.h> |
| 234 | target_compile_definitions (gtest INTERFACE GTEST_HAS_POSIX_RE=0) |
| 235 | target_include_directories (gtest INTERFACE ${ClickHouse_SOURCE_DIR}/contrib/googletest/include) |
| 236 | endif () |
| 237 | |
| 238 | macro(grep_gtest_sources BASE_DIR DST_VAR) |
| 239 | # Cold match files that are not in tests/ directories |
| 240 | file(GLOB_RECURSE "${DST_VAR}" RELATIVE "${BASE_DIR}" "gtest*.cpp") |
| 241 | endmacro() |
| 242 | |
| 243 | # attach all dbms gtest sources |
| 244 | grep_gtest_sources(${ClickHouse_SOURCE_DIR}/dbms dbms_gtest_sources) |
| 245 | add_executable(unit_tests_dbms ${dbms_gtest_sources}) |
| 246 | target_link_libraries(unit_tests_dbms gtest_main dbms) |
| 247 | add_check(unit_tests_dbms) |
| 248 | endif () |