CMakeLists.txt 6.4 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})

H
Hongze Cheng 已提交
12
# googletest
H
Hongze Cheng 已提交
13 14 15 16
if(${BUILD_TEST})
    cat("${CMAKE_SUPPORT_DIR}/gtest_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
endif(${BUILD_TEST})

H
Hongze Cheng 已提交
17
# lz4
H
Hongze Cheng 已提交
18 19
cat("${CMAKE_SUPPORT_DIR}/lz4_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})

H
Hongze Cheng 已提交
20
# zlib
H
Hongze Cheng 已提交
21 22
cat("${CMAKE_SUPPORT_DIR}/zlib_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})

H
Hongze Cheng 已提交
23
# cJson
H
Hongze Cheng 已提交
24 25
cat("${CMAKE_SUPPORT_DIR}/cjson_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})

H
Hongze Cheng 已提交
26
# leveldb
H
Hongze Cheng 已提交
27 28 29 30
if(${BUILD_WITH_LEVELDB})
    cat("${CMAKE_SUPPORT_DIR}/leveldb_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
endif(${BUILD_WITH_LEVELDB})

H
Hongze Cheng 已提交
31
# rocksdb
H
Hongze Cheng 已提交
32 33 34 35 36
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 已提交
37 38 39 40 41
# canonical-raft
if(${BUILD_WITH_CRAFT})
    cat("${CMAKE_SUPPORT_DIR}/craft_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
endif(${BUILD_WITH_CRAFT})

H
Hongze Cheng 已提交
42
# bdb
H
Hongze Cheng 已提交
43 44 45 46
if(${BUILD_WITH_BDB})
    cat("${CMAKE_SUPPORT_DIR}/bdb_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
endif(${BUILD_WITH_DBD})

H
Hongze Cheng 已提交
47
# sqlite
H
Hongze Cheng 已提交
48 49 50 51
if(${BUILD_WITH_SQLITE})
    cat("${CMAKE_SUPPORT_DIR}/sqlite_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
endif(${BUILD_WITH_SQLITE})

H
Hongze Cheng 已提交
52
# lucene
H
Hongze Cheng 已提交
53 54 55 56 57
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 已提交
58
# NuRaft
H
Hongze Cheng 已提交
59 60 61 62
if(${BUILD_WITH_NURAFT})
    cat("${CMAKE_SUPPORT_DIR}/nuraft_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
endif(${BUILD_WITH_NURAFT})

H
Hongze Cheng 已提交
63
# download dependencies
H
Hongze Cheng 已提交
64 65 66 67 68 69
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 已提交
70
# ================================================================================================
H
Hongze Cheng 已提交
71
# Build
H
Hongze Cheng 已提交
72
# ================================================================================================
H
Hongze Cheng 已提交
73
# googletest
H
refact  
Hongze Cheng 已提交
74 75 76
if(${BUILD_TEST})
    add_subdirectory(googletest)
endif(${BUILD_TEST})
H
refact  
Hongze Cheng 已提交
77

H
Hongze Cheng 已提交
78
# cJson
H
Hongze Cheng 已提交
79 80
# 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 已提交
81 82 83
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 已提交
84
add_subdirectory(cJson)
S
Shengliang Guan 已提交
85 86
target_include_directories(
    cjson
H
Hongze Cheng 已提交
87 88
    # 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 已提交
89
)
H
Hongze Cheng 已提交
90
unset(CMAKE_PROJECT_INCLUDE_BEFORE)
S
Shengliang Guan 已提交
91

H
Hongze Cheng 已提交
92
# lz4
H
refact  
Hongze Cheng 已提交
93
add_subdirectory(lz4/build/cmake)
S
Shengliang Guan 已提交
94 95 96 97 98
target_include_directories(
    lz4_static
    PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/lz4/lib
)

H
Hongze Cheng 已提交
99
# zlib
H
Hongze Cheng 已提交
100
set(CMAKE_PROJECT_INCLUDE_BEFORE "${CMAKE_SUPPORT_DIR}/EnableCMP0048.txt.in")
H
Hongze Cheng 已提交
101 102 103 104 105 106
add_subdirectory(zlib)
target_include_directories(
    zlib
    PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/zlib
    PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/zlib
)
H
Hongze Cheng 已提交
107
unset(CMAKE_PROJECT_INCLUDE_BEFORE)
H
Hongze Cheng 已提交
108 109 110

# leveldb
if(${BUILD_WITH_LEVELDB})
H
more  
Hongze Cheng 已提交
111
    option(LEVELDB_BUILD_TESTS "" OFF)
H
Hongze Cheng 已提交
112 113 114 115 116 117 118 119
    add_subdirectory(leveldb)
    target_include_directories(
        leveldb
        PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/leveldb/include>
    )
endif(${BUILD_WITH_LEVELDB})

# rocksdb
H
Hongze Cheng 已提交
120
# To support rocksdb build on ubuntu: sudo apt-get install libgflags-dev
H
Hongze Cheng 已提交
121
if(${BUILD_WITH_ROCKSDB})
L
Liu Jicong 已提交
122
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=maybe-uninitialized")
H
Hongze Cheng 已提交
123 124
    option(WITH_TESTS "" OFF)
    option(WITH_BENCHMARK_TOOLS "" OFF)
L
Liu Jicong 已提交
125 126
    option(WITH_TOOLS "" OFF)
    option(WITH_LIBURING "" OFF)
H
refact  
Hongze Cheng 已提交
127
    option(ROCKSDB_BUILD_SHARED "Build shared versions of the RocksDB libraries" OFF)
H
Hongze Cheng 已提交
128 129 130 131 132 133
    add_subdirectory(rocksdb)
    target_include_directories(
        rocksdb
        PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/rocksdb/include>
    )
endif(${BUILD_WITH_ROCKSDB})
H
Hongze Cheng 已提交
134 135 136 137 138 139

# 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 已提交
140 141 142 143 144
    target_include_directories(
      lucene++ 
      PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lucene/include>
    ) 
     
H
Hongze Cheng 已提交
145
endif(${BUILD_WITH_LUCENE})
H
Hongze Cheng 已提交
146

H
Hongze Cheng 已提交
147 148 149 150 151
# NuRaft
if(${BUILD_WITH_NURAFT})
    add_subdirectory(nuraft)
endif(${BUILD_WITH_NURAFT})

M
Minghao Li 已提交
152 153 154 155 156 157 158 159 160 161 162 163
# 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"
        INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/craft"
    )
    target_link_libraries(craft
        INTERFACE pthread
    )
endif(${BUILD_WITH_CRAFT})

H
Hongze Cheng 已提交
164 165
# BDB
if(${BUILD_WITH_BDB})
166
    add_library(bdb STATIC IMPORTED GLOBAL)
H
Hongze Cheng 已提交
167 168 169 170
    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 已提交
171 172 173
    target_link_libraries(bdb 
        INTERFACE pthread 
    )
H
Hongze Cheng 已提交
174 175
endif(${BUILD_WITH_BDB})

H
Hongze Cheng 已提交
176
# SQLite
177
# see https://stackoverflow.com/questions/8774593/cmake-link-to-external-library#comment58570736_10550334
H
Hongze Cheng 已提交
178
if(${BUILD_WITH_SQLITE})
179
    add_library(sqlite STATIC IMPORTED GLOBAL)
H
Hongze Cheng 已提交
180 181
    set_target_properties(sqlite PROPERTIES
        IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/sqlite/.libs/libsqlite3.a"
H
Hongze Cheng 已提交
182 183
        INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/sqlite"
    )
H
Hongze Cheng 已提交
184 185 186 187 188
    target_link_libraries(sqlite 
        INTERFACE m 
        INTERFACE pthread 
        INTERFACE dl
    )
H
Hongze Cheng 已提交
189 190
endif(${BUILD_WITH_SQLITE})

H
Hongze Cheng 已提交
191

H
Hongze Cheng 已提交
192

H
Hongze Cheng 已提交
193
# ================================================================================================
H
Hongze Cheng 已提交
194
# Build test
H
Hongze Cheng 已提交
195 196 197 198
# ================================================================================================
if(${BUILD_DEPENDENCY_TESTS})
    add_subdirectory(test)
endif(${BUILD_DEPENDENCY_TESTS})