| 1 |
# Copyright 2017 The LevelDB Authors. All rights reserved. |
| 2 |
# Use of this source code is governed by a BSD-style license that can be |
| 3 |
# found in the LICENSE file. See the AUTHORS file for names of contributors. |
| 4 |
|
| 5 |
cmake_minimum_required(VERSION 3.9) |
| 6 |
# Keep the version below in sync with the one in db.h |
| 7 |
project(leveldb VERSION 1.23.0 LANGUAGES C CXX) |
| 8 |
|
| 9 |
# C standard can be overridden when this is used as a sub-project. |
| 10 |
if(NOT CMAKE_C_STANDARD) |
| 11 |
# This project can use C11, but will gracefully decay down to C89. |
| 12 |
set(CMAKE_C_STANDARD 11) |
| 13 |
set(CMAKE_C_STANDARD_REQUIRED OFF) |
| 14 |
set(CMAKE_C_EXTENSIONS OFF) |
| 15 |
endif(NOT CMAKE_C_STANDARD) |
| 16 |
|
| 17 |
# C++ standard can be overridden when this is used as a sub-project. |
| 18 |
if(NOT CMAKE_CXX_STANDARD) |
| 19 |
# This project requires C++11. |
| 20 |
set(CMAKE_CXX_STANDARD 11) |
| 21 |
set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 22 |
set(CMAKE_CXX_EXTENSIONS OFF) |
| 23 |
endif(NOT CMAKE_CXX_STANDARD) |
| 24 |
|
| 25 |
if (WIN32) |
| 26 |
set(LEVELDB_PLATFORM_NAME LEVELDB_PLATFORM_WINDOWS) |
| 27 |
# TODO(cmumford): Make UNICODE configurable for Windows. |
| 28 |
add_definitions(-D_UNICODE -DUNICODE) |
| 29 |
else (WIN32) |
| 30 |
set(LEVELDB_PLATFORM_NAME LEVELDB_PLATFORM_POSIX) |
| 31 |
endif (WIN32) |
| 32 |
|
| 33 |
option(LEVELDB_BUILD_TESTS "Build LevelDB's unit tests" ON) |
| 34 |
option(LEVELDB_BUILD_BENCHMARKS "Build LevelDB's benchmarks" ON) |
| 35 |
option(LEVELDB_INSTALL "Install LevelDB's header and library" ON) |
| 36 |
|
| 37 |
include(CheckIncludeFile) |
| 38 |
check_include_file("unistd.h" HAVE_UNISTD_H) |
| 39 |
|
| 40 |
include(CheckLibraryExists) |
| 41 |
check_library_exists(crc32c crc32c_value "" HAVE_CRC32C) |
| 42 |
check_library_exists(snappy snappy_compress "" HAVE_SNAPPY) |
| 43 |
check_library_exists(tcmalloc malloc "" HAVE_TCMALLOC) |
| 44 |
|
| 45 |
include(CheckCXXSymbolExists) |
| 46 |
# Using check_cxx_symbol_exists() instead of check_c_symbol_exists() because |
| 47 |
# we're including the header from C++, and feature detection should use the same |
| 48 |
# compiler language that the project will use later. Principles aside, some |
| 49 |
# versions of do not expose fdatasync() in <unistd.h> in standard C mode |
| 50 |
# (-std=c11), but do expose the function in standard C++ mode (-std=c++11). |
| 51 |
check_cxx_symbol_exists(fdatasync "unistd.h" HAVE_FDATASYNC) |
| 52 |
check_cxx_symbol_exists(F_FULLFSYNC "fcntl.h" HAVE_FULLFSYNC) |
| 53 |
check_cxx_symbol_exists(O_CLOEXEC "fcntl.h" HAVE_O_CLOEXEC) |
| 54 |
|
| 55 |
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") |
| 56 |
# Disable C++ exceptions. |
| 57 |
string(REGEX REPLACE "/EH[a-z]+" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
| 58 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHs-c-") |
| 59 |
add_definitions(-D_HAS_EXCEPTIONS=0) |
| 60 |
|
| 61 |
# Disable RTTI. |
| 62 |
string(REGEX REPLACE "/GR" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
| 63 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-") |
| 64 |
else(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") |
| 65 |
# Enable strict prototype warnings for C code in clang and gcc. |
| 66 |
if(NOT CMAKE_C_FLAGS MATCHES "-Wstrict-prototypes") |
| 67 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wstrict-prototypes") |
| 68 |
endif(NOT CMAKE_C_FLAGS MATCHES "-Wstrict-prototypes") |
| 69 |
|
| 70 |
# Disable C++ exceptions. |
| 71 |
string(REGEX REPLACE "-fexceptions" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
| 72 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions") |
| 73 |
|
| 74 |
# We need RTTI support if code that uses leveldb uses typeid (e.g. ceph). |
| 75 |
# string(REGEX REPLACE "-frtti" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") |
| 76 |
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti") |
| 77 |
endif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") |
| 78 |
|
| 79 |
# Test whether -Wthread-safety is available. See |
| 80 |
# https://clang.llvm.org/docs/ThreadSafetyAnalysis.html |
| 81 |
include(CheckCXXCompilerFlag) |
| 82 |
check_cxx_compiler_flag(-Wthread-safety HAVE_CLANG_THREAD_SAFETY) |
| 83 |
|
| 84 |
# Used by googletest. |
| 85 |
check_cxx_compiler_flag(-Wno-missing-field-initializers |
| 86 |
LEVELDB_HAVE_NO_MISSING_FIELD_INITIALIZERS) |
| 87 |
|
| 88 |
include(CheckCXXSourceCompiles) |
| 89 |
|
| 90 |
# Test whether C++17 __has_include is available. |
| 91 |
check_cxx_source_compiles(" |
| 92 |
#if defined(__has_include) && __has_include(<string>) |
| 93 |
#include <string> |
| 94 |
#endif |
| 95 |
int main() { std::string str; return 0; } |
| 96 |
" HAVE_CXX17_HAS_INCLUDE) |
| 97 |
|
| 98 |
set(LEVELDB_PUBLIC_INCLUDE_DIR "include/leveldb") |
| 99 |
set(LEVELDB_PORT_CONFIG_DIR "include/port") |
| 100 |
|
| 101 |
configure_file( |
| 102 |
"port/port_config.h.in" |
| 103 |
"${PROJECT_BINARY_DIR}/${LEVELDB_PORT_CONFIG_DIR}/port_config.h" |
| 104 |
) |
| 105 |
|
| 106 |
include_directories( |
| 107 |
"${PROJECT_BINARY_DIR}/include" |
| 108 |
"." |
| 109 |
) |
| 110 |
|
| 111 |
if(BUILD_SHARED_LIBS) |
| 112 |
# Only export LEVELDB_EXPORT symbols from the shared library. |
| 113 |
add_compile_options(-fvisibility=hidden) |
| 114 |
endif(BUILD_SHARED_LIBS) |
| 115 |
|
| 116 |
# Must be included before CMAKE_INSTALL_INCLUDEDIR is used. |
| 117 |
include(GNUInstallDirs) |
| 118 |
|
| 119 |
add_library(leveldb "") |
| 120 |
target_sources(leveldb |
| 121 |
PRIVATE |
| 122 |
"${PROJECT_BINARY_DIR}/${LEVELDB_PORT_CONFIG_DIR}/port_config.h" |
| 123 |
"db/builder.cc" |
| 124 |
"db/builder.h" |
| 125 |
"db/c.cc" |
| 126 |
"db/db_impl.cc" |
| 127 |
"db/db_impl.h" |
| 128 |
"db/db_iter.cc" |
| 129 |
"db/db_iter.h" |
| 130 |
"db/dbformat.cc" |
| 131 |
"db/dbformat.h" |
| 132 |
"db/dumpfile.cc" |
| 133 |
"db/filename.cc" |
| 134 |
"db/filename.h" |
| 135 |
"db/log_format.h" |
| 136 |
"db/log_reader.cc" |
| 137 |
"db/log_reader.h" |
| 138 |
"db/log_writer.cc" |
| 139 |
"db/log_writer.h" |
| 140 |
"db/memtable.cc" |
| 141 |
"db/memtable.h" |
| 142 |
"db/repair.cc" |
| 143 |
"db/skiplist.h" |
| 144 |
"db/snapshot.h" |
| 145 |
"db/table_cache.cc" |
| 146 |
"db/table_cache.h" |
| 147 |
"db/version_edit.cc" |
| 148 |
"db/version_edit.h" |
| 149 |
"db/version_set.cc" |
| 150 |
"db/version_set.h" |
| 151 |
"db/write_batch_internal.h" |
| 152 |
"db/write_batch.cc" |
| 153 |
"port/port_stdcxx.h" |
| 154 |
"port/port.h" |
| 155 |
"port/thread_annotations.h" |
| 156 |
"table/block_builder.cc" |
| 157 |
"table/block_builder.h" |
| 158 |
"table/block.cc" |
| 159 |
"table/block.h" |
| 160 |
"table/filter_block.cc" |
| 161 |
"table/filter_block.h" |
| 162 |
"table/format.cc" |
| 163 |
"table/format.h" |
| 164 |
"table/iterator_wrapper.h" |
| 165 |
"table/iterator.cc" |
| 166 |
"table/merger.cc" |
| 167 |
"table/merger.h" |
| 168 |
"table/table_builder.cc" |
| 169 |
"table/table.cc" |
| 170 |
"table/two_level_iterator.cc" |
| 171 |
"table/two_level_iterator.h" |
| 172 |
"util/arena.cc" |
| 173 |
"util/arena.h" |
| 174 |
"util/bloom.cc" |
| 175 |
"util/cache.cc" |
| 176 |
"util/coding.cc" |
| 177 |
"util/coding.h" |
| 178 |
"util/comparator.cc" |
| 179 |
"util/crc32c.cc" |
| 180 |
"util/crc32c.h" |
| 181 |
"util/env.cc" |
| 182 |
"util/filter_policy.cc" |
| 183 |
"util/hash.cc" |
| 184 |
"util/hash.h" |
| 185 |
"util/logging.cc" |
| 186 |
"util/logging.h" |
| 187 |
"util/mutexlock.h" |
| 188 |
"util/no_destructor.h" |
| 189 |
"util/options.cc" |
| 190 |
"util/random.h" |
| 191 |
"util/status.cc" |
| 192 |
|
| 193 |
# Only CMake 3.3+ supports PUBLIC sources in targets exported by "install". |
| 194 |
$<$<VERSION_GREATER:CMAKE_VERSION,3.2>:PUBLIC> |
| 195 |
"${LEVELDB_PUBLIC_INCLUDE_DIR}/c.h" |
| 196 |
"${LEVELDB_PUBLIC_INCLUDE_DIR}/cache.h" |
| 197 |
"${LEVELDB_PUBLIC_INCLUDE_DIR}/comparator.h" |
| 198 |
"${LEVELDB_PUBLIC_INCLUDE_DIR}/db.h" |
| 199 |
"${LEVELDB_PUBLIC_INCLUDE_DIR}/dumpfile.h" |
| 200 |
"${LEVELDB_PUBLIC_INCLUDE_DIR}/env.h" |
| 201 |
"${LEVELDB_PUBLIC_INCLUDE_DIR}/export.h" |
| 202 |
"${LEVELDB_PUBLIC_INCLUDE_DIR}/filter_policy.h" |
| 203 |
"${LEVELDB_PUBLIC_INCLUDE_DIR}/iterator.h" |
| 204 |
"${LEVELDB_PUBLIC_INCLUDE_DIR}/options.h" |
| 205 |
"${LEVELDB_PUBLIC_INCLUDE_DIR}/slice.h" |
| 206 |
"${LEVELDB_PUBLIC_INCLUDE_DIR}/status.h" |
| 207 |
"${LEVELDB_PUBLIC_INCLUDE_DIR}/table_builder.h" |
| 208 |
"${LEVELDB_PUBLIC_INCLUDE_DIR}/table.h" |
| 209 |
"${LEVELDB_PUBLIC_INCLUDE_DIR}/write_batch.h" |
| 210 |
) |
| 211 |
|
| 212 |
if (WIN32) |
| 213 |
target_sources(leveldb |
| 214 |
PRIVATE |
| 215 |
"util/env_windows.cc" |
| 216 |
"util/windows_logger.h" |
| 217 |
) |
| 218 |
else (WIN32) |
| 219 |
target_sources(leveldb |
| 220 |
PRIVATE |
| 221 |
"util/env_posix.cc" |
| 222 |
"util/posix_logger.h" |
| 223 |
) |
| 224 |
endif (WIN32) |
| 225 |
|
| 226 |
# MemEnv is not part of the interface and could be pulled to a separate library. |
| 227 |
target_sources(leveldb |
| 228 |
PRIVATE |
| 229 |
"helpers/memenv/memenv.cc" |
| 230 |
"helpers/memenv/memenv.h" |
| 231 |
) |
| 232 |
|
| 233 |
if(NOT BUILD_SHARED_LIBS) |
| 234 |
# Build static MemEnv library. |
| 235 |
add_library(memenv "") |
| 236 |
target_sources(memenv |
| 237 |
PRIVATE |
| 238 |
"${PROJECT_SOURCE_DIR}/helpers/memenv/memenv.cc" |
| 239 |
"${PROJECT_SOURCE_DIR}/helpers/memenv/memenv.h" |
| 240 |
) |
| 241 |
endif(NOT BUILD_SHARED_LIBS) |
| 242 |
|
| 243 |
target_include_directories(leveldb |
| 244 |
PUBLIC |
| 245 |
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> |
| 246 |
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> |
| 247 |
) |
| 248 |
|
| 249 |
if(NOT BUILD_SHARED_LIBS) |
| 250 |
target_include_directories(memenv |
| 251 |
PUBLIC |
| 252 |
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> |
| 253 |
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> |
| 254 |
) |
| 255 |
endif(NOT BUILD_SHARED_LIBS) |
| 256 |
|
| 257 |
set_target_properties(leveldb |
| 258 |
PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}d) |
| 259 |
|
| 260 |
target_compile_definitions(leveldb |
| 261 |
PRIVATE |
| 262 |
# Used by include/export.h when building shared libraries. |
| 263 |
LEVELDB_COMPILE_LIBRARY |
| 264 |
# Used by port/port.h. |
| 265 |
${LEVELDB_PLATFORM_NAME}=1 |
| 266 |
) |
| 267 |
if (NOT HAVE_CXX17_HAS_INCLUDE) |
| 268 |
target_compile_definitions(leveldb |
| 269 |
PRIVATE |
| 270 |
LEVELDB_HAS_PORT_CONFIG_H=1 |
| 271 |
) |
| 272 |
endif(NOT HAVE_CXX17_HAS_INCLUDE) |
| 273 |
|
| 274 |
if(NOT BUILD_SHARED_LIBS) |
| 275 |
target_compile_definitions(memenv |
| 276 |
PRIVATE |
| 277 |
# Used by include/export.h when building shared libraries. |
| 278 |
LEVELDB_COMPILE_LIBRARY |
| 279 |
# Used by port/port.h. |
| 280 |
${LEVELDB_PLATFORM_NAME}=1 |
| 281 |
) |
| 282 |
endif(NOT BUILD_SHARED_LIBS) |
| 283 |
|
| 284 |
if(BUILD_SHARED_LIBS) |
| 285 |
target_compile_definitions(leveldb |
| 286 |
PUBLIC |
| 287 |
# Used by include/export.h. |
| 288 |
LEVELDB_SHARED_LIBRARY |
| 289 |
) |
| 290 |
endif(BUILD_SHARED_LIBS) |
| 291 |
|
| 292 |
if(HAVE_CLANG_THREAD_SAFETY) |
| 293 |
target_compile_options(leveldb |
| 294 |
PUBLIC |
| 295 |
-Werror -Wthread-safety) |
| 296 |
endif(HAVE_CLANG_THREAD_SAFETY) |
| 297 |
|
| 298 |
if(HAVE_CRC32C) |
| 299 |
target_link_libraries(leveldb crc32c) |
| 300 |
endif(HAVE_CRC32C) |
| 301 |
if(HAVE_SNAPPY) |
| 302 |
target_link_libraries(leveldb snappy) |
| 303 |
endif(HAVE_SNAPPY) |
| 304 |
if(HAVE_TCMALLOC) |
| 305 |
target_link_libraries(leveldb tcmalloc) |
| 306 |
endif(HAVE_TCMALLOC) |
| 307 |
|
| 308 |
# Needed by port_stdcxx.h |
| 309 |
find_package(Threads REQUIRED) |
| 310 |
target_link_libraries(leveldb Threads::Threads) |
| 311 |
|
| 312 |
add_executable(leveldbutil |
| 313 |
"db/leveldbutil.cc" |
| 314 |
) |
| 315 |
target_link_libraries(leveldbutil leveldb) |
| 316 |
|
| 317 |
if(LEVELDB_BUILD_TESTS) |
| 318 |
enable_testing() |
| 319 |
|
| 320 |
# Prevent overriding the parent project's compiler/linker settings on Windows. |
| 321 |
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) |
| 322 |
set(install_gtest OFF) |
| 323 |
set(install_gmock OFF) |
| 324 |
set(build_gmock ON) |
| 325 |
|
| 326 |
# This project is tested using GoogleTest. |
| 327 |
#add_subdirectory("third_party/googletest") |
| 328 |
|
| 329 |
# This project uses Google benchmark for benchmarking. |
| 330 |
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE) |
| 331 |
set(BENCHMARK_ENABLE_EXCEPTIONS OFF CACHE BOOL "" FORCE) |
| 332 |
#add_subdirectory("third_party/benchmark") |
| 333 |
|
| 334 |
# GoogleTest triggers a missing field initializers warning. |
| 335 |
if(LEVELDB_HAVE_NO_MISSING_FIELD_INITIALIZERS) |
| 336 |
# set_property(TARGET gtest |
| 337 |
# APPEND PROPERTY COMPILE_OPTIONS -Wno-missing-field-initializers) |
| 338 |
# set_property(TARGET gmock |
| 339 |
# APPEND PROPERTY COMPILE_OPTIONS -Wno-missing-field-initializers) |
| 340 |
endif(LEVELDB_HAVE_NO_MISSING_FIELD_INITIALIZERS) |
| 341 |
|
| 342 |
function(leveldb_test test_file) |
| 343 |
get_filename_component(test_target_name "${test_file}" NAME_WE) |
| 344 |
|
| 345 |
add_executable("${test_target_name}" "") |
| 346 |
target_sources("${test_target_name}" |
| 347 |
PRIVATE |
| 348 |
"${PROJECT_BINARY_DIR}/${LEVELDB_PORT_CONFIG_DIR}/port_config.h" |
| 349 |
"util/testutil.cc" |
| 350 |
"util/testutil.h" |
| 351 |
|
| 352 |
"${test_file}" |
| 353 |
) |
| 354 |
target_link_libraries("${test_target_name}" leveldb gmock gtest benchmark) |
| 355 |
target_compile_definitions("${test_target_name}" |
| 356 |
PRIVATE |
| 357 |
${LEVELDB_PLATFORM_NAME}=1 |
| 358 |
) |
| 359 |
if (NOT HAVE_CXX17_HAS_INCLUDE) |
| 360 |
target_compile_definitions("${test_target_name}" |
| 361 |
PRIVATE |
| 362 |
LEVELDB_HAS_PORT_CONFIG_H=1 |
| 363 |
) |
| 364 |
endif(NOT HAVE_CXX17_HAS_INCLUDE) |
| 365 |
|
| 366 |
add_test(NAME "${test_target_name}" COMMAND "${test_target_name}") |
| 367 |
endfunction(leveldb_test) |
| 368 |
|
| 369 |
leveldb_test("db/c_test.c") |
| 370 |
leveldb_test("db/fault_injection_test.cc") |
| 371 |
|
| 372 |
leveldb_test("issues/issue178_test.cc") |
| 373 |
leveldb_test("issues/issue200_test.cc") |
| 374 |
leveldb_test("issues/issue320_test.cc") |
| 375 |
|
| 376 |
leveldb_test("util/env_test.cc") |
| 377 |
leveldb_test("util/status_test.cc") |
| 378 |
leveldb_test("util/no_destructor_test.cc") |
| 379 |
|
| 380 |
if(NOT BUILD_SHARED_LIBS) |
| 381 |
leveldb_test("db/autocompact_test.cc") |
| 382 |
leveldb_test("db/corruption_test.cc") |
| 383 |
leveldb_test("db/db_test.cc") |
| 384 |
leveldb_test("db/dbformat_test.cc") |
| 385 |
leveldb_test("db/filename_test.cc") |
| 386 |
leveldb_test("db/log_test.cc") |
| 387 |
leveldb_test("db/recovery_test.cc") |
| 388 |
leveldb_test("db/skiplist_test.cc") |
| 389 |
leveldb_test("db/version_edit_test.cc") |
| 390 |
leveldb_test("db/version_set_test.cc") |
| 391 |
leveldb_test("db/write_batch_test.cc") |
| 392 |
|
| 393 |
leveldb_test("helpers/memenv/memenv_test.cc") |
| 394 |
|
| 395 |
leveldb_test("table/filter_block_test.cc") |
| 396 |
leveldb_test("table/table_test.cc") |
| 397 |
|
| 398 |
leveldb_test("util/arena_test.cc") |
| 399 |
leveldb_test("util/bloom_test.cc") |
| 400 |
leveldb_test("util/cache_test.cc") |
| 401 |
leveldb_test("util/coding_test.cc") |
| 402 |
leveldb_test("util/crc32c_test.cc") |
| 403 |
leveldb_test("util/hash_test.cc") |
| 404 |
leveldb_test("util/logging_test.cc") |
| 405 |
|
| 406 |
# TODO(costan): This test also uses |
| 407 |
# "util/env_{posix|windows}_test_helper.h" |
| 408 |
if (WIN32) |
| 409 |
leveldb_test("util/env_windows_test.cc") |
| 410 |
else (WIN32) |
| 411 |
leveldb_test("util/env_posix_test.cc") |
| 412 |
endif (WIN32) |
| 413 |
endif(NOT BUILD_SHARED_LIBS) |
| 414 |
endif(LEVELDB_BUILD_TESTS) |
| 415 |
|
| 416 |
if(LEVELDB_BUILD_BENCHMARKS) |
| 417 |
function(leveldb_benchmark bench_file) |
| 418 |
get_filename_component(bench_target_name "${bench_file}" NAME_WE) |
| 419 |
|
| 420 |
add_executable("${bench_target_name}" "") |
| 421 |
target_sources("${bench_target_name}" |
| 422 |
PRIVATE |
| 423 |
"${PROJECT_BINARY_DIR}/${LEVELDB_PORT_CONFIG_DIR}/port_config.h" |
| 424 |
"util/histogram.cc" |
| 425 |
"util/histogram.h" |
| 426 |
"util/testutil.cc" |
| 427 |
"util/testutil.h" |
| 428 |
|
| 429 |
"${bench_file}" |
| 430 |
) |
| 431 |
target_link_libraries("${bench_target_name}" leveldb gmock gtest) |
| 432 |
target_compile_definitions("${bench_target_name}" |
| 433 |
PRIVATE |
| 434 |
${LEVELDB_PLATFORM_NAME}=1 |
| 435 |
) |
| 436 |
if (NOT HAVE_CXX17_HAS_INCLUDE) |
| 437 |
target_compile_definitions("${bench_target_name}" |
| 438 |
PRIVATE |
| 439 |
LEVELDB_HAS_PORT_CONFIG_H=1 |
| 440 |
) |
| 441 |
endif(NOT HAVE_CXX17_HAS_INCLUDE) |
| 442 |
endfunction(leveldb_benchmark) |
| 443 |
|
| 444 |
if(NOT BUILD_SHARED_LIBS) |
| 445 |
leveldb_benchmark("benchmarks/db_bench.cc") |
| 446 |
endif(NOT BUILD_SHARED_LIBS) |
| 447 |
|
| 448 |
check_library_exists(sqlite3 sqlite3_open "" HAVE_SQLITE3) |
| 449 |
if(HAVE_SQLITE3) |
| 450 |
leveldb_benchmark("benchmarks/db_bench_sqlite3.cc") |
| 451 |
target_link_libraries(db_bench_sqlite3 sqlite3) |
| 452 |
endif(HAVE_SQLITE3) |
| 453 |
|
| 454 |
# check_library_exists is insufficient here because the library names have |
| 455 |
# different manglings when compiled with clang or gcc, at least when installed |
| 456 |
# with Homebrew on Mac. |
| 457 |
set(OLD_CMAKE_REQURED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) |
| 458 |
list(APPEND CMAKE_REQUIRED_LIBRARIES kyotocabinet) |
| 459 |
check_cxx_source_compiles(" |
| 460 |
#include <kcpolydb.h> |
| 461 |
|
| 462 |
int main() { |
| 463 |
kyotocabinet::TreeDB* db = new kyotocabinet::TreeDB(); |
| 464 |
delete db; |
| 465 |
return 0; |
| 466 |
} |
| 467 |
" HAVE_KYOTOCABINET) |
| 468 |
set(CMAKE_REQUIRED_LIBRARIES ${OLD_CMAKE_REQURED_LIBRARIES}) |
| 469 |
if(HAVE_KYOTOCABINET) |
| 470 |
leveldb_benchmark("benchmarks/db_bench_tree_db.cc") |
| 471 |
target_link_libraries(db_bench_tree_db kyotocabinet) |
| 472 |
endif(HAVE_KYOTOCABINET) |
| 473 |
endif(LEVELDB_BUILD_BENCHMARKS) |
| 474 |
|
| 475 |
if(LEVELDB_INSTALL) |
| 476 |
install(TARGETS leveldb |
| 477 |
EXPORT leveldbTargets |
| 478 |
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} |
| 479 |
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 480 |
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 481 |
) |
| 482 |
install( |
| 483 |
FILES |
| 484 |
"${LEVELDB_PUBLIC_INCLUDE_DIR}/c.h" |
| 485 |
"${LEVELDB_PUBLIC_INCLUDE_DIR}/cache.h" |
| 486 |
"${LEVELDB_PUBLIC_INCLUDE_DIR}/comparator.h" |
| 487 |
"${LEVELDB_PUBLIC_INCLUDE_DIR}/db.h" |
| 488 |
"${LEVELDB_PUBLIC_INCLUDE_DIR}/dumpfile.h" |
| 489 |
"${LEVELDB_PUBLIC_INCLUDE_DIR}/env.h" |
| 490 |
"${LEVELDB_PUBLIC_INCLUDE_DIR}/export.h" |
| 491 |
"${LEVELDB_PUBLIC_INCLUDE_DIR}/filter_policy.h" |
| 492 |
"${LEVELDB_PUBLIC_INCLUDE_DIR}/iterator.h" |
| 493 |
"${LEVELDB_PUBLIC_INCLUDE_DIR}/options.h" |
| 494 |
"${LEVELDB_PUBLIC_INCLUDE_DIR}/slice.h" |
| 495 |
"${LEVELDB_PUBLIC_INCLUDE_DIR}/status.h" |
| 496 |
"${LEVELDB_PUBLIC_INCLUDE_DIR}/table_builder.h" |
| 497 |
"${LEVELDB_PUBLIC_INCLUDE_DIR}/table.h" |
| 498 |
"${LEVELDB_PUBLIC_INCLUDE_DIR}/write_batch.h" |
| 499 |
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/leveldb" |
| 500 |
) |
| 501 |
|
| 502 |
include(CMakePackageConfigHelpers) |
| 503 |
configure_package_config_file( |
| 504 |
"cmake/${PROJECT_NAME}Config.cmake.in" |
| 505 |
"${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}Config.cmake" |
| 506 |
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" |
| 507 |
) |
| 508 |
write_basic_package_version_file( |
| 509 |
"${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}ConfigVersion.cmake" |
| 510 |
COMPATIBILITY SameMajorVersion |
| 511 |
) |
| 512 |
install( |
| 513 |
EXPORT leveldbTargets |
| 514 |
NAMESPACE leveldb:: |
| 515 |
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" |
| 516 |
) |
| 517 |
install( |
| 518 |
FILES |
| 519 |
"${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}Config.cmake" |
| 520 |
"${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}ConfigVersion.cmake" |
| 521 |
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" |
| 522 |
) |
| 523 |
if(NOT BUILD_SHARED_LIBS) |
| 524 |
install( |
| 525 |
FILES |
| 526 |
"${PROJECT_SOURCE_DIR}/helpers/memenv/memenv.h" |
| 527 |
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/leveldb/helpers |
| 528 |
) |
| 529 |
install(TARGETS memenv |
| 530 |
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 531 |
) |
| 532 |
endif(NOT BUILD_SHARED_LIBS) |
| 533 |
endif(LEVELDB_INSTALL) |