Merge pull request #23441 from tchaikov/wip-cmake-rocksdb-cleanup

cmake: rocksdb related cleanup

Reviewed-by: Casey Bodley <cbodley@redhat.com>
This commit is contained in:
Kefu Chai 2018-08-09 00:46:53 +08:00 committed by GitHub
commit 72cc4cedd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 82 additions and 41 deletions

View File

@ -314,6 +314,10 @@ if(WITH_LZ4)
endif(WITH_LZ4)
#if allocator is set on command line make sure it matches below strings
set(ALLOCATOR "" CACHE STRING
"specify memory allocator to use. currently tcmalloc, tcmalloc_minimal, \
jemalloc, and libc is supported. if not specified, will try to find tcmalloc, \
and then jemalloc. If neither of then is found. use the one in libc.")
if(ALLOCATOR)
if(${ALLOCATOR} MATCHES "tcmalloc(_minimal)?")
find_package(gperftools REQUIRED)
@ -581,7 +585,7 @@ endif()
# Rocksdb
option(WITH_SYSTEM_ROCKSDB "require and build with system rocksdb" OFF)
if (WITH_SYSTEM_ROCKSDB)
find_package(rocksdb 5.8 REQUIRED)
find_package(RocksDB 5.8 REQUIRED)
endif()
option(WITH_SEASTAR "Build seastar components")

View File

