diff options
-rw-r--r-- | cmake/FindLZ4.cmake | 9 | ||||
-rw-r--r-- | cmake/FindZSTD.cmake | 18 | ||||
-rw-r--r-- | storage/rocksdb/CMakeLists.txt | 31 | ||||
-rw-r--r-- | storage/rocksdb/build_rocksdb.cmake | 47 |
4 files changed, 65 insertions, 40 deletions
diff --git a/cmake/FindLZ4.cmake b/cmake/FindLZ4.cmake new file mode 100644 index 00000000000..e97dd63e2b0 --- /dev/null +++ b/cmake/FindLZ4.cmake @@ -0,0 +1,9 @@ +find_path(LZ4_INCLUDE_DIR NAMES lz4.h) +find_library(LZ4_LIBRARY NAMES lz4) + +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS( + LZ4 DEFAULT_MSG + LZ4_LIBRARY LZ4_INCLUDE_DIR) + +mark_as_advanced(LZ4_INCLUDE_DIR LZ4_LIBRARY) diff --git a/cmake/FindZSTD.cmake b/cmake/FindZSTD.cmake new file mode 100644 index 00000000000..0fd73501327 --- /dev/null +++ b/cmake/FindZSTD.cmake @@ -0,0 +1,18 @@ +find_path( + ZSTD_INCLUDE_DIR + NAMES "zstd.h" +) + +find_library( + ZSTD_LIBRARY + NAMES zstd +) + +set(ZSTD_LIBRARIES ${ZSTD_LIBRARY}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + ZSTD DEFAULT_MSG ZSTD_INCLUDE_DIR ZSTD_LIBRARIES) + +mark_as_advanced(ZSTD_INCLUDE_DIR ZSTD_LIBRARIES ZSTD_FOUND) + diff --git a/storage/rocksdb/CMakeLists.txt b/storage/rocksdb/CMakeLists.txt index 106330a2c30..0c8025d3d18 100644 --- a/storage/rocksdb/CMakeLists.txt +++ b/storage/rocksdb/CMakeLists.txt @@ -152,34 +152,3 @@ IF(MSVC) # Some checks in C++ runtime that make debug build much slower ADD_DEFINITIONS(-D_ITERATOR_DEBUG_LEVEL=0) ENDIF() - -# Optional compression libraries. -# -# TODO: search compression libraries properly. -# Use FIND_PACKAGE, CHECK_LIBRARY_EXISTS etc -IF(MARIAROCKS_NOT_YET) -IF (NOT "$ENV{WITH_SNAPPY}" STREQUAL "") - SET(rocksdb_static_libs ${rocksdb_static_libs} - $ENV{WITH_SNAPPY}/libsnappy${PIC_EXT}.a) - ADD_DEFINITIONS(-DSNAPPY) -ENDIF() - -IF (NOT "$ENV{WITH_LZ4}" STREQUAL "") - SET(rocksdb_static_libs ${rocksdb_static_libs} - $ENV{WITH_LZ4}/liblz4${PIC_EXT}.a) - ADD_DEFINITIONS(-DLZ4) -ENDIF() - -IF (NOT "$ENV{WITH_BZ2}" STREQUAL "") - SET(rocksdb_static_libs ${rocksdb_static_libs} - $ENV{WITH_BZ2}/libbz2${PIC_EXT}.a) - ADD_DEFINITIONS(-DBZIP2) -ENDIF() - -# link ZSTD only if instructed -IF (NOT "$ENV{WITH_ZSTD}" STREQUAL "") - SET(rocksdb_static_libs ${rocksdb_static_libs} - $ENV{WITH_ZSTD}/libzstd${PIC_EXT}.a) - ADD_DEFINITIONS(-DZSTD) -ENDIF() -ENDIF(MARIAROCKS_NOT_YET) diff --git a/storage/rocksdb/build_rocksdb.cmake b/storage/rocksdb/build_rocksdb.cmake index 14dfe746ae1..a482172f000 100644 --- a/storage/rocksdb/build_rocksdb.cmake +++ b/storage/rocksdb/build_rocksdb.cmake @@ -11,8 +11,6 @@ INCLUDE_DIRECTORIES( ${ROCKSDB_SOURCE_DIR}/third-party/gtest-1.7.0/fused-src ) - - list(APPEND CMAKE_MODULE_PATH "${ROCKSDB_SOURCE_DIR}/cmake/modules/") if(WIN32) @@ -29,18 +27,49 @@ else() add_definitions(-DROCKSDB_JEMALLOC) set(WITH_JEMALLOC ON) endif() - option(WITH_ROCKSDB_SNAPPY "build RocksDB with SNAPPY" OFF) - if(WITH_ROCKSDB_SNAPPY) - find_package(snappy REQUIRED) - add_definitions(-DSNAPPY) - include_directories(${SNAPPY_INCLUDE_DIR}) - list(APPEND THIRDPARTY_LIBS ${SNAPPY_LIBRARIES}) +endif() + +# Optional compression libraries. + +foreach(compression_lib LZ4 BZIP2 ZSTD snappy) + FIND_PACKAGE(${compression_lib} QUIET) + + SET(WITH_ROCKSDB_${compression_lib} AUTO CACHE STRING + "Build RocksDB with ${compression_lib} compression. Possible values are 'ON', 'OFF', 'AUTO' and default is 'AUTO'") + + if(${WITH_ROCKSDB_${compression_lib}} STREQUAL "ON" AND NOT ${${compression_lib}_FOUND}) + MESSAGE(FATAL_ERROR + "${compression_lib} library was not found, but WITH_ROCKSDB${compression_lib} option is ON.\ + Either set WITH_ROCKSDB${compression_lib} to OFF, or make sure ${compression_lib} is installed") endif() +endforeach() + +if(LZ4_FOUND AND (NOT WITH_ROCKSDB_LZ4 STREQUAL "OFF")) + add_definitions(-DLZ4) + include_directories(${LZ4_INCLUDE_DIR}) + list(APPEND THIRDPARTY_LIBS ${LZ4_LIBRARY}) endif() +if(BZIP2_FOUND AND (NOT WITH_ROCKSDB_BZIP2 STREQUAL "OFF")) + add_definitions(-DBZIP2) + include_directories(${BZIP2_INCLUDE_DIR}) + list(APPEND THIRDPARTY_LIBS ${BZIP2_LIBRARIES}) +endif() +if(SNAPPY_FOUND AND (NOT WITH_ROCKSDB_SNAPPY STREQUAL "OFF")) + add_definitions(-DSNAPPY) + include_directories(${SNAPPY_INCLUDE_DIR}) + list(APPEND THIRDPARTY_LIBS ${SNAPPY_LIBRARIES}) +endif() +if(ZSTD_FOUND AND (NOT WITH_ROCKSDB_ZSTD STREQUAL "OFF")) + add_definitions(-DZSTD) + include_directories(${ZSTD_INCLUDE_DIR}) + list(APPEND THIRDPARTY_LIBS ${ZSTD_LIBRARY}) +endif() +add_definitions(-DZLIB) +list(APPEND THIRDPARTY_LIBS ${ZLIB_LIBRARY}) if(CMAKE_SYSTEM_NAME MATCHES "Cygwin") add_definitions(-fno-builtin-memcmp -DCYGWIN) @@ -330,7 +359,7 @@ CONFIGURE_FILE(${ROCKSDB_SOURCE_DIR}/util/build_version.cc.in build_version.cc @ INCLUDE_DIRECTORIES(${ROCKSDB_SOURCE_DIR}/util) list(APPEND SOURCES ${CMAKE_CURRENT_BINARY_DIR}/build_version.cc) -ADD_CONVENIENCE_LIBRARY(rocksdblib STATIC ${SOURCES}) +ADD_CONVENIENCE_LIBRARY(rocksdblib ${SOURCES}) target_link_libraries(rocksdblib ${THIRDPARTY_LIBS} ${SYSTEM_LIBS}) IF(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") set_target_properties(rocksdblib PROPERTIES COMPILE_FLAGS "-fPIC -fno-builtin-memcmp -frtti") |