CMakeLists.txt 19.4 KB
Newer Older
H
Hongze Cheng 已提交
1 2 3
# ================================================================================================
# Download
# ================================================================================================
H
Hongze Cheng 已提交
4 5 6 7 8 9
function(cat IN_FILE OUT_FILE)
    file(READ ${IN_FILE} CONTENTS)
    file(APPEND ${OUT_FILE} "${CONTENTS}")
endfunction(cat IN_FILE OUT_FILE)

set(CONTRIB_TMP_FILE "${CMAKE_BINARY_DIR}/deps_tmp_CMakeLists.txt.in")
wafwerar's avatar
wafwerar 已提交
10
configure_file("${TD_SUPPORT_DIR}/deps_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
H
Hongze Cheng 已提交
11

12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
# taos-tools
if(${BUILD_TOOLS})
    cat("${TD_SUPPORT_DIR}/taostools_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
endif()

# taosws-rs
if(${WEBSOCKET})
    cat("${TD_SUPPORT_DIR}/taosws_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
endif()

# taosadapter
if(${BUILD_HTTP})
    MESSAGE("BUILD_HTTP is on")
else ()
    MESSAGE("BUILD_HTTP is off, use taosAdapter")
    cat("${TD_SUPPORT_DIR}/taosadapter_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
endif()

30 31
# pthread
if(${BUILD_PTHREAD})
wafwerar's avatar
wafwerar 已提交
32
    cat("${TD_SUPPORT_DIR}/pthread_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
33 34
endif()

35 36 37 38 39
# iconv
if(${BUILD_WITH_ICONV})
    cat("${TD_SUPPORT_DIR}/iconv_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
endif()

wafwerar's avatar
wafwerar 已提交
40 41 42 43 44
# jemalloc
if(${JEMALLOC_ENABLED})
    cat("${TD_SUPPORT_DIR}/jemalloc_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
endif()

45 46 47 48 49 50 51 52 53 54 55 56 57
# msvc regex
if(${BUILD_MSVCREGEX})
    cat("${TD_SUPPORT_DIR}/msvcregex_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
endif()

# wcwidth
if(${BUILD_WCWIDTH})
    cat("${TD_SUPPORT_DIR}/wcwidth_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
endif()

# wingetopt
if(${BUILD_WINGETOPT})
    cat("${TD_SUPPORT_DIR}/wingetopt_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
58 59
endif()

H
Hongze Cheng 已提交
60
# googletest
H
Hongze Cheng 已提交
61
if(${BUILD_TEST})
wafwerar's avatar
wafwerar 已提交
62 63
    cat("${TD_SUPPORT_DIR}/gtest_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
    cat("${TD_SUPPORT_DIR}/stub_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
H
Hongze Cheng 已提交
64 65
endif(${BUILD_TEST})

H
Hongze Cheng 已提交
66
# lz4
wafwerar's avatar
wafwerar 已提交
67
cat("${TD_SUPPORT_DIR}/lz4_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
H
Hongze Cheng 已提交
68

H
Hongze Cheng 已提交
69
# zlib
wafwerar's avatar
wafwerar 已提交
70
cat("${TD_SUPPORT_DIR}/zlib_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
H
Hongze Cheng 已提交
71

H
Hongze Cheng 已提交
72
# cJson
wafwerar's avatar
wafwerar 已提交
73
cat("${TD_SUPPORT_DIR}/cjson_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
H
Hongze Cheng 已提交
74

H
Hongze Cheng 已提交
75
# leveldb
H
Hongze Cheng 已提交
76
if(${BUILD_WITH_LEVELDB})
wafwerar's avatar
wafwerar 已提交
77
    cat("${TD_SUPPORT_DIR}/leveldb_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
H
Hongze Cheng 已提交
78 79
endif(${BUILD_WITH_LEVELDB})

D
dapan1121 已提交
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
if (${BUILD_CONTRIB})
    if(${BUILD_WITH_ROCKSDB})
        cat("${TD_SUPPORT_DIR}/rocksdb_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
        add_definitions(-DUSE_ROCKSDB)
    endif()
else() 
    if (NOT ${TD_LINUX})
        if(${BUILD_WITH_ROCKSDB})
            cat("${TD_SUPPORT_DIR}/rocksdb_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
            add_definitions(-DUSE_ROCKSDB)
        endif(${BUILD_WITH_ROCKSDB})
    else()
        if(${BUILD_WITH_ROCKSDB})
            add_definitions(-DUSE_ROCKSDB)
        endif(${BUILD_WITH_ROCKSDB})
    endif()
endif()
H
Hongze Cheng 已提交
97

M
Minghao Li 已提交
98 99
# canonical-raft
if(${BUILD_WITH_CRAFT})
wafwerar's avatar
wafwerar 已提交
100
    cat("${TD_SUPPORT_DIR}/craft_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
H
Hongze Cheng 已提交
101
    SET(BUILD_WITH_UV ON CACHE BOOL "craft need libuv" FORCE)
M
Minghao Li 已提交
102 103
endif(${BUILD_WITH_CRAFT})

M
Minghao Li 已提交
104 105
# traft
if(${BUILD_WITH_TRAFT})
wafwerar's avatar
wafwerar 已提交
106
    cat("${TD_SUPPORT_DIR}/traft_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
M
Minghao Li 已提交
107 108 109
    SET(BUILD_WITH_UV ON CACHE BOOL "traft need libuv" FORCE)
endif(${BUILD_WITH_TRAFT})

H
Hongze Cheng 已提交
110 111
#libuv
if(${BUILD_WITH_UV})
wafwerar's avatar
wafwerar 已提交
112
    cat("${TD_SUPPORT_DIR}/libuv_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
H
Hongze Cheng 已提交
113 114
endif(${BUILD_WITH_UV})

H
Hongze Cheng 已提交
115
# bdb
H
Hongze Cheng 已提交
116 117 118
if(${BUILD_WITH_BDB})
    cat("${TD_SUPPORT_DIR}/bdb_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
endif(${BUILD_WITH_BDB})
H
Hongze Cheng 已提交
119

H
Hongze Cheng 已提交
120
# sqlite
H
Hongze Cheng 已提交
121
if(${BUILD_WITH_SQLITE})
wafwerar's avatar
wafwerar 已提交
122
    cat("${TD_SUPPORT_DIR}/sqlite_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
H
Hongze Cheng 已提交
123 124
endif(${BUILD_WITH_SQLITE})

H
Hongze Cheng 已提交
125
# lucene
H
Hongze Cheng 已提交
126
if(${BUILD_WITH_LUCENE})
wafwerar's avatar
wafwerar 已提交
127
    cat("${TD_SUPPORT_DIR}/lucene_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
H
Hongze Cheng 已提交
128 129 130
    add_definitions(-DUSE_LUCENE)
endif(${BUILD_WITH_LUCENE})

H
Hongze Cheng 已提交
131
# NuRaft
H
Hongze Cheng 已提交
132
if(${BUILD_WITH_NURAFT})
wafwerar's avatar
wafwerar 已提交
133
    cat("${TD_SUPPORT_DIR}/nuraft_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
H
Hongze Cheng 已提交
134 135
endif(${BUILD_WITH_NURAFT})

wafwerar's avatar
wafwerar 已提交
136 137 138 139 140
# crashdump
if(${BUILD_CRASHDUMP})
    cat("${TD_SUPPORT_DIR}/crashdump_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
endif(${BUILD_CRASHDUMP})

wafwerar's avatar
wafwerar 已提交
141 142
# addr2line
if(${BUILD_ADDR2LINE})
wafwerar's avatar
wafwerar 已提交
143 144 145 146
    if(NOT ${TD_WINDOWS})
        cat("${TD_SUPPORT_DIR}/libdwarf_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
        cat("${TD_SUPPORT_DIR}/addr2line_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
    endif(NOT ${TD_WINDOWS})
wafwerar's avatar
wafwerar 已提交
147 148
endif(${BUILD_ADDR2LINE})

D
Dingle Zhang 已提交
149 150 151 152 153
# geos
if(${BUILD_GEOS})
    cat("${TD_SUPPORT_DIR}/geos_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
endif()

H
Hongze Cheng 已提交
154
# download dependencies
wafwerar's avatar
wafwerar 已提交
155
configure_file(${CONTRIB_TMP_FILE} "${TD_CONTRIB_DIR}/deps-download/CMakeLists.txt")
H
Hongze Cheng 已提交
156
execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
wafwerar's avatar
wafwerar 已提交
157
        WORKING_DIRECTORY "${TD_CONTRIB_DIR}/deps-download")
H
Hongze Cheng 已提交
158
execute_process(COMMAND "${CMAKE_COMMAND}" --build .
wafwerar's avatar
wafwerar 已提交
159
        WORKING_DIRECTORY "${TD_CONTRIB_DIR}/deps-download")
H
Hongze Cheng 已提交
160

H
Hongze Cheng 已提交
161
# ================================================================================================
H
Hongze Cheng 已提交
162
# Build
H
Hongze Cheng 已提交
163
# ================================================================================================
H
Hongze Cheng 已提交
164
# googletest
H
refact  
Hongze Cheng 已提交
165
if(${BUILD_TEST})
wafwerar's avatar
wafwerar 已提交
166
    set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
wafwerar's avatar
wafwerar 已提交
167
    add_subdirectory(googletest EXCLUDE_FROM_ALL)
X
Xiaoyu Wang 已提交
168 169 170 171
    target_include_directories(
        gtest
        PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cpp-stub/src>
    )
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
    if(${TD_WINDOWS})
        target_include_directories(
            gtest
            PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cpp-stub/src_win>
        )
    endif(${TD_WINDOWS})
    if(${TD_LINUX})
        target_include_directories(
            gtest
            PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cpp-stub/src_linux>
        )
    endif(${TD_LINUX})
    if(${TD_DARWIN})
        target_include_directories(
            gtest
            PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cpp-stub/src_darwin>
        )
    endif(${TD_DARWIN})
190 191


H
refact  
Hongze Cheng 已提交
192
endif(${BUILD_TEST})
H
refact  
Hongze Cheng 已提交
193

H
Hongze Cheng 已提交
194
# cJson
H
Hongze Cheng 已提交
195
# see https://stackoverflow.com/questions/37582508/silence-cmp0048-warnings-in-vendored-projects
wafwerar's avatar
wafwerar 已提交
196
set(CMAKE_PROJECT_INCLUDE_BEFORE "${TD_SUPPORT_DIR}/EnableCMP0048.txt.in")
H
Hongze Cheng 已提交
197 198 199
option(ENABLE_CJSON_TEST "Enable building cJSON test" OFF)
option(CJSON_OVERRIDE_BUILD_SHARED_LIBS "Override BUILD_SHARED_LIBS with CJSON_BUILD_SHARED_LIBS" ON)
option(CJSON_BUILD_SHARED_LIBS "Overrides BUILD_SHARED_LIBS if CJSON_OVERRIDE_BUILD_SHARED_LIBS is enabled" OFF)
wafwerar's avatar
wafwerar 已提交
200
add_subdirectory(cJson EXCLUDE_FROM_ALL)
S
Shengliang Guan 已提交
201 202
target_include_directories(
    cjson
H
Hongze Cheng 已提交
203 204
    # see https://stackoverflow.com/questions/25676277/cmake-target-include-directories-prints-an-error-when-i-try-to-add-the-source
    PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cJson>
S
Shengliang Guan 已提交
205
)
H
Hongze Cheng 已提交
206
unset(CMAKE_PROJECT_INCLUDE_BEFORE)
S
Shengliang Guan 已提交
207

H
Hongze Cheng 已提交
208
# lz4
wafwerar's avatar
wafwerar 已提交
209
add_subdirectory(lz4/build/cmake EXCLUDE_FROM_ALL)
S
Shengliang Guan 已提交
210 211 212 213 214
target_include_directories(
    lz4_static
    PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/lz4/lib
)

H
Hongze Cheng 已提交
215
# zlib
wafwerar's avatar
wafwerar 已提交
216
set(CMAKE_PROJECT_INCLUDE_BEFORE "${TD_SUPPORT_DIR}/EnableCMP0048.txt.in")
wafwerar's avatar
wafwerar 已提交
217
add_subdirectory(zlib EXCLUDE_FROM_ALL)
H
Hongze Cheng 已提交
218
target_include_directories(
H
Haojun Liao 已提交
219 220 221 222 223 224
    zlibstatic
    PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/zlib
    PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/zlib
)
target_include_directories(
    zlib
H
Hongze Cheng 已提交
225 226 227
    PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/zlib
    PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/zlib
)
H
Hongze Cheng 已提交
228
unset(CMAKE_PROJECT_INCLUDE_BEFORE)
H
Hongze Cheng 已提交
229 230 231

# leveldb
if(${BUILD_WITH_LEVELDB})
H
more  
Hongze Cheng 已提交
232
    option(LEVELDB_BUILD_TESTS "" OFF)
wafwerar's avatar
wafwerar 已提交
233
    add_subdirectory(leveldb EXCLUDE_FROM_ALL)
H
Hongze Cheng 已提交
234 235 236 237 238 239 240
    target_include_directories(
        leveldb
        PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/leveldb/include>
    )
endif(${BUILD_WITH_LEVELDB})

# rocksdb
H
Hongze Cheng 已提交
241
# To support rocksdb build on ubuntu: sudo apt-get install libgflags-dev
D
dapan1121 已提交
242
if (${BUILD_WITH_UV})
dengyihao's avatar
dengyihao 已提交
243
    if(${TD_LINUX})
D
dapan1121 已提交
244 245
        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS_REL}")
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_REL}")
K
kailixu 已提交
246
        IF ("${CMAKE_BUILD_TYPE}" STREQUAL "")
K
kailixu 已提交
247 248
            SET(CMAKE_BUILD_TYPE Release)
        endif()
dengyihao's avatar
dengyihao 已提交
249
    endif(${TD_LINUX})
D
dapan1121 已提交
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
endif (${BUILD_WITH_UV})

if (${BUILD_WITH_ROCKSDB})
    if (${BUILD_CONTRIB})
        if(${TD_LINUX})
            SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_REL} -Wno-error=maybe-uninitialized -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=unused-function -Wno-errno=unused-private-field -Wno-error=unused-result")
            if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
                SET(CMAKE_BUILD_TYPE Release)
            endif()
        endif(${TD_LINUX})
        MESSAGE(STATUS "CXXXX STATUS CONFIG: " ${CMAKE_CXX_FLAGS})

        if(${TD_DARWIN})
            SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=maybe-uninitialized")
        endif(${TD_DARWIN})

        if (${TD_DARWIN_ARM64})
            set(HAS_ARMV8_CRC true)
        endif(${TD_DARWIN_ARM64})

        if (${TD_WINDOWS})
            SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4244 /wd4819")
            option(WITH_JNI "" OFF)
            option(WITH_MD_LIBRARY "build with MD" OFF)
            set(SYSTEM_LIBS ${SYSTEM_LIBS} shlwapi.lib rpcrt4.lib)
        endif(${TD_WINDOWS})


        if(${TD_DARWIN})
            option(HAVE_THREAD_LOCAL "" OFF)
            option(WITH_IOSTATS_CONTEXT "" OFF)
            option(WITH_PERF_CONTEXT "" OFF)
        endif(${TD_DARWIN})

        option(WITH_FALLOCATE "" OFF)
        option(WITH_JEMALLOC "" OFF)
        option(WITH_GFLAGS "" OFF)
        option(PORTABLE "" ON)
        option(WITH_LIBURING "" OFF)
        option(FAIL_ON_WARNINGS OFF)

        option(WITH_TESTS "" OFF)
        option(WITH_BENCHMARK_TOOLS "" OFF)
        option(WITH_TOOLS "" OFF)
        option(WITH_LIBURING "" OFF)

        option(ROCKSDB_BUILD_SHARED "Build shared versions of the RocksDB libraries" OFF)
        add_subdirectory(rocksdb EXCLUDE_FROM_ALL)
        target_include_directories(
            rocksdb
            PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/rocksdb/include>
        )
    else() 
        if (NOT ${TD_LINUX})
            MESSAGE(STATUS "CXXXX STATUS CONFIG: " ${CMAKE_CXX_FLAGS})
            if(${TD_DARWIN})
                SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=maybe-uninitialized")
            endif(${TD_DARWIN})

            if (${TD_DARWIN_ARM64})
                set(HAS_ARMV8_CRC true)
            endif(${TD_DARWIN_ARM64})

            if (${TD_WINDOWS})
                SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4244 /wd4819")
                option(WITH_JNI "" OFF)
                option(WITH_MD_LIBRARY "build with MD" OFF)
                set(SYSTEM_LIBS ${SYSTEM_LIBS} shlwapi.lib rpcrt4.lib)
            endif(${TD_WINDOWS})


            if(${TD_DARWIN})
                option(HAVE_THREAD_LOCAL "" OFF)
                option(WITH_IOSTATS_CONTEXT "" OFF)
                option(WITH_PERF_CONTEXT "" OFF)
            endif(${TD_DARWIN})

            option(WITH_FALLOCATE "" OFF)
            option(WITH_JEMALLOC "" OFF)
            option(WITH_GFLAGS "" OFF)
            option(PORTABLE "" ON)
            option(WITH_LIBURING "" OFF)
            option(FAIL_ON_WARNINGS OFF)

            option(WITH_TESTS "" OFF)
            option(WITH_BENCHMARK_TOOLS "" OFF)
            option(WITH_TOOLS "" OFF)
            option(WITH_LIBURING "" OFF)

            option(ROCKSDB_BUILD_SHARED "Build shared versions of the RocksDB libraries" OFF)
            add_subdirectory(rocksdb EXCLUDE_FROM_ALL)
            target_include_directories(
                rocksdb
                PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/rocksdb/include>
            )
        endif() 
      
    endif()
endif()
H
Hongze Cheng 已提交
349 350 351 352 353

# lucene
# To support build on ubuntu: sudo apt-get install libboost-all-dev
if(${BUILD_WITH_LUCENE})
    option(ENABLE_TEST "Enable the tests" OFF)
wafwerar's avatar
wafwerar 已提交
354
    add_subdirectory(lucene EXCLUDE_FROM_ALL)
dengyihao's avatar
dengyihao 已提交
355
    target_include_directories(
356
      lucene++
dengyihao's avatar
dengyihao 已提交
357
      PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lucene/include>
358 359
    )

H
Hongze Cheng 已提交
360
endif(${BUILD_WITH_LUCENE})
H
Hongze Cheng 已提交
361

H
Hongze Cheng 已提交
362 363
# NuRaft
if(${BUILD_WITH_NURAFT})
wafwerar's avatar
wafwerar 已提交
364
    add_subdirectory(nuraft EXCLUDE_FROM_ALL)
H
Hongze Cheng 已提交
365 366
endif(${BUILD_WITH_NURAFT})

367 368
# pthread
if(${BUILD_PTHREAD})
wafwerar's avatar
wafwerar 已提交
369
    set(CMAKE_BUILD_TYPE debug)
wafwerar's avatar
wafwerar 已提交
370
    add_definitions(-DPTW32_STATIC_LIB)
wafwerar's avatar
wafwerar 已提交
371
    add_subdirectory(pthread EXCLUDE_FROM_ALL)
372
    set_target_properties(libpthreadVC3 PROPERTIES OUTPUT_NAME pthread)
wafwerar's avatar
wafwerar 已提交
373 374
    add_library(pthread INTERFACE)
    target_link_libraries(pthread INTERFACE libpthreadVC3)
375 376
endif()

wafwerar's avatar
wafwerar 已提交
377 378 379 380 381 382 383
# jemalloc
if(${JEMALLOC_ENABLED})
    include(ExternalProject)
    ExternalProject_Add(jemalloc
        PREFIX        "jemalloc"
        SOURCE_DIR    ${CMAKE_CURRENT_SOURCE_DIR}/jemalloc
        BUILD_IN_SOURCE     1
H
Haojun Liao 已提交
384
        CONFIGURE_COMMAND  ./autogen.sh COMMAND ./configure --prefix=${CMAKE_BINARY_DIR}/build/ --disable-initial-exec-tls
wafwerar's avatar
wafwerar 已提交
385 386 387 388 389
        BUILD_COMMAND       ${MAKE}
    )
    INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/build/include)
endif()

wafwerar's avatar
wafwerar 已提交
390 391 392 393 394 395 396 397 398 399
# crashdump
if(${BUILD_CRASHDUMP})
    add_executable(dumper "crashdump/dumper/dumper.c")
    target_link_libraries(dumper User32.lib dbghelp.lib)
    file(READ "crashdump/crasher/crasher.c" CRASHDUMP_CONTENT)
    string(REPLACE "main(" "main_crashdump(" CRASHDUMP_CONTENT "${CRASHDUMP_CONTENT}")
    file(WRITE "crashdump/crasher/crasher.c" "${CRASHDUMP_CONTENT}")
    add_library(crashdump STATIC "crashdump/crasher/crasher.c")
endif()

400 401
# iconv
if(${BUILD_WITH_ICONV})
wafwerar's avatar
wafwerar 已提交
402
    add_library(iconv STATIC iconv/win_iconv.c)
403 404 405 406
endif(${BUILD_WITH_ICONV})

# wingetopt
if(${BUILD_WINGETOPT})
wafwerar's avatar
wafwerar 已提交
407
    add_subdirectory(wingetopt EXCLUDE_FROM_ALL)
408 409 410 411 412 413 414 415 416 417 418
endif(${BUILD_WINGETOPT})

# msvcregex
if(${BUILD_MSVCREGEX})
    add_library(msvcregex STATIC "")
    target_sources(msvcregex
        PRIVATE "msvcregex/regex.c"
    )
    target_include_directories(msvcregex
        PRIVATE "msvcregex"
    )
419
    target_link_libraries(msvcregex
420 421 422 423 424
        INTERFACE Shell32
    )
    SET_TARGET_PROPERTIES(msvcregex PROPERTIES OUTPUT_NAME msvcregex)
endif(${BUILD_MSVCREGEX})

wafwerar's avatar
wafwerar 已提交
425
# wcwidth
426 427 428 429 430 431 432 433 434 435 436
if(${BUILD_WCWIDTH})
    add_library(wcwidth STATIC "")
    target_sources(wcwidth
        PRIVATE "wcwidth/wcwidth.c"
    )
    target_include_directories(wcwidth
        PRIVATE "wcwidth"
    )
    SET_TARGET_PROPERTIES(wcwidth PROPERTIES OUTPUT_NAME wcwidth)
endif(${BUILD_WCWIDTH})

M
Minghao Li 已提交
437 438 439 440 441
# CRAFT
if(${BUILD_WITH_CRAFT})
    add_library(craft STATIC IMPORTED GLOBAL)
    set_target_properties(craft PROPERTIES
        IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/craft/.libs/libraft.a"
H
Hongze Cheng 已提交
442
        INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/craft/include"
M
Minghao Li 已提交
443
    )
H
Hongze Cheng 已提交
444 445 446
    # target_link_libraries(craft
    #     INTERFACE pthread
    # )
M
Minghao Li 已提交
447 448
endif(${BUILD_WITH_CRAFT})

M
Minghao Li 已提交
449 450 451 452 453 454 455 456 457 458 459 460
# TRAFT
if(${BUILD_WITH_TRAFT})
    add_library(traft STATIC IMPORTED GLOBAL)
    set_target_properties(traft PROPERTIES
        IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/traft/.libs/libraft.a"
        INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/traft/include"
    )
    # target_link_libraries(craft
    #     INTERFACE pthread
    # )
endif(${BUILD_WITH_TRAFT})

H
Hongze Cheng 已提交
461 462
# LIBUV
if(${BUILD_WITH_UV})
wafwerar's avatar
wafwerar 已提交
463 464 465 466 467
    if (TD_WINDOWS)
        # There is no GetHostNameW function on win7.
        file(READ "libuv/src/win/util.c" LIBUV_WIN_UTIL_CONTENT)
        string(REPLACE "if (GetHostNameW(buf, UV_MAXHOSTNAMESIZE" "DWORD  nSize = UV_MAXHOSTNAMESIZE;\n  if (GetComputerNameW(buf, &nSize" LIBUV_WIN_UTIL_CONTENT "${LIBUV_WIN_UTIL_CONTENT}")
        file(WRITE "libuv/src/win/util.c" "${LIBUV_WIN_UTIL_CONTENT}")
468
    endif ()
wafwerar's avatar
wafwerar 已提交
469
    add_subdirectory(libuv EXCLUDE_FROM_ALL)
H
Hongze Cheng 已提交
470 471
endif(${BUILD_WITH_UV})

H
Hongze Cheng 已提交
472 473
# BDB
if(${BUILD_WITH_BDB})
474
    add_library(bdb STATIC IMPORTED GLOBAL)
H
Hongze Cheng 已提交
475 476 477 478
    set_target_properties(bdb PROPERTIES
        IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/bdb/libdb.a"
        INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/bdb"
    )
479 480
    target_link_libraries(bdb
        INTERFACE pthread
H
Hongze Cheng 已提交
481
    )
H
Hongze Cheng 已提交
482 483
endif(${BUILD_WITH_BDB})

H
Hongze Cheng 已提交
484
# SQLite
485
# see https://stackoverflow.com/questions/8774593/cmake-link-to-external-library#comment58570736_10550334
H
Hongze Cheng 已提交
486
if(${BUILD_WITH_SQLITE})
487
    add_library(sqlite STATIC IMPORTED GLOBAL)
H
Hongze Cheng 已提交
488 489
    set_target_properties(sqlite PROPERTIES
        IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/sqlite/.libs/libsqlite3.a"
H
Hongze Cheng 已提交
490 491
        INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/sqlite"
    )
492 493 494
    target_link_libraries(sqlite
        INTERFACE m
        INTERFACE pthread
H
Hongze Cheng 已提交
495
    )
496
    if(NOT TD_WINDOWS)
497
        target_link_libraries(sqlite
498 499 500
            INTERFACE dl
        )
    endif(NOT TD_WINDOWS)
H
Hongze Cheng 已提交
501 502
endif(${BUILD_WITH_SQLITE})

wafwerar's avatar
wafwerar 已提交
503 504
# addr2line
if(${BUILD_ADDR2LINE})
505 506 507 508 509 510 511 512 513
    if(NOT ${TD_WINDOWS})
        check_include_file( "sys/types.h"     HAVE_SYS_TYPES_H)
        check_include_file( "sys/stat.h"      HAVE_SYS_STAT_H )
        check_include_file( "inttypes.h"      HAVE_INTTYPES_H   )
        check_include_file( "stddef.h"        HAVE_STDDEF_H   )
        check_include_file( "stdlib.h"        HAVE_STDLIB_H   )
        check_include_file( "string.h"        HAVE_STRING_H   )
        check_include_file( "memory.h"        HAVE_MEMORY_H   )
        check_include_file( "strings.h"       HAVE_STRINGS_H  )
wafwerar's avatar
wafwerar 已提交
514 515 516 517
        check_include_file( "stdint.h"        HAVE_STDINT_H   )
        check_include_file( "unistd.h"        HAVE_UNISTD_H   )
        check_include_file( "sgidefs.h"       HAVE_SGIDEFS_H  )
        check_include_file( "stdafx.h"        HAVE_STDAFX_H   )
518 519 520
        check_include_file( "elf.h"           HAVE_ELF_H      )
        check_include_file( "libelf.h"        HAVE_LIBELF_H   )
        check_include_file( "libelf/libelf.h" HAVE_LIBELF_LIBELF_H)
wafwerar's avatar
wafwerar 已提交
521 522 523 524 525 526 527
        check_include_file( "alloca.h"        HAVE_ALLOCA_H   )
        check_include_file( "elfaccess.h"     HAVE_ELFACCESS_H)
        check_include_file( "sys/elf_386.h"   HAVE_SYS_ELF_386_H  )
        check_include_file( "sys/elf_amd64.h" HAVE_SYS_ELF_AMD64_H)
        check_include_file( "sys/elf_sparc.h" HAVE_SYS_ELF_SPARC_H)
        check_include_file( "sys/ia64/elf.h"  HAVE_SYS_IA64_ELF_H )
        set(VERSION 0.3.1)
528
        set(PACKAGE_VERSION "\"${VERSION}\"")
wafwerar's avatar
wafwerar 已提交
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545
        configure_file(libdwarf/cmake/config.h.cmake config.h)
        file(GLOB_RECURSE LIBDWARF_SOURCES "libdwarf/src/lib/libdwarf/*.c")
        add_library(libdwarf STATIC ${LIBDWARF_SOURCES})
        set_target_properties(libdwarf PROPERTIES OUTPUT_NAME "libdwarf")
        if(HAVE_LIBELF_H OR HAVE_LIBELF_LIBELF_H)
            target_link_libraries(libdwarf PUBLIC libelf)
        endif()
        target_include_directories(libdwarf SYSTEM PUBLIC "libdwarf/src/lib/libdwarf" ${CMAKE_CURRENT_BINARY_DIR})
        file(READ "addr2line/addr2line.c" ADDR2LINE_CONTENT)
        string(REPLACE "static int" "int" ADDR2LINE_CONTENT "${ADDR2LINE_CONTENT}")
        string(REPLACE "static void" "void" ADDR2LINE_CONTENT "${ADDR2LINE_CONTENT}")
        string(REPLACE "main(" "main_addr2line(" ADDR2LINE_CONTENT "${ADDR2LINE_CONTENT}")
        file(WRITE "addr2line/addr2line.c" "${ADDR2LINE_CONTENT}")
        add_library(addr2line STATIC "addr2line/addr2line.c")
        target_link_libraries(addr2line PUBLIC libdwarf dl z)
        target_include_directories(addr2line PUBLIC "libdwarf/src/lib/libdwarf" )
    endif(NOT ${TD_WINDOWS})
wafwerar's avatar
wafwerar 已提交
546
endif(${BUILD_ADDR2LINE})
H
Hongze Cheng 已提交
547

D
Dingle Zhang 已提交
548 549
# geos
if(${BUILD_GEOS})
K
kailixu 已提交
550 551 552
    if(${TD_LINUX})
        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS_REL}")
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_REL}")
K
kailixu 已提交
553 554
        IF ("${CMAKE_BUILD_TYPE}" STREQUAL "")
            SET(CMAKE_BUILD_TYPE Release)
K
kailixu 已提交
555
        endif()
K
kailixu 已提交
556
    endif(${TD_LINUX})
D
Dingle Zhang 已提交
557 558
    option(BUILD_SHARED_LIBS "Build GEOS with shared libraries" OFF)
    add_subdirectory(geos EXCLUDE_FROM_ALL)
559
    unset(CMAKE_CXX_STANDARD CACHE) # undo libgeos's setting of global CMAKE_CXX_STANDARD
D
Dingle Zhang 已提交
560 561 562 563 564
    target_include_directories(
        geos_c
        PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/geos/include>
    )
endif(${BUILD_GEOS})
H
Hongze Cheng 已提交
565

H
Hongze Cheng 已提交
566
# ================================================================================================
H
Hongze Cheng 已提交
567
# Build test
H
Hongze Cheng 已提交
568 569
# ================================================================================================
if(${BUILD_DEPENDENCY_TESTS})
wafwerar's avatar
wafwerar 已提交
570
    add_subdirectory(test EXCLUDE_FROM_ALL)
H
Hongze Cheng 已提交
571
endif(${BUILD_DEPENDENCY_TESTS})