@ -1,67 +1,83 @@
function(do_build_rocksdb)
set(ROCKSDB_CMAKE_ARGS -DCMAKE_POSITION_INDEPENDENT_CODE=ON)
list(APPEND ROCKSDB_CMAKE_ARGS -DWITH_GFLAGS=OFF)
function(build_rocksdb)
set(rocksdb_CMAKE_ARGS -DCMAKE_POSITION_INDEPENDENT_CODE=ON)
list(APPEND rocksdb_CMAKE_ARGS -DWITH_GFLAGS=OFF)
if(ALLOCATOR STREQUAL "jemalloc")
list(APPEND ROCKSDB_CMAKE_ARGS -DWITH_JEMALLOC=ON)
list(APPEND rocksdb_CMAKE_ARGS -DWITH_JEMALLOC=ON)
list(APPEND rocksdb_INTERFACE_LINK_LIBRARIES JeMalloc::JeMalloc)
endif()
if (WITH_CCACHE AND CCACHE_FOUND)
list(APPEND ROCKSDB_CMAKE_ARGS -DCMAKE_CXX_COMPILER=ccache)
list(APPEND ROCKSDB_CMAKE_ARGS -DCMAKE_CXX_COMPILER_ARG1=${CMAKE_CXX_COMPILER})
list(APPEND rocksdb_CMAKE_ARGS -DCMAKE_CXX_COMPILER=ccache)
list(APPEND rocksdb_CMAKE_ARGS -DCMAKE_CXX_COMPILER_ARG1=${CMAKE_CXX_COMPILER})
else()
list(APPEND ROCKSDB_CMAKE_ARGS -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER})
list(APPEND rocksdb_CMAKE_ARGS -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER})
endif()
list(APPEND rocksdb_CMAKE_ARGS -DWITH_SNAPPY=${SNAPPY_FOUND})
if(SNAPPY_FOUND)
list(APPEND rocksdb_INTERFACE_LINK_LIBRARIES snappy::snappy)
endif()
# libsnappy is a C++ library, we need to force rocksdb to link against
# libsnappy statically.
list(APPEND ROCKSDB_CMAKE_ARGS -DWITH_SNAPPY=${SNAPPY_FOUND})
if(SNAPPY_FOUND AND WITH_STATIC_LIBSTDCXX)
list(APPEND ROCKSDB_CMAKE_ARGS -DWITH_SNAPPY_STATIC_LIB=ON)
list(APPEND rocksdb_CMAKE_ARGS -DWITH_SNAPPY_STATIC_LIB=ON)
endif()
list(APPEND ROCKSDB_CMAKE_ARGS -DWITH_LZ4=${LZ4_FOUND})
list(APPEND ROCKSDB_CMAKE_ARGS -DWITH_ZLIB=${ZLIB_FOUND})
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)
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)
endif()
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)
CHECK_C_COMPILER_FLAG("-Wno-stringop-truncation" HAS_WARNING_STRINGOP_TRUNCATION)
if(HAS_WARNING_STRINGOP_TRUNCATION)
list(APPEND ROCKSDB_CMAKE_ARGS -DCMAKE_C_FLAGS="-Wno-stringop-truncation")
list(APPEND rocksdb_CMAKE_ARGS -DCMAKE_C_FLAGS="-Wno-stringop-truncation")
endif()
# 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)
set(rocksdb_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/rocksdb")
set(rocksdb_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/rocksdb")
ExternalProject_Add(rocksdb_ext
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/rocksdb
CMAKE_ARGS ${ROCKSDB_CMAKE_ARGS}
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/rocksdb
SOURCE_DIR "${rocksdb_SOURCE_DIR}"
CMAKE_ARGS ${rocksdb_CMAKE_ARGS}
BINARY_DIR "${rocksdb_BINARY_DIR}"
BUILD_COMMAND $(MAKE) rocksdb
INSTALL_COMMAND "true")
# force rocksdb make to be called on each time
ExternalProject_Add_Step(rocksdb_ext forcebuild
DEPENDEES configure
DEPENDERS build
COMMAND "true"
ALWAYS 1)
endfunction()
macro(build_rocksdb)
do_build_rocksdb()
add_library(rocksdb STATIC IMPORTED)
add_dependencies(rocksdb rocksdb_ext)
set_property(TARGET rocksdb PROPERTY IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/rocksdb/librocksdb.a")
set(ROCKSDB_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/rocksdb/include)
set(ROCKSDB_LIBRARIES rocksdb)
add_library(RocksDB::RocksDB STATIC IMPORTED)
add_dependencies(RocksDB::RocksDB rocksdb_ext)
set(rocksdb_INCLUDE_DIR "${rocksdb_SOURCE_DIR}/include")
set(rocksdb_LIBRARY "${rocksdb_BINARY_DIR}/librocksdb.a")
foreach(ver "MAJOR" "MINOR" "PATCH")
file(STRINGS "${ROCKSDB_INCLUDE_DIR}/rocksdb/version.h" ROCKSDB_VER_${ver}_LINE
file(STRINGS "${rocksdb_INCLUDE_DIR}/rocksdb/version.h" ROCKSDB_VER_${ver}_LINE
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()
set(ROCKSDB_VERSION_STRING
set(rocksdb_VERSION_STRING
"${ROCKSDB_VERSION_MAJOR}.${ROCKSDB_VERSION_MINOR}.${ROCKSDB_VERSION_PATCH}")
endmacro()
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()

View File

@ -32,3 +32,12 @@ find_package_handle_standard_args(LZ4
VERSION_VAR LZ4_VERSION_STRING)
mark_as_advanced(LZ4_INCLUDE_DIR LZ4_LIBRARY)
if(LZ4_FOUND AND NOT (TARGET LZ4::LZ4))
add_library(LZ4::LZ4 UNKNOWN IMPORTED)
set_target_properties(LZ4::LZ4 PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${LZ4_INCLUDE_DIR}"
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${LZ4_LIBRARY}"
VERSION "${LZ4_VERSION_STRING}")
endif()

View File

@ -26,10 +26,22 @@ if(ROCKSDB_INCLUDE_DIR AND EXISTS "${ROCKSDB_INCLUDE_DIR}/rocksdb/version.h")
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(rocksdb
find_package_handle_standard_args(RocksDB
REQUIRED_VARS ROCKSDB_LIBRARIES ROCKSDB_INCLUDE_DIR
VERSION_VAR ROCKSDB_VERSION_STRING)
mark_as_advanced(
ROCKSDB_INCLUDE_DIR
ROCKSDB_LIBRARIES)
if(RocksDB_FOUND)
if(NOT TARGET RocksDB::RocksDB)
add_library(RocksDB::RocksDB UNKNOWN IMPORTED)
set_target_properties(RocksDB::RocksDB PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${ROCKSDB_INCLUDE_DIR}"
IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
IMPORTED_LOCATION "${ROCKSDB_LIBRARY}"
VERSION "${ROCKSDB_VERSION_STRING}")
endif()
endif()

View File

@ -9,9 +9,8 @@ endif (WITH_LEVELDB)
add_library(kv_objs OBJECT ${kv_srcs})
add_library(kv STATIC $<TARGET_OBJECTS:kv_objs>)
target_include_directories(kv_objs SYSTEM BEFORE PUBLIC ${ROCKSDB_INCLUDE_DIR})
target_include_directories(kv SYSTEM BEFORE PUBLIC ${ROCKSDB_INCLUDE_DIR})
target_link_libraries(kv ${LEVELDB_LIBRARIES} ${ROCKSDB_LIBRARIES} ${SNAPPY_LIBRARIES} ${ZLIB_LIBRARIES})
if(WITH_LZ4)
target_link_libraries(kv ${LZ4_LIBRARY})
endif()
target_include_directories(kv_objs SYSTEM BEFORE PUBLIC
$<TARGET_PROPERTY:RocksDB::RocksDB,INTERFACE_INCLUDE_DIRECTORIES>)
target_include_directories(kv SYSTEM BEFORE PUBLIC
$<TARGET_PROPERTY:RocksDB::RocksDB,INTERFACE_INCLUDE_DIRECTORIES>)
target_link_libraries(kv ${LEVELDB_LIBRARIES} RocksDB::RocksDB)

View File

@ -76,7 +76,8 @@ add_library(os STATIC ${libos_srcs} $<TARGET_OBJECTS:kv_objs>)
if(WITH_BLUEFS)
add_library(bluefs SHARED
bluestore/BlueRocksEnv.cc)
target_include_directories(bluefs SYSTEM PUBLIC ${ROCKSDB_INCLUDE_DIR})
target_include_directories(bluefs SYSTEM PUBLIC
$<TARGET_PROPERTY:RocksDB::RocksDB,INTERFACE_INCLUDE_DIRECTORIES>)
target_link_libraries(bluefs global)
install(TARGETS bluefs DESTINATION lib)
endif(WITH_BLUEFS)