From fd2799f87fef5517ac536210aa72cfab1c9a4bdd Mon Sep 17 00:00:00 2001 From: Andrew Kryczka Date: Sun, 30 Jun 2019 14:13:20 -0700 Subject: [PATCH] Revert "cmake: cmake related cleanups (#5662)" This reverts commit cc9fa7fcdb35fdd12505053b2a6cd38140c93d3b. --- CMakeLists.txt | 65 ++++++++++++++++++++------------ cmake/modules/FindJeMalloc.cmake | 24 ++++-------- cmake/modules/FindNUMA.cmake | 16 ++------ cmake/modules/FindTBB.cmake | 26 +++++-------- cmake/modules/Findbzip2.cmake | 21 +++++++++++ cmake/modules/Findlz4.cmake | 28 +++++--------- cmake/modules/Findsnappy.cmake | 26 +++++-------- cmake/modules/Findzstd.cmake | 28 +++++--------- cmake/modules/ReadVersion.cmake | 10 ----- 9 files changed, 112 insertions(+), 132 deletions(-) create mode 100644 cmake/modules/Findbzip2.cmake delete mode 100644 cmake/modules/ReadVersion.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 45693df5024..52c313525ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,19 +32,18 @@ # 3. cmake .. # 4. make -j -cmake_minimum_required(VERSION 3.5.1) - -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/modules/") -include(ReadVersion) -get_rocksdb_version(rocksdb_VERSION) -project(rocksdb - VERSION ${rocksdb_VERSION} - LANGUAGES CXX C ASM) +cmake_minimum_required(VERSION 2.8.12) +project(rocksdb) +enable_language(CXX) +enable_language(C) +enable_language(ASM) if(POLICY CMP0042) cmake_policy(SET CMP0042 NEW) endif() +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/modules/") + find_program(CCACHE_FOUND ccache) if(CCACHE_FOUND) set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) @@ -82,7 +81,8 @@ else() if(WITH_JEMALLOC) find_package(JeMalloc REQUIRED) add_definitions(-DROCKSDB_JEMALLOC -DJEMALLOC_NO_DEMANGLE) - list(APPEND THIRDPARTY_LIBS JeMalloc::JeMalloc) + include_directories(${JEMALLOC_INCLUDE_DIR}) + list(APPEND THIRDPARTY_LIBS ${JEMALLOC_LIBRARIES}) endif() endif() @@ -100,38 +100,43 @@ else() if(WITH_SNAPPY) find_package(snappy REQUIRED) add_definitions(-DSNAPPY) - list(APPEND THIRDPARTY_LIBS snappy::snappy) + include_directories(${SNAPPY_INCLUDE_DIR}) + list(APPEND THIRDPARTY_LIBS ${SNAPPY_LIBRARIES}) endif() if(WITH_ZLIB) find_package(ZLIB REQUIRED) add_definitions(-DZLIB) - list(APPEND THIRDPARTY_LIBS ZLIB::ZLIB) + if(ZLIB_INCLUDE_DIRS) + # CMake 3 + include_directories(${ZLIB_INCLUDE_DIRS}) + else() + # CMake 2 + include_directories(${ZLIB_INCLUDE_DIR}) + endif() + list(APPEND THIRDPARTY_LIBS ${ZLIB_LIBRARIES}) endif() option(WITH_BZ2 "build with bzip2" OFF) if(WITH_BZ2) - find_package(BZip2 REQUIRED) + find_package(bzip2 REQUIRED) add_definitions(-DBZIP2) - if(BZIP2_INCLUDE_DIRS) - include_directories(${BZIP2_INCLUDE_DIRS}) - else() - include_directories(${BZIP2_INCLUDE_DIR}) - endif() + include_directories(${BZIP2_INCLUDE_DIR}) list(APPEND THIRDPARTY_LIBS ${BZIP2_LIBRARIES}) endif() if(WITH_LZ4) find_package(lz4 REQUIRED) add_definitions(-DLZ4) - list(APPEND THIRDPARTY_LIBS lz4::lz4) + include_directories(${LZ4_INCLUDE_DIR}) + list(APPEND THIRDPARTY_LIBS ${LZ4_LIBRARIES}) endif() if(WITH_ZSTD) find_package(zstd REQUIRED) add_definitions(-DZSTD) include_directories(${ZSTD_INCLUDE_DIR}) - list(APPEND THIRDPARTY_LIBS zstd::zstd) + list(APPEND THIRDPARTY_LIBS ${ZSTD_LIBRARIES}) endif() endif() @@ -153,6 +158,17 @@ endif() string(REGEX REPLACE "[^0-9a-f]+" "" GIT_SHA "${GIT_SHA}") +# Read rocksdb version from version.h header file. +file(READ include/rocksdb/version.h version_header_file) +string(REGEX MATCH "#define ROCKSDB_MAJOR ([0-9]+)" _ ${version_header_file}) +set(ROCKSDB_VERSION_MAJOR ${CMAKE_MATCH_1}) +string(REGEX MATCH "#define ROCKSDB_MINOR ([0-9]+)" _ ${version_header_file}) +set(ROCKSDB_VERSION_MINOR ${CMAKE_MATCH_1}) +string(REGEX MATCH "#define ROCKSDB_PATCH ([0-9]+)" _ ${version_header_file}) +set(ROCKSDB_VERSION_PATCH ${CMAKE_MATCH_1}) +set(ROCKSDB_VERSION ${ROCKSDB_VERSION_MAJOR}.${ROCKSDB_VERSION_MINOR}.${ROCKSDB_VERSION_PATCH}) + + option(WITH_MD_LIBRARY "build with MD" ON) if(WIN32 AND MSVC) if(WITH_MD_LIBRARY) @@ -308,14 +324,15 @@ if(WITH_NUMA) find_package(NUMA REQUIRED) add_definitions(-DNUMA) include_directories(${NUMA_INCLUDE_DIR}) - list(APPEND THIRDPARTY_LIBS NUMA::NUMA) + list(APPEND THIRDPARTY_LIBS ${NUMA_LIBRARIES}) endif() option(WITH_TBB "build with Threading Building Blocks (TBB)" OFF) if(WITH_TBB) find_package(TBB REQUIRED) add_definitions(-DTBB) - list(APPEND THIRDPARTY_LIBS TBB::TBB) + include_directories(${TBB_INCLUDE_DIR}) + list(APPEND THIRDPARTY_LIBS ${TBB_LIBRARIES}) endif() # Stall notifications eat some performance from inserts @@ -788,8 +805,8 @@ else() ${THIRDPARTY_LIBS} ${SYSTEM_LIBS}) set_target_properties(${ROCKSDB_SHARED_LIB} PROPERTIES LINKER_LANGUAGE CXX - VERSION ${rocksdb_VERSION} - SOVERSION ${rocksdb_VERSION_MAJOR} + VERSION ${ROCKSDB_VERSION} + SOVERSION ${ROCKSDB_VERSION_MAJOR} CXX_STANDARD 11 OUTPUT_NAME "rocksdb") endif() @@ -844,7 +861,7 @@ if(NOT WIN32 OR ROCKSDB_INSTALL_ON_WINDOWS) write_basic_package_version_file( RocksDBConfigVersion.cmake - VERSION ${rocksdb_VERSION} + VERSION ${ROCKSDB_VERSION} COMPATIBILITY SameMajorVersion ) diff --git a/cmake/modules/FindJeMalloc.cmake b/cmake/modules/FindJeMalloc.cmake index f695b3ed1b3..7911f77c4c3 100644 --- a/cmake/modules/FindJeMalloc.cmake +++ b/cmake/modules/FindJeMalloc.cmake @@ -1,29 +1,21 @@ # - Find JeMalloc library # Find the native JeMalloc includes and library # -# JeMalloc_INCLUDE_DIRS - where to find jemalloc.h, etc. -# JeMalloc_LIBRARIES - List of libraries when using jemalloc. -# JeMalloc_FOUND - True if jemalloc found. +# JEMALLOC_INCLUDE_DIR - where to find jemalloc.h, etc. +# JEMALLOC_LIBRARIES - List of libraries when using jemalloc. +# JEMALLOC_FOUND - True if jemalloc found. -find_path(JeMalloc_INCLUDE_DIRS +find_path(JEMALLOC_INCLUDE_DIR NAMES jemalloc/jemalloc.h HINTS ${JEMALLOC_ROOT_DIR}/include) -find_library(JeMalloc_LIBRARIES +find_library(JEMALLOC_LIBRARIES NAMES jemalloc HINTS ${JEMALLOC_ROOT_DIR}/lib) include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(JeMalloc DEFAULT_MSG JeMalloc_LIBRARIES JeMalloc_INCLUDE_DIRS) +find_package_handle_standard_args(jemalloc DEFAULT_MSG JEMALLOC_LIBRARIES JEMALLOC_INCLUDE_DIR) mark_as_advanced( - JeMalloc_LIBRARIES - JeMalloc_INCLUDE_DIRS) - -if(JeMalloc_FOUND AND NOT (TARGET JeMalloc::JeMalloc)) - add_library (JeMalloc::JeMalloc UNKNOWN IMPORTED) - set_target_properties(JeMalloc::JeMalloc - PROPERTIES - IMPORTED_LOCATION ${JeMalloc_LIBRARIES} - INTERFACE_INCLUDE_DIRECTORIES ${JeMalloc_INCLUDE_DIRS}) -endif() + JEMALLOC_LIBRARIES + JEMALLOC_INCLUDE_DIR) diff --git a/cmake/modules/FindNUMA.cmake b/cmake/modules/FindNUMA.cmake index 69b95c9b60b..02760344c68 100644 --- a/cmake/modules/FindNUMA.cmake +++ b/cmake/modules/FindNUMA.cmake @@ -1,11 +1,11 @@ # - Find NUMA # Find the NUMA library and includes # -# NUMA_INCLUDE_DIRS - where to find numa.h, etc. +# NUMA_INCLUDE_DIR - where to find numa.h, etc. # NUMA_LIBRARIES - List of libraries when using NUMA. # NUMA_FOUND - True if NUMA found. -find_path(NUMA_INCLUDE_DIRS +find_path(NUMA_INCLUDE_DIR NAMES numa.h numaif.h HINTS ${NUMA_ROOT_DIR}/include) @@ -14,16 +14,8 @@ find_library(NUMA_LIBRARIES HINTS ${NUMA_ROOT_DIR}/lib) include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(NUMA DEFAULT_MSG NUMA_LIBRARIES NUMA_INCLUDE_DIRS) +find_package_handle_standard_args(NUMA DEFAULT_MSG NUMA_LIBRARIES NUMA_INCLUDE_DIR) mark_as_advanced( NUMA_LIBRARIES - NUMA_INCLUDE_DIRS) - -if(NUMA_FOUND AND NOT (TARGET NUMA::NUMA)) - add_library (NUMA::NUMA UNKNOWN IMPORTED) - set_target_properties(NUMA::NUMA - PROPERTIES - IMPORTED_LOCATION ${NUMA_LIBRARIES} - INTERFACE_INCLUDE_DIRECTORIES ${NUMA_INCLUDE_DIRS}) -endif() + NUMA_INCLUDE_DIR) diff --git a/cmake/modules/FindTBB.cmake b/cmake/modules/FindTBB.cmake index f6861fa5521..556ce872b17 100644 --- a/cmake/modules/FindTBB.cmake +++ b/cmake/modules/FindTBB.cmake @@ -1,7 +1,7 @@ # - Find TBB # Find the Thread Building Blocks library and includes # -# TBB_INCLUDE_DIRS - where to find tbb.h, etc. +# TBB_INCLUDE_DIR - where to find tbb.h, etc. # TBB_LIBRARIES - List of libraries when using TBB. # TBB_FOUND - True if TBB found. @@ -9,25 +9,17 @@ if(NOT DEFINED TBB_ROOT_DIR) set(TBB_ROOT_DIR "$ENV{TBBROOT}") endif() -find_path(TBB_INCLUDE_DIRS - NAMES tbb/tbb.h - HINTS ${TBB_ROOT_DIR}/include) +find_path(TBB_INCLUDE_DIR +NAMES tbb/tbb.h +HINTS ${TBB_ROOT_DIR}/include) find_library(TBB_LIBRARIES - NAMES tbb - HINTS ${TBB_ROOT_DIR}/lib ENV LIBRARY_PATH) +NAMES tbb +HINTS ${TBB_ROOT_DIR}/lib ENV LIBRARY_PATH) include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(TBB DEFAULT_MSG TBB_LIBRARIES TBB_INCLUDE_DIRS) +find_package_handle_standard_args(TBB DEFAULT_MSG TBB_LIBRARIES TBB_INCLUDE_DIR) mark_as_advanced( - TBB_LIBRARIES - TBB_INCLUDE_DIRS) - -if(TBB_FOUND AND NOT (TARGET TBB::TBB)) - add_library (TBB::TBB UNKNOWN IMPORTED) - set_target_properties(TBB::TBB - PROPERTIES - IMPORTED_LOCATION ${TBB_LIBRARIES} - INTERFACE_INCLUDE_DIRECTORIES ${TBB_INCLUDE_DIRS}) -endif() +TBB_LIBRARIES +TBB_INCLUDE_DIR) diff --git a/cmake/modules/Findbzip2.cmake b/cmake/modules/Findbzip2.cmake new file mode 100644 index 00000000000..87abbe941e0 --- /dev/null +++ b/cmake/modules/Findbzip2.cmake @@ -0,0 +1,21 @@ +# - Find Bzip2 +# Find the bzip2 compression library and includes +# +# BZIP2_INCLUDE_DIR - where to find bzlib.h, etc. +# BZIP2_LIBRARIES - List of libraries when using bzip2. +# BZIP2_FOUND - True if bzip2 found. + +find_path(BZIP2_INCLUDE_DIR + NAMES bzlib.h + HINTS ${BZIP2_ROOT_DIR}/include) + +find_library(BZIP2_LIBRARIES + NAMES bz2 + HINTS ${BZIP2_ROOT_DIR}/lib) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(bzip2 DEFAULT_MSG BZIP2_LIBRARIES BZIP2_INCLUDE_DIR) + +mark_as_advanced( + BZIP2_LIBRARIES + BZIP2_INCLUDE_DIR) diff --git a/cmake/modules/Findlz4.cmake b/cmake/modules/Findlz4.cmake index 7cf7d7f5fe3..c34acef5e39 100644 --- a/cmake/modules/Findlz4.cmake +++ b/cmake/modules/Findlz4.cmake @@ -1,29 +1,21 @@ # - Find Lz4 # Find the lz4 compression library and includes # -# lz4_INCLUDE_DIRS - where to find lz4.h, etc. -# lz4_LIBRARIES - List of libraries when using lz4. -# lz4_FOUND - True if lz4 found. +# LZ4_INCLUDE_DIR - where to find lz4.h, etc. +# LZ4_LIBRARIES - List of libraries when using lz4. +# LZ4_FOUND - True if lz4 found. -find_path(lz4_INCLUDE_DIRS +find_path(LZ4_INCLUDE_DIR NAMES lz4.h - HINTS ${lz4_ROOT_DIR}/include) + HINTS ${LZ4_ROOT_DIR}/include) -find_library(lz4_LIBRARIES +find_library(LZ4_LIBRARIES NAMES lz4 - HINTS ${lz4_ROOT_DIR}/lib) + HINTS ${LZ4_ROOT_DIR}/lib) include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(lz4 DEFAULT_MSG lz4_LIBRARIES lz4_INCLUDE_DIRS) +find_package_handle_standard_args(lz4 DEFAULT_MSG LZ4_LIBRARIES LZ4_INCLUDE_DIR) mark_as_advanced( - lz4_LIBRARIES - lz4_INCLUDE_DIRS) - -if(lz4_FOUND AND NOT (TARGET lz4::lz4)) - add_library(lz4::lz4 UNKNOWN IMPORTED) - set_target_properties(lz4::lz4 - PROPERTIES - IMPORTED_LOCATION ${lz4_LIBRARIES} - INTERFACE_INCLUDE_DIRECTORIES ${lz4_INCLUDE_DIRS}) -endif() + LZ4_LIBRARIES + LZ4_INCLUDE_DIR) diff --git a/cmake/modules/Findsnappy.cmake b/cmake/modules/Findsnappy.cmake index 39bba6bd217..fae2c004ab0 100644 --- a/cmake/modules/Findsnappy.cmake +++ b/cmake/modules/Findsnappy.cmake @@ -1,29 +1,21 @@ # - Find Snappy # Find the snappy compression library and includes # -# snappy_INCLUDE_DIRS - where to find snappy.h, etc. -# snappy_LIBRARIES - List of libraries when using snappy. -# snappy_FOUND - True if snappy found. +# SNAPPY_INCLUDE_DIR - where to find snappy.h, etc. +# SNAPPY_LIBRARIES - List of libraries when using snappy. +# SNAPPY_FOUND - True if snappy found. -find_path(snappy_INCLUDE_DIRS +find_path(SNAPPY_INCLUDE_DIR NAMES snappy.h - HINTS ${snappy_ROOT_DIR}/include) + HINTS ${SNAPPY_ROOT_DIR}/include) find_library(snappy_LIBRARIES NAMES snappy - HINTS ${snappy_ROOT_DIR}/lib) + HINTS ${SNAPPY_ROOT_DIR}/lib) include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(snappy DEFAULT_MSG snappy_LIBRARIES snappy_INCLUDE_DIRS) +find_package_handle_standard_args(snappy DEFAULT_MSG SNAPPY_LIBRARIES SNAPPY_INCLUDE_DIR) mark_as_advanced( - snappy_LIBRARIES - snappy_INCLUDE_DIRS) - -if(snappy_FOUND AND NOT (TARGET snappy::snappy)) - add_library (snappy::snappy UNKNOWN IMPORTED) - set_target_properties(snappy::snappy - PROPERTIES - IMPORTED_LOCATION ${snappy_LIBRARIES} - INTERFACE_INCLUDE_DIRECTORIES ${snappy_INCLUDE_DIRS}) -endif() + SNAPPY_LIBRARIES + SNAPPY_INCLUDE_DIR) diff --git a/cmake/modules/Findzstd.cmake b/cmake/modules/Findzstd.cmake index 9430821df6e..a2964aa9f80 100644 --- a/cmake/modules/Findzstd.cmake +++ b/cmake/modules/Findzstd.cmake @@ -1,29 +1,21 @@ # - Find zstd # Find the zstd compression library and includes # -# zstd_INCLUDE_DIRS - where to find zstd.h, etc. -# zstd_LIBRARIES - List of libraries when using zstd. -# zstd_FOUND - True if zstd found. +# ZSTD_INCLUDE_DIR - where to find zstd.h, etc. +# ZSTD_LIBRARIES - List of libraries when using zstd. +# ZSTD_FOUND - True if zstd found. -find_path(zstd_INCLUDE_DIRS +find_path(ZSTD_INCLUDE_DIR NAMES zstd.h - HINTS ${zstd_ROOT_DIR}/include) + HINTS ${ZSTD_ROOT_DIR}/include) -find_library(zstd_LIBRARIES +find_library(ZSTD_LIBRARIES NAMES zstd - HINTS ${zstd_ROOT_DIR}/lib) + HINTS ${ZSTD_ROOT_DIR}/lib) include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(zstd DEFAULT_MSG zstd_LIBRARIES zstd_INCLUDE_DIRS) +find_package_handle_standard_args(zstd DEFAULT_MSG ZSTD_LIBRARIES ZSTD_INCLUDE_DIR) mark_as_advanced( - zstd_LIBRARIES - zstd_INCLUDE_DIRS) - -if(zstd_FOUND AND NOT (TARGET zstd::zstd)) - add_library (zstd::zstd UNKNOWN IMPORTED) - set_target_properties(zstd::zstd - PROPERTIES - IMPORTED_LOCATION ${zstd_LIBRARIES} - INTERFACE_INCLUDE_DIRECTORIES ${zstd_INCLUDE_DIRS}) -endif() + ZSTD_LIBRARIES + ZSTD_INCLUDE_DIR) diff --git a/cmake/modules/ReadVersion.cmake b/cmake/modules/ReadVersion.cmake deleted file mode 100644 index ae356d99659..00000000000 --- a/cmake/modules/ReadVersion.cmake +++ /dev/null @@ -1,10 +0,0 @@ -# Read rocksdb version from version.h header file. - -function(get_rocksdb_version version_var) - file(READ "${CMAKE_SOURCE_DIR}/include/rocksdb/version.h" version_header_file) - foreach(component MAJOR MINOR PATCH) - string(REGEX MATCH "#define ROCKSDB_${component} ([0-9]+)" _ ${version_header_file}) - set(ROCKSDB_VERSION_${component} ${CMAKE_MATCH_1}) - endforeach() - set(${version_var} "${ROCKSDB_VERSION_MAJOR}.${ROCKSDB_VERSION_MINOR}.${ROCKSDB_VERSION_PATCH}" PARENT_SCOPE) -endfunction()