作者: 谢瑞阳 10225101483 徐翔宇 10225101535
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

495 行
15 KiB

leveldb: Fix PosixWritableFile::Sync() on Apple systems. Apple doesn't follow POSIX specifications for fsync(). Instead, fsync() guarantees to flush the buffer cache to the device, which means the data will survive kernel panics, but may not survive power outages. Applications that need stronger guarantees (like databases) need to use fcntl(F_FULLFSYNC). This CL switches PosixWritableFile::Sync() to get the stronger guarantees on Apple systems. The improved implementation follows the same principles as SQLite [1] and node.js [2]. Research for the fcntl() to fsync() fallback strategy: Apple's released source code at https://opensource.apple.com/ shows at least three different error codes being returned when a filesystem does not support F_FULLFSYNC. fcntl() is implemented in xnu-4903.221.2 in bsd/kern/kern_descrip.c, where it delegates to fcntl_nocancel(). The documentation for fcntl_nocancel() mentions error codes for some operations, but does not include F_FULLFSYNC. The F_FULLSYNC branch in fcntl_nocancel() calls VNOP_IOCTL(_, F_FULLSYNC, NULL, 0, _), whose return value sets the error code. VNOP_IOCTL() is implemented in bsd/vfs/kpi_vfs.c and calls the ioctl function in the vnode's operation vector. The per-filesystem function names follow the pattern _vnop_ioctl() for all the instances in opensource code: {hfs,msdosfs,nfs,ntfs,smbfs,webdav,zfs}_vnop_ioctl(). hfs-407.30.1, msdosfs-229.200.3, and nfs in xnu-4903.221.2 handle F_FULLFSYNC. ntfs-94.200.1 and smb-759.40.1 do not handle F_FULLFSYNC, and the default branch returns ENOSUP. webdav-380.200.1 also does not handle F_FULLFSYNC, but the default branch returns EINVAL. zfs-59 also does not handle F_FULLSYNC, and its default branch returns ENOTTY. From a different angle, Apple's ntfs-94.200.1 includes utility code that uses fcntl(F_FULLFSYNC) and falls back to fsync() just like we do, supporting the hypothesis that there is no good way to detect lack of F_FULLFSYNC support. Also, Apple's fcntl() man page [3] does not mention a way to detect lack of F_FULLFSYNC support. [1] https://www.sqlite.org/src/doc/trunk/src/os_unix.c [2] https://github.com/libuv/libuv/blob/master/src/unix/fs.c [3] https://developer.apple.com/library/archive/documentatiVon/System/Conceptual/ManPages_iPhoneOS/man2/fcntl.2.html Tested: https://travis-ci.org/pwnall/leveldb/builds/477318498 TAP global presubmit ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=228593729
5年前
  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. cmake_minimum_required(VERSION 3.9)
  5. # Keep the version below in sync with the one in db.h
  6. project(leveldb VERSION 1.23.0 LANGUAGES C CXX)
  7. # C standard can be overridden when this is used as a sub-project.
  8. if(NOT CMAKE_C_STANDARD)
  9. # This project can use C11, but will gracefully decay down to C89.
  10. set(CMAKE_C_STANDARD 11)
  11. set(CMAKE_C_STANDARD_REQUIRED OFF)
  12. set(CMAKE_C_EXTENSIONS OFF)
  13. endif(NOT CMAKE_C_STANDARD)
  14. # C++ standard can be overridden when this is used as a sub-project.
  15. if(NOT CMAKE_CXX_STANDARD)
  16. # This project requires C++11.
  17. set(CMAKE_CXX_STANDARD 11)
  18. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  19. set(CMAKE_CXX_EXTENSIONS OFF)
  20. endif(NOT CMAKE_CXX_STANDARD)
  21. if (WIN32)
  22. set(LEVELDB_PLATFORM_NAME LEVELDB_PLATFORM_WINDOWS)
  23. # TODO(cmumford): Make UNICODE configurable for Windows.
  24. add_definitions(-D_UNICODE -DUNICODE)
  25. else (WIN32)
  26. set(LEVELDB_PLATFORM_NAME LEVELDB_PLATFORM_POSIX)
  27. endif (WIN32)
  28. option(LEVELDB_BUILD_TESTS "Build LevelDB's unit tests" ON)
  29. option(LEVELDB_BUILD_BENCHMARKS "Build LevelDB's benchmarks" ON)
  30. option(LEVELDB_INSTALL "Install LevelDB's header and library" ON)
  31. include(CheckIncludeFile)
  32. check_include_file("unistd.h" HAVE_UNISTD_H)
  33. include(CheckLibraryExists)
  34. check_library_exists(crc32c crc32c_value "" HAVE_CRC32C)
  35. check_library_exists(snappy snappy_compress "" HAVE_SNAPPY)
  36. check_library_exists(tcmalloc malloc "" HAVE_TCMALLOC)
  37. include(CheckCXXSymbolExists)
  38. # Using check_cxx_symbol_exists() instead of check_c_symbol_exists() because
  39. # we're including the header from C++, and feature detection should use the same
  40. # compiler language that the project will use later. Principles aside, some
  41. # versions of do not expose fdatasync() in <unistd.h> in standard C mode
  42. # (-std=c11), but do expose the function in standard C++ mode (-std=c++11).
  43. check_cxx_symbol_exists(fdatasync "unistd.h" HAVE_FDATASYNC)
  44. check_cxx_symbol_exists(F_FULLFSYNC "fcntl.h" HAVE_FULLFSYNC)
  45. check_cxx_symbol_exists(O_CLOEXEC "fcntl.h" HAVE_O_CLOEXEC)
  46. if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
  47. # Disable C++ exceptions.
  48. string(REGEX REPLACE "/EH[a-z]+" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
  49. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHs-c-")
  50. add_definitions(-D_HAS_EXCEPTIONS=0)
  51. # Disable RTTI.
  52. string(REGEX REPLACE "/GR" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
  53. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
  54. else(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
  55. # Enable strict prototype warnings for C code in clang and gcc.
  56. if(NOT CMAKE_C_FLAGS MATCHES "-Wstrict-prototypes")
  57. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wstrict-prototypes")
  58. endif(NOT CMAKE_C_FLAGS MATCHES "-Wstrict-prototypes")
  59. # Disable C++ exceptions.
  60. string(REGEX REPLACE "-fexceptions" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
  61. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")
  62. # Disable RTTI.
  63. string(REGEX REPLACE "-frtti" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
  64. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
  65. endif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
  66. # Test whether -Wthread-safety is available. See
  67. # https://clang.llvm.org/docs/ThreadSafetyAnalysis.html
  68. include(CheckCXXCompilerFlag)
  69. check_cxx_compiler_flag(-Wthread-safety HAVE_CLANG_THREAD_SAFETY)
  70. # Used by googletest.
  71. check_cxx_compiler_flag(-Wno-missing-field-initializers
  72. LEVELDB_HAVE_NO_MISSING_FIELD_INITIALIZERS)
  73. include(CheckCXXSourceCompiles)
  74. # Test whether C++17 __has_include is available.
  75. check_cxx_source_compiles("
  76. #if defined(__has_include) && __has_include(<string>)
  77. #include <string>
  78. #endif
  79. int main() { std::string str; return 0; }
  80. " HAVE_CXX17_HAS_INCLUDE)
  81. set(LEVELDB_PUBLIC_INCLUDE_DIR "include/leveldb")
  82. set(LEVELDB_PORT_CONFIG_DIR "include/port")
  83. configure_file(
  84. "port/port_config.h.in"
  85. "${PROJECT_BINARY_DIR}/${LEVELDB_PORT_CONFIG_DIR}/port_config.h"
  86. )
  87. include_directories(
  88. "${PROJECT_BINARY_DIR}/include"
  89. "."
  90. )
  91. if(BUILD_SHARED_LIBS)
  92. # Only export LEVELDB_EXPORT symbols from the shared library.
  93. add_compile_options(-fvisibility=hidden)
  94. endif(BUILD_SHARED_LIBS)
  95. # Must be included before CMAKE_INSTALL_INCLUDEDIR is used.
  96. include(GNUInstallDirs)
  97. add_library(leveldb "")
  98. target_sources(leveldb
  99. PRIVATE
  100. "${PROJECT_BINARY_DIR}/${LEVELDB_PORT_CONFIG_DIR}/port_config.h"
  101. "db/builder.cc"
  102. "db/builder.h"
  103. "db/c.cc"
  104. "db/db_impl.cc"
  105. "db/db_impl.h"
  106. "db/db_iter.cc"
  107. "db/db_iter.h"
  108. "db/dbformat.cc"
  109. "db/dbformat.h"
  110. "db/dumpfile.cc"
  111. "db/filename.cc"
  112. "db/filename.h"
  113. "db/log_format.h"
  114. "db/log_reader.cc"
  115. "db/log_reader.h"
  116. "db/log_writer.cc"
  117. "db/log_writer.h"
  118. "db/memtable.cc"
  119. "db/memtable.h"
  120. "db/repair.cc"
  121. "db/skiplist.h"
  122. "db/snapshot.h"
  123. "db/table_cache.cc"
  124. "db/table_cache.h"
  125. "db/version_edit.cc"
  126. "db/version_edit.h"
  127. "db/version_set.cc"
  128. "db/version_set.h"
  129. "db/write_batch_internal.h"
  130. "db/write_batch.cc"
  131. "port/port_stdcxx.h"
  132. "port/port.h"
  133. "port/thread_annotations.h"
  134. "table/block_builder.cc"
  135. "table/block_builder.h"
  136. "table/block.cc"
  137. "table/block.h"
  138. "table/filter_block.cc"
  139. "table/filter_block.h"
  140. "table/format.cc"
  141. "table/format.h"
  142. "table/iterator_wrapper.h"
  143. "table/iterator.cc"
  144. "table/merger.cc"
  145. "table/merger.h"
  146. "table/table_builder.cc"
  147. "table/table.cc"
  148. "table/two_level_iterator.cc"
  149. "table/two_level_iterator.h"
  150. "util/arena.cc"
  151. "util/arena.h"
  152. "util/bloom.cc"
  153. "util/cache.cc"
  154. "util/coding.cc"
  155. "util/coding.h"
  156. "util/comparator.cc"
  157. "util/crc32c.cc"
  158. "util/crc32c.h"
  159. "util/env.cc"
  160. "util/filter_policy.cc"
  161. "util/hash.cc"
  162. "util/hash.h"
  163. "util/logging.cc"
  164. "util/logging.h"
  165. "util/mutexlock.h"
  166. "util/no_destructor.h"
  167. "util/options.cc"
  168. "util/random.h"
  169. "util/status.cc"
  170. # Only CMake 3.3+ supports PUBLIC sources in targets exported by "install".
  171. $<$<VERSION_GREATER:CMAKE_VERSION,3.2>:PUBLIC>
  172. "${LEVELDB_PUBLIC_INCLUDE_DIR}/c.h"
  173. "${LEVELDB_PUBLIC_INCLUDE_DIR}/cache.h"
  174. "${LEVELDB_PUBLIC_INCLUDE_DIR}/comparator.h"
  175. "${LEVELDB_PUBLIC_INCLUDE_DIR}/db.h"
  176. "${LEVELDB_PUBLIC_INCLUDE_DIR}/dumpfile.h"
  177. "${LEVELDB_PUBLIC_INCLUDE_DIR}/env.h"
  178. "${LEVELDB_PUBLIC_INCLUDE_DIR}/export.h"
  179. "${LEVELDB_PUBLIC_INCLUDE_DIR}/filter_policy.h"
  180. "${LEVELDB_PUBLIC_INCLUDE_DIR}/iterator.h"
  181. "${LEVELDB_PUBLIC_INCLUDE_DIR}/options.h"
  182. "${LEVELDB_PUBLIC_INCLUDE_DIR}/slice.h"
  183. "${LEVELDB_PUBLIC_INCLUDE_DIR}/status.h"
  184. "${LEVELDB_PUBLIC_INCLUDE_DIR}/table_builder.h"
  185. "${LEVELDB_PUBLIC_INCLUDE_DIR}/table.h"
  186. "${LEVELDB_PUBLIC_INCLUDE_DIR}/write_batch.h"
  187. )
  188. if (WIN32)
  189. target_sources(leveldb
  190. PRIVATE
  191. "util/env_windows.cc"
  192. "util/windows_logger.h"
  193. )
  194. else (WIN32)
  195. target_sources(leveldb
  196. PRIVATE
  197. "util/env_posix.cc"
  198. "util/posix_logger.h"
  199. )
  200. endif (WIN32)
  201. # MemEnv is not part of the interface and could be pulled to a separate library.
  202. target_sources(leveldb
  203. PRIVATE
  204. "helpers/memenv/memenv.cc"
  205. "helpers/memenv/memenv.h"
  206. )
  207. target_include_directories(leveldb
  208. PUBLIC
  209. $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
  210. $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
  211. )
  212. set_target_properties(leveldb
  213. PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR})
  214. target_compile_definitions(leveldb
  215. PRIVATE
  216. # Used by include/export.h when building shared libraries.
  217. LEVELDB_COMPILE_LIBRARY
  218. # Used by port/port.h.
  219. ${LEVELDB_PLATFORM_NAME}=1
  220. )
  221. if (NOT HAVE_CXX17_HAS_INCLUDE)
  222. target_compile_definitions(leveldb
  223. PRIVATE
  224. LEVELDB_HAS_PORT_CONFIG_H=1
  225. )
  226. endif(NOT HAVE_CXX17_HAS_INCLUDE)
  227. if(BUILD_SHARED_LIBS)
  228. target_compile_definitions(leveldb
  229. PUBLIC
  230. # Used by include/export.h.
  231. LEVELDB_SHARED_LIBRARY
  232. )
  233. endif(BUILD_SHARED_LIBS)
  234. if(HAVE_CLANG_THREAD_SAFETY)
  235. target_compile_options(leveldb
  236. PUBLIC
  237. -Werror -Wthread-safety)
  238. endif(HAVE_CLANG_THREAD_SAFETY)
  239. if(HAVE_CRC32C)
  240. target_link_libraries(leveldb crc32c)
  241. endif(HAVE_CRC32C)
  242. if(HAVE_SNAPPY)
  243. target_link_libraries(leveldb snappy)
  244. endif(HAVE_SNAPPY)
  245. if(HAVE_TCMALLOC)
  246. target_link_libraries(leveldb tcmalloc)
  247. endif(HAVE_TCMALLOC)
  248. # Needed by port_stdcxx.h
  249. find_package(Threads REQUIRED)
  250. target_link_libraries(leveldb Threads::Threads)
  251. add_executable(leveldbutil
  252. "db/leveldbutil.cc"
  253. )
  254. target_link_libraries(leveldbutil leveldb)
  255. if(LEVELDB_BUILD_TESTS)
  256. enable_testing()
  257. # Prevent overriding the parent project's compiler/linker settings on Windows.
  258. set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
  259. set(install_gtest OFF)
  260. set(install_gmock OFF)
  261. set(build_gmock ON)
  262. # This project is tested using GoogleTest.
  263. add_subdirectory("third_party/googletest")
  264. # This project uses Google benchmark for benchmarking.
  265. set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE)
  266. set(BENCHMARK_ENABLE_EXCEPTIONS OFF CACHE BOOL "" FORCE)
  267. add_subdirectory("third_party/benchmark")
  268. # GoogleTest triggers a missing field initializers warning.
  269. if(LEVELDB_HAVE_NO_MISSING_FIELD_INITIALIZERS)
  270. set_property(TARGET gtest
  271. APPEND PROPERTY COMPILE_OPTIONS -Wno-missing-field-initializers)
  272. set_property(TARGET gmock
  273. APPEND PROPERTY COMPILE_OPTIONS -Wno-missing-field-initializers)
  274. endif(LEVELDB_HAVE_NO_MISSING_FIELD_INITIALIZERS)
  275. function(leveldb_test test_file)
  276. get_filename_component(test_target_name "${test_file}" NAME_WE)
  277. add_executable("${test_target_name}" "")
  278. target_sources("${test_target_name}"
  279. PRIVATE
  280. "${PROJECT_BINARY_DIR}/${LEVELDB_PORT_CONFIG_DIR}/port_config.h"
  281. "util/testutil.cc"
  282. "util/testutil.h"
  283. "${test_file}"
  284. )
  285. target_link_libraries("${test_target_name}" leveldb gmock gtest benchmark)
  286. target_compile_definitions("${test_target_name}"
  287. PRIVATE
  288. ${LEVELDB_PLATFORM_NAME}=1
  289. )
  290. if (NOT HAVE_CXX17_HAS_INCLUDE)
  291. target_compile_definitions("${test_target_name}"
  292. PRIVATE
  293. LEVELDB_HAS_PORT_CONFIG_H=1
  294. )
  295. endif(NOT HAVE_CXX17_HAS_INCLUDE)
  296. add_test(NAME "${test_target_name}" COMMAND "${test_target_name}")
  297. endfunction(leveldb_test)
  298. leveldb_test("db/c_test.c")
  299. leveldb_test("db/fault_injection_test.cc")
  300. leveldb_test("issues/issue178_test.cc")
  301. leveldb_test("issues/issue200_test.cc")
  302. leveldb_test("issues/issue320_test.cc")
  303. leveldb_test("util/env_test.cc")
  304. leveldb_test("util/status_test.cc")
  305. leveldb_test("util/no_destructor_test.cc")
  306. if(NOT BUILD_SHARED_LIBS)
  307. leveldb_test("db/autocompact_test.cc")
  308. leveldb_test("db/corruption_test.cc")
  309. leveldb_test("db/db_test.cc")
  310. leveldb_test("db/dbformat_test.cc")
  311. leveldb_test("db/filename_test.cc")
  312. leveldb_test("db/log_test.cc")
  313. leveldb_test("db/recovery_test.cc")
  314. leveldb_test("db/skiplist_test.cc")
  315. leveldb_test("db/version_edit_test.cc")
  316. leveldb_test("db/version_set_test.cc")
  317. leveldb_test("db/write_batch_test.cc")
  318. leveldb_test("helpers/memenv/memenv_test.cc")
  319. leveldb_test("table/filter_block_test.cc")
  320. leveldb_test("table/table_test.cc")
  321. leveldb_test("util/arena_test.cc")
  322. leveldb_test("util/bloom_test.cc")
  323. leveldb_test("util/cache_test.cc")
  324. leveldb_test("util/coding_test.cc")
  325. leveldb_test("util/crc32c_test.cc")
  326. leveldb_test("util/hash_test.cc")
  327. leveldb_test("util/logging_test.cc")
  328. # TODO(costan): This test also uses
  329. # "util/env_{posix|windows}_test_helper.h"
  330. if (WIN32)
  331. leveldb_test("util/env_windows_test.cc")
  332. else (WIN32)
  333. leveldb_test("util/env_posix_test.cc")
  334. endif (WIN32)
  335. endif(NOT BUILD_SHARED_LIBS)
  336. endif(LEVELDB_BUILD_TESTS)
  337. if(LEVELDB_BUILD_BENCHMARKS)
  338. function(leveldb_benchmark bench_file)
  339. get_filename_component(bench_target_name "${bench_file}" NAME_WE)
  340. add_executable("${bench_target_name}" "")
  341. target_sources("${bench_target_name}"
  342. PRIVATE
  343. "${PROJECT_BINARY_DIR}/${LEVELDB_PORT_CONFIG_DIR}/port_config.h"
  344. "util/histogram.cc"
  345. "util/histogram.h"
  346. "util/testutil.cc"
  347. "util/testutil.h"
  348. "${bench_file}"
  349. )
  350. target_link_libraries("${bench_target_name}" leveldb gmock gtest)
  351. target_compile_definitions("${bench_target_name}"
  352. PRIVATE
  353. ${LEVELDB_PLATFORM_NAME}=1
  354. )
  355. if (NOT HAVE_CXX17_HAS_INCLUDE)
  356. target_compile_definitions("${bench_target_name}"
  357. PRIVATE
  358. LEVELDB_HAS_PORT_CONFIG_H=1
  359. )
  360. endif(NOT HAVE_CXX17_HAS_INCLUDE)
  361. endfunction(leveldb_benchmark)
  362. if(NOT BUILD_SHARED_LIBS)
  363. leveldb_benchmark("benchmarks/db_bench.cc")
  364. endif(NOT BUILD_SHARED_LIBS)
  365. check_library_exists(sqlite3 sqlite3_open "" HAVE_SQLITE3)
  366. if(HAVE_SQLITE3)
  367. leveldb_benchmark("benchmarks/db_bench_sqlite3.cc")
  368. target_link_libraries(db_bench_sqlite3 sqlite3)
  369. endif(HAVE_SQLITE3)
  370. # check_library_exists is insufficient here because the library names have
  371. # different manglings when compiled with clang or gcc, at least when installed
  372. # with Homebrew on Mac.
  373. set(OLD_CMAKE_REQURED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
  374. list(APPEND CMAKE_REQUIRED_LIBRARIES kyotocabinet)
  375. check_cxx_source_compiles("
  376. #include <kcpolydb.h>
  377. int main() {
  378. kyotocabinet::TreeDB* db = new kyotocabinet::TreeDB();
  379. delete db;
  380. return 0;
  381. }
  382. " HAVE_KYOTOCABINET)
  383. set(CMAKE_REQUIRED_LIBRARIES ${OLD_CMAKE_REQURED_LIBRARIES})
  384. if(HAVE_KYOTOCABINET)
  385. leveldb_benchmark("benchmarks/db_bench_tree_db.cc")
  386. target_link_libraries(db_bench_tree_db kyotocabinet)
  387. endif(HAVE_KYOTOCABINET)
  388. endif(LEVELDB_BUILD_BENCHMARKS)
  389. if(LEVELDB_INSTALL)
  390. install(TARGETS leveldb
  391. EXPORT leveldbTargets
  392. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  393. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  394. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  395. )
  396. install(
  397. FILES
  398. "${LEVELDB_PUBLIC_INCLUDE_DIR}/c.h"
  399. "${LEVELDB_PUBLIC_INCLUDE_DIR}/cache.h"
  400. "${LEVELDB_PUBLIC_INCLUDE_DIR}/comparator.h"
  401. "${LEVELDB_PUBLIC_INCLUDE_DIR}/db.h"
  402. "${LEVELDB_PUBLIC_INCLUDE_DIR}/dumpfile.h"
  403. "${LEVELDB_PUBLIC_INCLUDE_DIR}/env.h"
  404. "${LEVELDB_PUBLIC_INCLUDE_DIR}/export.h"
  405. "${LEVELDB_PUBLIC_INCLUDE_DIR}/filter_policy.h"
  406. "${LEVELDB_PUBLIC_INCLUDE_DIR}/iterator.h"
  407. "${LEVELDB_PUBLIC_INCLUDE_DIR}/options.h"
  408. "${LEVELDB_PUBLIC_INCLUDE_DIR}/slice.h"
  409. "${LEVELDB_PUBLIC_INCLUDE_DIR}/status.h"
  410. "${LEVELDB_PUBLIC_INCLUDE_DIR}/table_builder.h"
  411. "${LEVELDB_PUBLIC_INCLUDE_DIR}/table.h"
  412. "${LEVELDB_PUBLIC_INCLUDE_DIR}/write_batch.h"
  413. DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/leveldb"
  414. )
  415. include(CMakePackageConfigHelpers)
  416. configure_package_config_file(
  417. "cmake/${PROJECT_NAME}Config.cmake.in"
  418. "${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}Config.cmake"
  419. INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
  420. )
  421. write_basic_package_version_file(
  422. "${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}ConfigVersion.cmake"
  423. COMPATIBILITY SameMajorVersion
  424. )
  425. install(
  426. EXPORT leveldbTargets
  427. NAMESPACE leveldb::
  428. DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
  429. )
  430. install(
  431. FILES
  432. "${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}Config.cmake"
  433. "${PROJECT_BINARY_DIR}/cmake/${PROJECT_NAME}ConfigVersion.cmake"
  434. DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
  435. )
  436. endif(LEVELDB_INSTALL)