CMakeLists.txt 8.1 KB
Newer Older
H
Hongze Cheng 已提交
1 2 3
# ================================================================================================
# Download
# ================================================================================================
H
Hongze Cheng 已提交
4 5 6 7 8 9 10 11
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")
configure_file("${CMAKE_SUPPORT_DIR}/deps_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})

12 13 14 15 16 17 18 19 20 21
# pthread
if(${BUILD_PTHREAD})
    cat("${CMAKE_SUPPORT_DIR}/pthread_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
endif()

# gnu regex
if(${BUILD_GNUREGEX})
    cat("${CMAKE_SUPPORT_DIR}/gnuregex_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
endif()

H
Hongze Cheng 已提交
22
# googletest
H
Hongze Cheng 已提交
23 24
if(${BUILD_TEST})
    cat("${CMAKE_SUPPORT_DIR}/gtest_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
X
Xiaoyu Wang 已提交
25
    cat("${CMAKE_SUPPORT_DIR}/stub_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
H
Hongze Cheng 已提交
26 27
endif(${BUILD_TEST})

H
Hongze Cheng 已提交
28
# lz4
H
Hongze Cheng 已提交
29 30
cat("${CMAKE_SUPPORT_DIR}/lz4_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})

H
Hongze Cheng 已提交
31
# zlib
H
Hongze Cheng 已提交
32 33
cat("${CMAKE_SUPPORT_DIR}/zlib_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})

H
Hongze Cheng 已提交
34
# cJson
H
Hongze Cheng 已提交
35 36
cat("${CMAKE_SUPPORT_DIR}/cjson_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})

H
Hongze Cheng 已提交
37
# leveldb
H
Hongze Cheng 已提交
38 39 40 41
if(${BUILD_WITH_LEVELDB})
    cat("${CMAKE_SUPPORT_DIR}/leveldb_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
endif(${BUILD_WITH_LEVELDB})

H
Hongze Cheng 已提交
42
# rocksdb
H
Hongze Cheng 已提交
43 44 45 46 47
if(${BUILD_WITH_ROCKSDB})
    cat("${CMAKE_SUPPORT_DIR}/rocksdb_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
    add_definitions(-DUSE_ROCKSDB)
endif(${BUILD_WITH_ROCKSDB})

M
Minghao Li 已提交
48 49 50
# canonical-raft
if(${BUILD_WITH_CRAFT})
    cat("${CMAKE_SUPPORT_DIR}/craft_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
H
Hongze Cheng 已提交
51
    SET(BUILD_WITH_UV ON CACHE BOOL "craft need libuv" FORCE)
M
Minghao Li 已提交
52 53
endif(${BUILD_WITH_CRAFT})

M
Minghao Li 已提交
54 55 56 57 58 59
# traft
if(${BUILD_WITH_TRAFT})
    cat("${CMAKE_SUPPORT_DIR}/traft_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
    SET(BUILD_WITH_UV ON CACHE BOOL "traft need libuv" FORCE)
endif(${BUILD_WITH_TRAFT})

H
Hongze Cheng 已提交
60 61 62 63 64
#libuv
if(${BUILD_WITH_UV})
    cat("${CMAKE_SUPPORT_DIR}/libuv_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
endif(${BUILD_WITH_UV})

H
Hongze Cheng 已提交
65
# bdb
L
Liu Jicong 已提交
66 67 68
#if(${BUILD_WITH_BDB})
    #cat("${CMAKE_SUPPORT_DIR}/bdb_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
#endif(${BUILD_WITH_BDB})
H
Hongze Cheng 已提交
69

H
Hongze Cheng 已提交
70
# sqlite
H
Hongze Cheng 已提交
71 72 73 74
if(${BUILD_WITH_SQLITE})
    cat("${CMAKE_SUPPORT_DIR}/sqlite_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
endif(${BUILD_WITH_SQLITE})

H
Hongze Cheng 已提交
75
# lucene
H
Hongze Cheng 已提交
76 77 78 79 80
if(${BUILD_WITH_LUCENE})
    cat("${CMAKE_SUPPORT_DIR}/lucene_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
    add_definitions(-DUSE_LUCENE)
endif(${BUILD_WITH_LUCENE})

H
Hongze Cheng 已提交
81
# NuRaft
H
Hongze Cheng 已提交
82 83 84 85
if(${BUILD_WITH_NURAFT})
    cat("${CMAKE_SUPPORT_DIR}/nuraft_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
endif(${BUILD_WITH_NURAFT})

H
Hongze Cheng 已提交
86
# download dependencies
H
Hongze Cheng 已提交
87 88 89 90 91 92
configure_file(${CONTRIB_TMP_FILE} "${CMAKE_CONTRIB_DIR}/deps-download/CMakeLists.txt")
execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
        WORKING_DIRECTORY "${CMAKE_CONTRIB_DIR}/deps-download")
execute_process(COMMAND "${CMAKE_COMMAND}" --build .
        WORKING_DIRECTORY "${CMAKE_CONTRIB_DIR}/deps-download")

H
Hongze Cheng 已提交
93
# ================================================================================================
H
Hongze Cheng 已提交
94
# Build
H
Hongze Cheng 已提交
95
# ================================================================================================
H
Hongze Cheng 已提交
96
# googletest
H
refact  
Hongze Cheng 已提交
97 98
if(${BUILD_TEST})
    add_subdirectory(googletest)
X
Xiaoyu Wang 已提交
99 100 101 102 103
    target_include_directories(
        gtest
        PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cpp-stub/src>
        PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cpp-stub/src_linux>
    )
H
refact  
Hongze Cheng 已提交
104
endif(${BUILD_TEST})
H
refact  
Hongze Cheng 已提交
105

H
Hongze Cheng 已提交
106
# cJson
H
Hongze Cheng 已提交
107 108
# see https://stackoverflow.com/questions/37582508/silence-cmp0048-warnings-in-vendored-projects
set(CMAKE_PROJECT_INCLUDE_BEFORE "${CMAKE_SUPPORT_DIR}/EnableCMP0048.txt.in")
H
Hongze Cheng 已提交
109 110 111
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)
H
refact  
Hongze Cheng 已提交
112
add_subdirectory(cJson)
S
Shengliang Guan 已提交
113 114
target_include_directories(
    cjson
H
Hongze Cheng 已提交
115 116
    # 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 已提交
117
)
H
Hongze Cheng 已提交
118
unset(CMAKE_PROJECT_INCLUDE_BEFORE)
S
Shengliang Guan 已提交
119

H
Hongze Cheng 已提交
120
# lz4
H
refact  
Hongze Cheng 已提交
121
add_subdirectory(lz4/build/cmake)
S
Shengliang Guan 已提交
122 123 124 125 126
target_include_directories(
    lz4_static
    PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/lz4/lib
)

H
Hongze Cheng 已提交
127
# zlib
H
Hongze Cheng 已提交
128
set(CMAKE_PROJECT_INCLUDE_BEFORE "${CMAKE_SUPPORT_DIR}/EnableCMP0048.txt.in")
H
Hongze Cheng 已提交
129 130
add_subdirectory(zlib)
target_include_directories(
H
Haojun Liao 已提交
131 132 133 134 135 136
    zlibstatic
    PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/zlib
    PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/zlib
)
target_include_directories(
    zlib
H
Hongze Cheng 已提交
137 138 139
    PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/zlib
    PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/zlib
)
H
Hongze Cheng 已提交
140
unset(CMAKE_PROJECT_INCLUDE_BEFORE)
H
Hongze Cheng 已提交
141 142 143

# leveldb
if(${BUILD_WITH_LEVELDB})
H
more  
Hongze Cheng 已提交
144
    option(LEVELDB_BUILD_TESTS "" OFF)
H
Hongze Cheng 已提交
145 146 147 148 149 150 151 152
    add_subdirectory(leveldb)
    target_include_directories(
        leveldb
        PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/leveldb/include>
    )
endif(${BUILD_WITH_LEVELDB})

# rocksdb
H
Hongze Cheng 已提交
153
# To support rocksdb build on ubuntu: sudo apt-get install libgflags-dev
H
Hongze Cheng 已提交
154
if(${BUILD_WITH_ROCKSDB})
L
Liu Jicong 已提交
155
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=maybe-uninitialized")
H
Hongze Cheng 已提交
156 157
    option(WITH_TESTS "" OFF)
    option(WITH_BENCHMARK_TOOLS "" OFF)
L
Liu Jicong 已提交
158 159
    option(WITH_TOOLS "" OFF)
    option(WITH_LIBURING "" OFF)
H
refact  
Hongze Cheng 已提交
160
    option(ROCKSDB_BUILD_SHARED "Build shared versions of the RocksDB libraries" OFF)
H
Hongze Cheng 已提交
161 162 163 164 165 166
    add_subdirectory(rocksdb)
    target_include_directories(
        rocksdb
        PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/rocksdb/include>
    )
endif(${BUILD_WITH_ROCKSDB})
H
Hongze Cheng 已提交
167 168 169 170 171 172

# lucene
# To support build on ubuntu: sudo apt-get install libboost-all-dev
if(${BUILD_WITH_LUCENE})
    option(ENABLE_TEST "Enable the tests" OFF)
    add_subdirectory(lucene)
dengyihao's avatar
dengyihao 已提交
173 174 175 176 177
    target_include_directories(
      lucene++ 
      PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lucene/include>
    ) 
     
H
Hongze Cheng 已提交
178
endif(${BUILD_WITH_LUCENE})
H
Hongze Cheng 已提交
179

H
Hongze Cheng 已提交
180 181 182 183 184
# NuRaft
if(${BUILD_WITH_NURAFT})
    add_subdirectory(nuraft)
endif(${BUILD_WITH_NURAFT})

M
Minghao Li 已提交
185 186 187 188 189
# 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 已提交
190
        INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/craft/include"
M
Minghao Li 已提交
191
    )
H
Hongze Cheng 已提交
192 193 194
    # target_link_libraries(craft
    #     INTERFACE pthread
    # )
M
Minghao Li 已提交
195 196
endif(${BUILD_WITH_CRAFT})

M
Minghao Li 已提交
197 198 199 200 201 202 203 204 205 206 207 208
# 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 已提交
209 210
# LIBUV
if(${BUILD_WITH_UV})
211 212 213 214
    if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows")
        MESSAGE("Windows need set no-sign-compare")
        add_compile_options(-Wno-sign-compare)
    endif ()
H
Hongze Cheng 已提交
215 216 217
    add_subdirectory(libuv)
endif(${BUILD_WITH_UV})

H
Hongze Cheng 已提交
218 219
# BDB
if(${BUILD_WITH_BDB})
220
    add_library(bdb STATIC IMPORTED GLOBAL)
H
Hongze Cheng 已提交
221 222 223 224
    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 已提交
225 226 227
    target_link_libraries(bdb 
        INTERFACE pthread 
    )
H
Hongze Cheng 已提交
228 229
endif(${BUILD_WITH_BDB})

H
Hongze Cheng 已提交
230
# SQLite
231
# see https://stackoverflow.com/questions/8774593/cmake-link-to-external-library#comment58570736_10550334
H
Hongze Cheng 已提交
232
if(${BUILD_WITH_SQLITE})
233
    add_library(sqlite STATIC IMPORTED GLOBAL)
H
Hongze Cheng 已提交
234 235
    set_target_properties(sqlite PROPERTIES
        IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/sqlite/.libs/libsqlite3.a"
H
Hongze Cheng 已提交
236 237
        INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/sqlite"
    )
H
Hongze Cheng 已提交
238 239 240 241 242
    target_link_libraries(sqlite 
        INTERFACE m 
        INTERFACE pthread 
        INTERFACE dl
    )
H
Hongze Cheng 已提交
243 244
endif(${BUILD_WITH_SQLITE})

245
# pthread
H
Hongze Cheng 已提交
246

H
Hongze Cheng 已提交
247

H
Hongze Cheng 已提交
248
# ================================================================================================
H
Hongze Cheng 已提交
249
# Build test
H
Hongze Cheng 已提交
250 251 252 253
# ================================================================================================
if(${BUILD_DEPENDENCY_TESTS})
    add_subdirectory(test)
endif(${BUILD_DEPENDENCY_TESTS})