CMakeLists.txt 7.0 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
if(${BUILD_TEST})
    cat("${CMAKE_SUPPORT_DIR}/gtest_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
X
Xiaoyu Wang 已提交
15
    cat("${CMAKE_SUPPORT_DIR}/stub_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
H
Hongze Cheng 已提交
16 17
endif(${BUILD_TEST})

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

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

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

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

H
Hongze Cheng 已提交
32
# rocksdb
H
Hongze Cheng 已提交
33 34 35 36 37
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 已提交
38 39 40
# canonical-raft
if(${BUILD_WITH_CRAFT})
    cat("${CMAKE_SUPPORT_DIR}/craft_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
H
Hongze Cheng 已提交
41
    SET(BUILD_WITH_UV ON CACHE BOOL "craft need libuv" FORCE)
M
Minghao Li 已提交
42 43
endif(${BUILD_WITH_CRAFT})

H
Hongze Cheng 已提交
44 45 46 47 48
#libuv
if(${BUILD_WITH_UV})
    cat("${CMAKE_SUPPORT_DIR}/libuv_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
endif(${BUILD_WITH_UV})

H
Hongze Cheng 已提交
49
# bdb
H
Hongze Cheng 已提交
50 51
if(${BUILD_WITH_BDB})
    cat("${CMAKE_SUPPORT_DIR}/bdb_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
H
Hongze Cheng 已提交
52
endif(${BUILD_WITH_BDB})
H
Hongze Cheng 已提交
53

H
Hongze Cheng 已提交
54
# sqlite
H
Hongze Cheng 已提交
55 56 57 58
if(${BUILD_WITH_SQLITE})
    cat("${CMAKE_SUPPORT_DIR}/sqlite_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
endif(${BUILD_WITH_SQLITE})

H
Hongze Cheng 已提交
59
# lucene
H
Hongze Cheng 已提交
60 61 62 63 64
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 已提交
65
# NuRaft
H
Hongze Cheng 已提交
66 67 68 69
if(${BUILD_WITH_NURAFT})
    cat("${CMAKE_SUPPORT_DIR}/nuraft_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
endif(${BUILD_WITH_NURAFT})

H
Hongze Cheng 已提交
70
# download dependencies
H
Hongze Cheng 已提交
71 72 73 74 75 76
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 已提交
77
# ================================================================================================
H
Hongze Cheng 已提交
78
# Build
H
Hongze Cheng 已提交
79
# ================================================================================================
H
Hongze Cheng 已提交
80
# googletest
H
refact  
Hongze Cheng 已提交
81 82
if(${BUILD_TEST})
    add_subdirectory(googletest)
X
Xiaoyu Wang 已提交
83 84 85 86 87
    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 已提交
88
endif(${BUILD_TEST})
H
refact  
Hongze Cheng 已提交
89

H
Hongze Cheng 已提交
90
# cJson
H
Hongze Cheng 已提交
91 92
# 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 已提交
93 94 95
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 已提交
96
add_subdirectory(cJson)
S
Shengliang Guan 已提交
97 98
target_include_directories(
    cjson
H
Hongze Cheng 已提交
99 100
    # 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 已提交
101
)
H
Hongze Cheng 已提交
102
unset(CMAKE_PROJECT_INCLUDE_BEFORE)
S
Shengliang Guan 已提交
103

H
Hongze Cheng 已提交
104
# lz4
H
refact  
Hongze Cheng 已提交
105
add_subdirectory(lz4/build/cmake)
S
Shengliang Guan 已提交
106 107 108 109 110
target_include_directories(
    lz4_static
    PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/lz4/lib
)

H
Hongze Cheng 已提交
111
# zlib
H
Hongze Cheng 已提交
112
set(CMAKE_PROJECT_INCLUDE_BEFORE "${CMAKE_SUPPORT_DIR}/EnableCMP0048.txt.in")
H
Hongze Cheng 已提交
113 114 115 116 117 118
add_subdirectory(zlib)
target_include_directories(
    zlib
    PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/zlib
    PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/zlib
)
H
Hongze Cheng 已提交
119
unset(CMAKE_PROJECT_INCLUDE_BEFORE)
H
Hongze Cheng 已提交
120 121 122

# leveldb
if(${BUILD_WITH_LEVELDB})
H
more  
Hongze Cheng 已提交
123
    option(LEVELDB_BUILD_TESTS "" OFF)
H
Hongze Cheng 已提交
124 125 126 127 128 129 130 131
    add_subdirectory(leveldb)
    target_include_directories(
        leveldb
        PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/leveldb/include>
    )
endif(${BUILD_WITH_LEVELDB})

# rocksdb
H
Hongze Cheng 已提交
132
# To support rocksdb build on ubuntu: sudo apt-get install libgflags-dev
H
Hongze Cheng 已提交
133
if(${BUILD_WITH_ROCKSDB})
L
Liu Jicong 已提交
134
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=maybe-uninitialized")
H
Hongze Cheng 已提交
135 136
    option(WITH_TESTS "" OFF)
    option(WITH_BENCHMARK_TOOLS "" OFF)
L
Liu Jicong 已提交
137 138
    option(WITH_TOOLS "" OFF)
    option(WITH_LIBURING "" OFF)
H
refact  
Hongze Cheng 已提交
139
    option(ROCKSDB_BUILD_SHARED "Build shared versions of the RocksDB libraries" OFF)
H
Hongze Cheng 已提交
140 141 142 143 144 145
    add_subdirectory(rocksdb)
    target_include_directories(
        rocksdb
        PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/rocksdb/include>
    )
endif(${BUILD_WITH_ROCKSDB})
H
Hongze Cheng 已提交
146 147 148 149 150 151

# 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 已提交
152 153 154 155 156
    target_include_directories(
      lucene++ 
      PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lucene/include>
    ) 
     
H
Hongze Cheng 已提交
157
endif(${BUILD_WITH_LUCENE})
H
Hongze Cheng 已提交
158

H
Hongze Cheng 已提交
159 160 161 162 163
# NuRaft
if(${BUILD_WITH_NURAFT})
    add_subdirectory(nuraft)
endif(${BUILD_WITH_NURAFT})

M
Minghao Li 已提交
164 165 166 167 168
# 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 已提交
169
        INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/craft/include"
M
Minghao Li 已提交
170
    )
H
Hongze Cheng 已提交
171 172 173
    # target_link_libraries(craft
    #     INTERFACE pthread
    # )
M
Minghao Li 已提交
174 175
endif(${BUILD_WITH_CRAFT})

H
Hongze Cheng 已提交
176 177 178 179 180
# LIBUV
if(${BUILD_WITH_UV})
    add_subdirectory(libuv)
endif(${BUILD_WITH_UV})

H
Hongze Cheng 已提交
181 182
# BDB
if(${BUILD_WITH_BDB})
183
    add_library(bdb STATIC IMPORTED GLOBAL)
H
Hongze Cheng 已提交
184 185 186 187
    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 已提交
188 189 190
    target_link_libraries(bdb 
        INTERFACE pthread 
    )
H
Hongze Cheng 已提交
191 192
endif(${BUILD_WITH_BDB})

H
Hongze Cheng 已提交
193
# SQLite
194
# see https://stackoverflow.com/questions/8774593/cmake-link-to-external-library#comment58570736_10550334
H
Hongze Cheng 已提交
195
if(${BUILD_WITH_SQLITE})
196
    add_library(sqlite STATIC IMPORTED GLOBAL)
H
Hongze Cheng 已提交
197 198
    set_target_properties(sqlite PROPERTIES
        IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/sqlite/.libs/libsqlite3.a"
H
Hongze Cheng 已提交
199 200
        INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/sqlite"
    )
H
Hongze Cheng 已提交
201 202 203 204 205
    target_link_libraries(sqlite 
        INTERFACE m 
        INTERFACE pthread 
        INTERFACE dl
    )
H
Hongze Cheng 已提交
206 207
endif(${BUILD_WITH_SQLITE})

H
Hongze Cheng 已提交
208

H
Hongze Cheng 已提交
209

H
Hongze Cheng 已提交
210
# ================================================================================================
H
Hongze Cheng 已提交
211
# Build test
H
Hongze Cheng 已提交
212 213 214 215
# ================================================================================================
if(${BUILD_DEPENDENCY_TESTS})
    add_subdirectory(test)
endif(${BUILD_DEPENDENCY_TESTS})