2018-08-06 09:55:02 +00:00
|
|
|
function(build_rocksdb)
|
|
|
|
set(rocksdb_CMAKE_ARGS -DCMAKE_POSITION_INDEPENDENT_CODE=ON)
|
|
|
|
list(APPEND rocksdb_CMAKE_ARGS -DWITH_GFLAGS=OFF)
|
2017-09-19 03:56:15 +00:00
|
|
|
|
|
|
|
if(ALLOCATOR STREQUAL "jemalloc")
|
2018-08-06 09:55:02 +00:00
|
|
|
list(APPEND rocksdb_CMAKE_ARGS -DWITH_JEMALLOC=ON)
|
|
|
|
list(APPEND rocksdb_INTERFACE_LINK_LIBRARIES JeMalloc::JeMalloc)
|
2017-09-19 03:56:15 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if (WITH_CCACHE AND CCACHE_FOUND)
|
2019-06-12 10:54:26 +00:00
|
|
|
list(APPEND rocksdb_CMAKE_ARGS -DCMAKE_CXX_COMPILER_LAUNCHER=ccache)
|
2017-09-19 03:56:15 +00:00
|
|
|
endif()
|
2019-06-12 10:54:26 +00:00
|
|
|
list(APPEND rocksdb_CMAKE_ARGS -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER})
|
2017-09-19 03:56:15 +00:00
|
|
|
|
2018-08-06 09:55:02 +00:00
|
|
|
list(APPEND rocksdb_CMAKE_ARGS -DWITH_SNAPPY=${SNAPPY_FOUND})
|
|
|
|
if(SNAPPY_FOUND)
|
|
|
|
list(APPEND rocksdb_INTERFACE_LINK_LIBRARIES snappy::snappy)
|
|
|
|
endif()
|
2018-07-23 11:55:05 +00:00
|
|
|
# libsnappy is a C++ library, we need to force rocksdb to link against
|
|
|
|
# libsnappy statically.
|
|
|
|
if(SNAPPY_FOUND AND WITH_STATIC_LIBSTDCXX)
|
2018-08-06 09:55:02 +00:00
|
|
|
list(APPEND rocksdb_CMAKE_ARGS -DWITH_SNAPPY_STATIC_LIB=ON)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
list(APPEND rocksdb_CMAKE_ARGS -DWITH_LZ4=${LZ4_FOUND})
|
|
|
|
if(LZ4_FOUND)
|
|
|
|
list(APPEND rocksdb_INTERFACE_LINK_LIBRARIES LZ4::LZ4)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
list(APPEND rocksdb_CMAKE_ARGS -DWITH_ZLIB=${ZLIB_FOUND})
|
|
|
|
if(ZLIB_FOUND)
|
|
|
|
list(APPEND rocksdb_INTERFACE_LINK_LIBRARIES ZLIB::ZLIB)
|
2018-07-23 11:55:05 +00:00
|
|
|
endif()
|
2018-08-06 09:55:02 +00:00
|
|
|
|
|
|
|
list(APPEND rocksdb_CMAKE_ARGS -DPORTABLE=ON)
|
|
|
|
list(APPEND rocksdb_CMAKE_ARGS -DCMAKE_AR=${CMAKE_AR})
|
|
|
|
list(APPEND rocksdb_CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})
|
|
|
|
list(APPEND rocksdb_CMAKE_ARGS -DFAIL_ON_WARNINGS=OFF)
|
|
|
|
list(APPEND rocksdb_CMAKE_ARGS -DUSE_RTTI=1)
|
2019-03-21 05:16:13 +00:00
|
|
|
list(APPEND rocksdb_CMAKE_ARGS -G${CMAKE_GENERATOR})
|
2018-06-18 06:15:27 +00:00
|
|
|
CHECK_C_COMPILER_FLAG("-Wno-stringop-truncation" HAS_WARNING_STRINGOP_TRUNCATION)
|
|
|
|
if(HAS_WARNING_STRINGOP_TRUNCATION)
|
2019-06-12 08:50:14 +00:00
|
|
|
list(APPEND rocksdb_CMAKE_ARGS -DCMAKE_C_FLAGS=-Wno-stringop-truncation)
|
|
|
|
endif()
|
|
|
|
include(CheckCXXCompilerFlag)
|
|
|
|
check_cxx_compiler_flag("-Wno-deprecated-copy" HAS_WARNING_DEPRECATED_COPY)
|
|
|
|
if(HAS_WARNING_DEPRECATED_COPY)
|
|
|
|
set(rocksdb_CXX_FLAGS -Wno-deprecated-copy)
|
|
|
|
endif()
|
|
|
|
check_cxx_compiler_flag("-Wno-pessimizing-move" HAS_WARNING_PESSIMIZING_MOVE)
|
|
|
|
if(HAS_WARNING_PESSIMIZING_MOVE)
|
|
|
|
set(rocksdb_CXX_FLAGS "${rocksdb_CXX_FLAGS} -Wno-pessimizing-move")
|
|
|
|
endif()
|
|
|
|
if(rocksdb_CXX_FLAGS)
|
|
|
|
list(APPEND rocksdb_CMAKE_ARGS -DCMAKE_CXX_FLAGS='${rocksdb_CXX_FLAGS}')
|
2018-06-18 06:15:27 +00:00
|
|
|
endif()
|
2017-09-19 03:56:15 +00:00
|
|
|
# we use an external project and copy the sources to bin directory to ensure
|
|
|
|
# that object files are built outside of the source tree.
|
|
|
|
include(ExternalProject)
|
2018-08-06 09:55:02 +00:00
|
|
|
set(rocksdb_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/rocksdb")
|
|
|
|
set(rocksdb_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/rocksdb")
|
2019-05-27 11:53:42 +00:00
|
|
|
set(rocksdb_LIBRARY "${rocksdb_BINARY_DIR}/librocksdb.a")
|
2017-09-19 03:56:15 +00:00
|
|
|
ExternalProject_Add(rocksdb_ext
|
2018-08-06 09:55:02 +00:00
|
|
|
SOURCE_DIR "${rocksdb_SOURCE_DIR}"
|
|
|
|
CMAKE_ARGS ${rocksdb_CMAKE_ARGS}
|
|
|
|
BINARY_DIR "${rocksdb_BINARY_DIR}"
|
2019-03-21 05:16:13 +00:00
|
|
|
BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --target rocksdb
|
2019-07-11 11:30:26 +00:00
|
|
|
BUILD_ALWAYS TRUE
|
2019-05-27 11:53:42 +00:00
|
|
|
BUILD_BYPRODUCTS "${rocksdb_LIBRARY}"
|
2017-09-19 03:56:15 +00:00
|
|
|
INSTALL_COMMAND "true")
|
|
|
|
|
2018-08-06 09:55:02 +00:00
|
|
|
add_library(RocksDB::RocksDB STATIC IMPORTED)
|
|
|
|
add_dependencies(RocksDB::RocksDB rocksdb_ext)
|
|
|
|
set(rocksdb_INCLUDE_DIR "${rocksdb_SOURCE_DIR}/include")
|
2017-09-19 05:07:59 +00:00
|
|
|
foreach(ver "MAJOR" "MINOR" "PATCH")
|
2018-08-06 09:55:02 +00:00
|
|
|
file(STRINGS "${rocksdb_INCLUDE_DIR}/rocksdb/version.h" ROCKSDB_VER_${ver}_LINE
|
2017-09-19 05:07:59 +00:00
|
|
|
REGEX "^#define[ \t]+ROCKSDB_${ver}[ \t]+[0-9]+$")
|
|
|
|
string(REGEX REPLACE "^#define[ \t]+ROCKSDB_${ver}[ \t]+([0-9]+)$"
|
|
|
|
"\\1" ROCKSDB_VERSION_${ver} "${ROCKSDB_VER_${ver}_LINE}")
|
|
|
|
unset(ROCKDB_VER_${ver}_LINE)
|
|
|
|
endforeach()
|
2018-08-06 09:55:02 +00:00
|
|
|
set(rocksdb_VERSION_STRING
|
2017-09-19 05:07:59 +00:00
|
|
|
"${ROCKSDB_VERSION_MAJOR}.${ROCKSDB_VERSION_MINOR}.${ROCKSDB_VERSION_PATCH}")
|
2018-08-06 09:55:02 +00:00
|
|
|
set_target_properties(RocksDB::RocksDB PROPERTIES
|
|
|
|
INTERFACE_INCLUDE_DIRECTORIES "${rocksdb_INCLUDE_DIR}"
|
|
|
|
INTERFACE_LINK_LIBRARIES "${rocksdb_INTERFACE_LINK_LIBRARIES}"
|
|
|
|
IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
|
|
|
|
IMPORTED_LOCATION "${rocksdb_LIBRARY}"
|
|
|
|
VERSION "${rocksdb_VERSION_STRING}")
|
|
|
|
endfunction()
|