CMakeLists.txt 13.2 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
# pthread
if(${BUILD_PTHREAD})
wafwerar's avatar
wafwerar 已提交
14
    cat("${TD_SUPPORT_DIR}/pthread_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
15 16
endif()

17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
# iconv
if(${BUILD_WITH_ICONV})
    cat("${TD_SUPPORT_DIR}/iconv_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
endif()

# 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})
35 36
endif()

H
Hongze Cheng 已提交
37
# googletest
H
Hongze Cheng 已提交
38
if(${BUILD_TEST})
wafwerar's avatar
wafwerar 已提交
39 40
    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 已提交
41 42
endif(${BUILD_TEST})

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

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

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

H
Hongze Cheng 已提交
52
# leveldb
H
Hongze Cheng 已提交
53
if(${BUILD_WITH_LEVELDB})
wafwerar's avatar
wafwerar 已提交
54
    cat("${TD_SUPPORT_DIR}/leveldb_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
H
Hongze Cheng 已提交
55 56
endif(${BUILD_WITH_LEVELDB})

H
Hongze Cheng 已提交
57
# rocksdb
H
Hongze Cheng 已提交
58
if(${BUILD_WITH_ROCKSDB})
wafwerar's avatar
wafwerar 已提交
59
    cat("${TD_SUPPORT_DIR}/rocksdb_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
H
Hongze Cheng 已提交
60 61 62
    add_definitions(-DUSE_ROCKSDB)
endif(${BUILD_WITH_ROCKSDB})

M
Minghao Li 已提交
63 64
# canonical-raft
if(${BUILD_WITH_CRAFT})
wafwerar's avatar
wafwerar 已提交
65
    cat("${TD_SUPPORT_DIR}/craft_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
H
Hongze Cheng 已提交
66
    SET(BUILD_WITH_UV ON CACHE BOOL "craft need libuv" FORCE)
M
Minghao Li 已提交
67 68
endif(${BUILD_WITH_CRAFT})

M
Minghao Li 已提交
69 70
# traft
if(${BUILD_WITH_TRAFT})
wafwerar's avatar
wafwerar 已提交
71
    cat("${TD_SUPPORT_DIR}/traft_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
M
Minghao Li 已提交
72 73 74
    SET(BUILD_WITH_UV ON CACHE BOOL "traft need libuv" FORCE)
endif(${BUILD_WITH_TRAFT})

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

H
Hongze Cheng 已提交
80
# bdb
H
Hongze Cheng 已提交
81 82 83
if(${BUILD_WITH_BDB})
    cat("${TD_SUPPORT_DIR}/bdb_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
endif(${BUILD_WITH_BDB})
H
Hongze Cheng 已提交
84

H
Hongze Cheng 已提交
85
# sqlite
H
Hongze Cheng 已提交
86
if(${BUILD_WITH_SQLITE})
wafwerar's avatar
wafwerar 已提交
87
    cat("${TD_SUPPORT_DIR}/sqlite_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
H
Hongze Cheng 已提交
88 89
endif(${BUILD_WITH_SQLITE})

H
Hongze Cheng 已提交
90
# lucene
H
Hongze Cheng 已提交
91
if(${BUILD_WITH_LUCENE})
wafwerar's avatar
wafwerar 已提交
92
    cat("${TD_SUPPORT_DIR}/lucene_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
H
Hongze Cheng 已提交
93 94 95
    add_definitions(-DUSE_LUCENE)
endif(${BUILD_WITH_LUCENE})

H
Hongze Cheng 已提交
96
# NuRaft
H
Hongze Cheng 已提交
97
if(${BUILD_WITH_NURAFT})
wafwerar's avatar
wafwerar 已提交
98
    cat("${TD_SUPPORT_DIR}/nuraft_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
H
Hongze Cheng 已提交
99 100
endif(${BUILD_WITH_NURAFT})

wafwerar's avatar
wafwerar 已提交
101 102
# addr2line
if(${BUILD_ADDR2LINE})
wafwerar's avatar
wafwerar 已提交
103 104 105 106
    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 已提交
107 108
endif(${BUILD_ADDR2LINE})

H
Hongze Cheng 已提交
109
# download dependencies
wafwerar's avatar
wafwerar 已提交
110
configure_file(${CONTRIB_TMP_FILE} "${TD_CONTRIB_DIR}/deps-download/CMakeLists.txt")
H
Hongze Cheng 已提交
111
execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
wafwerar's avatar
wafwerar 已提交
112
        WORKING_DIRECTORY "${TD_CONTRIB_DIR}/deps-download")
H
Hongze Cheng 已提交
113
execute_process(COMMAND "${CMAKE_COMMAND}" --build .
wafwerar's avatar
wafwerar 已提交
114
        WORKING_DIRECTORY "${TD_CONTRIB_DIR}/deps-download")
H
Hongze Cheng 已提交
115

H
Hongze Cheng 已提交
116
# ================================================================================================
H
Hongze Cheng 已提交
117
# Build
H
Hongze Cheng 已提交
118
# ================================================================================================
H
Hongze Cheng 已提交
119
# googletest
H
refact  
Hongze Cheng 已提交
120
if(${BUILD_TEST})
wafwerar's avatar
wafwerar 已提交
121
    add_subdirectory(googletest EXCLUDE_FROM_ALL)
X
Xiaoyu Wang 已提交
122 123 124 125
    target_include_directories(
        gtest
        PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cpp-stub/src>
    )
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
    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})
    
    
H
refact  
Hongze Cheng 已提交
146
endif(${BUILD_TEST})
H
refact  
Hongze Cheng 已提交
147

H
Hongze Cheng 已提交
148
# cJson
H
Hongze Cheng 已提交
149
# see https://stackoverflow.com/questions/37582508/silence-cmp0048-warnings-in-vendored-projects
wafwerar's avatar
wafwerar 已提交
150
set(CMAKE_PROJECT_INCLUDE_BEFORE "${TD_SUPPORT_DIR}/EnableCMP0048.txt.in")
H
Hongze Cheng 已提交
151 152 153
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 已提交
154
add_subdirectory(cJson EXCLUDE_FROM_ALL)
S
Shengliang Guan 已提交
155 156
target_include_directories(
    cjson
H
Hongze Cheng 已提交
157 158
    # 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 已提交
159
)
H
Hongze Cheng 已提交
160
unset(CMAKE_PROJECT_INCLUDE_BEFORE)
S
Shengliang Guan 已提交
161

H
Hongze Cheng 已提交
162
# lz4
wafwerar's avatar
wafwerar 已提交
163
add_subdirectory(lz4/build/cmake EXCLUDE_FROM_ALL)
S
Shengliang Guan 已提交
164 165 166 167 168
target_include_directories(
    lz4_static
    PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/lz4/lib
)

H
Hongze Cheng 已提交
169
# zlib
wafwerar's avatar
wafwerar 已提交
170
set(CMAKE_PROJECT_INCLUDE_BEFORE "${TD_SUPPORT_DIR}/EnableCMP0048.txt.in")
wafwerar's avatar
wafwerar 已提交
171
add_subdirectory(zlib EXCLUDE_FROM_ALL)
H
Hongze Cheng 已提交
172
target_include_directories(
H
Haojun Liao 已提交
173 174 175 176 177 178
    zlibstatic
    PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/zlib
    PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/zlib
)
target_include_directories(
    zlib
H
Hongze Cheng 已提交
179 180 181
    PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/zlib
    PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/zlib
)
H
Hongze Cheng 已提交
182
unset(CMAKE_PROJECT_INCLUDE_BEFORE)
H
Hongze Cheng 已提交
183 184 185

# leveldb
if(${BUILD_WITH_LEVELDB})
H
more  
Hongze Cheng 已提交
186
    option(LEVELDB_BUILD_TESTS "" OFF)
wafwerar's avatar
wafwerar 已提交
187
    add_subdirectory(leveldb EXCLUDE_FROM_ALL)
H
Hongze Cheng 已提交
188 189 190 191 192 193 194
    target_include_directories(
        leveldb
        PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/leveldb/include>
    )
endif(${BUILD_WITH_LEVELDB})

# rocksdb
H
Hongze Cheng 已提交
195
# To support rocksdb build on ubuntu: sudo apt-get install libgflags-dev
H
Hongze Cheng 已提交
196
if(${BUILD_WITH_ROCKSDB})
L
Liu Jicong 已提交
197
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=maybe-uninitialized")
H
Hongze Cheng 已提交
198 199
    option(WITH_TESTS "" OFF)
    option(WITH_BENCHMARK_TOOLS "" OFF)
L
Liu Jicong 已提交
200 201
    option(WITH_TOOLS "" OFF)
    option(WITH_LIBURING "" OFF)
H
refact  
Hongze Cheng 已提交
202
    option(ROCKSDB_BUILD_SHARED "Build shared versions of the RocksDB libraries" OFF)
wafwerar's avatar
wafwerar 已提交
203
    add_subdirectory(rocksdb EXCLUDE_FROM_ALL)
H
Hongze Cheng 已提交
204 205 206 207 208
    target_include_directories(
        rocksdb
        PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/rocksdb/include>
    )
endif(${BUILD_WITH_ROCKSDB})
H
Hongze Cheng 已提交
209 210 211 212 213

# 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 已提交
214
    add_subdirectory(lucene EXCLUDE_FROM_ALL)
dengyihao's avatar
dengyihao 已提交
215 216 217 218 219
    target_include_directories(
      lucene++ 
      PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lucene/include>
    ) 
     
H
Hongze Cheng 已提交
220
endif(${BUILD_WITH_LUCENE})
H
Hongze Cheng 已提交
221

H
Hongze Cheng 已提交
222 223
# NuRaft
if(${BUILD_WITH_NURAFT})
wafwerar's avatar
wafwerar 已提交
224
    add_subdirectory(nuraft EXCLUDE_FROM_ALL)
H
Hongze Cheng 已提交
225 226
endif(${BUILD_WITH_NURAFT})

227 228 229
# pthread
if(${BUILD_PTHREAD})
    set(CMAKE_BUILD_TYPE release)
wafwerar's avatar
wafwerar 已提交
230
    add_definitions(-DPTW32_STATIC_LIB)
wafwerar's avatar
wafwerar 已提交
231
    add_subdirectory(pthread EXCLUDE_FROM_ALL)
232
    set_target_properties(libpthreadVC3 PROPERTIES OUTPUT_NAME pthread)
wafwerar's avatar
wafwerar 已提交
233 234
    add_library(pthread INTERFACE)
    target_link_libraries(pthread INTERFACE libpthreadVC3)
235 236 237 238
endif()

# iconv
if(${BUILD_WITH_ICONV})
wafwerar's avatar
wafwerar 已提交
239
    add_library(iconv STATIC iconv/win_iconv.c)
240 241 242 243
endif(${BUILD_WITH_ICONV})

# wingetopt
if(${BUILD_WINGETOPT})
wafwerar's avatar
wafwerar 已提交
244
    add_subdirectory(wingetopt EXCLUDE_FROM_ALL)
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
endif(${BUILD_WINGETOPT})

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

# msvcregex
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 已提交
274 275 276 277 278
# 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 已提交
279
        INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/craft/include"
M
Minghao Li 已提交
280
    )
H
Hongze Cheng 已提交
281 282 283
    # target_link_libraries(craft
    #     INTERFACE pthread
    # )
M
Minghao Li 已提交
284 285
endif(${BUILD_WITH_CRAFT})

M
Minghao Li 已提交
286 287 288 289 290 291 292 293 294 295 296 297
# 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 已提交
298 299
# LIBUV
if(${BUILD_WITH_UV})
300 301 302 303
    if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows")
        MESSAGE("Windows need set no-sign-compare")
        add_compile_options(-Wno-sign-compare)
    endif ()
wafwerar's avatar
wafwerar 已提交
304
    add_subdirectory(libuv EXCLUDE_FROM_ALL)
H
Hongze Cheng 已提交
305 306
endif(${BUILD_WITH_UV})

H
Hongze Cheng 已提交
307 308
# BDB
if(${BUILD_WITH_BDB})
309
    add_library(bdb STATIC IMPORTED GLOBAL)
H
Hongze Cheng 已提交
310 311 312 313
    set_target_properties(bdb PROPERTIES
        IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/bdb/libdb.a"
        INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/bdb"
    )
H
Hongze Cheng 已提交
314 315 316
    target_link_libraries(bdb 
        INTERFACE pthread 
    )
H
Hongze Cheng 已提交
317 318
endif(${BUILD_WITH_BDB})

H
Hongze Cheng 已提交
319
# SQLite
320
# see https://stackoverflow.com/questions/8774593/cmake-link-to-external-library#comment58570736_10550334
H
Hongze Cheng 已提交
321
if(${BUILD_WITH_SQLITE})
322
    add_library(sqlite STATIC IMPORTED GLOBAL)
H
Hongze Cheng 已提交
323 324
    set_target_properties(sqlite PROPERTIES
        IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/sqlite/.libs/libsqlite3.a"
H
Hongze Cheng 已提交
325 326
        INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/sqlite"
    )
H
Hongze Cheng 已提交
327 328 329 330
    target_link_libraries(sqlite 
        INTERFACE m 
        INTERFACE pthread 
    )
331 332 333 334 335
    if(NOT TD_WINDOWS)
        target_link_libraries(sqlite 
            INTERFACE dl
        )
    endif(NOT TD_WINDOWS)
H
Hongze Cheng 已提交
336 337
endif(${BUILD_WITH_SQLITE})

wafwerar's avatar
wafwerar 已提交
338 339
# addr2line
if(${BUILD_ADDR2LINE})
wafwerar's avatar
wafwerar 已提交
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
    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  ) 
        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   )
        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) 
        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)
        set(PACKAGE_VERSION "\"${VERSION}\"") 
        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 已提交
381
endif(${BUILD_ADDR2LINE})
H
Hongze Cheng 已提交
382

H
Hongze Cheng 已提交
383

H
Hongze Cheng 已提交
384
# ================================================================================================
H
Hongze Cheng 已提交
385
# Build test
H
Hongze Cheng 已提交
386 387
# ================================================================================================
if(${BUILD_DEPENDENCY_TESTS})
wafwerar's avatar
wafwerar 已提交
388
    add_subdirectory(test EXCLUDE_FROM_ALL)
H
Hongze Cheng 已提交
389
endif(${BUILD_DEPENDENCY_TESTS})