2017-10-31 09:39:02 +00:00
|
|
|
include(CheckCXXSourceRuns)
|
2017-10-26 10:26:24 +00:00
|
|
|
|
2017-09-19 03:56:15 +00:00
|
|
|
function(do_build_rocksdb)
|
|
|
|
set(ROCKSDB_CMAKE_ARGS -DCMAKE_POSITION_INDEPENDENT_CODE=ON)
|
|
|
|
|
|
|
|
if(ALLOCATOR STREQUAL "jemalloc")
|
|
|
|
list(APPEND ROCKSDB_CMAKE_ARGS -DWITH_JEMALLOC=ON)
|
|
|
|
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})
|
|
|
|
else()
|
|
|
|
list(APPEND ROCKSDB_CMAKE_ARGS -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER})
|
|
|
|
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})
|
2017-12-09 12:18:39 +00:00
|
|
|
list(APPEND ROCKSDB_CMAKE_ARGS -DFAIL_ON_WARNINGS=OFF)
|
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)
|
|
|
|
ExternalProject_Add(rocksdb_ext
|
|
|
|
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/rocksdb
|
|
|
|
CMAKE_ARGS ${ROCKSDB_CMAKE_ARGS}
|
|
|
|
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/rocksdb
|
|
|
|
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()
|
|
|
|
|
2017-10-26 10:26:24 +00:00
|
|
|
function(check_aligned_alloc)
|
|
|
|
set(SAVE_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
|
2017-10-31 09:39:02 +00:00
|
|
|
set(CMAKE_REQUIRED_FLAGS "-std=c++11 -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free")
|
2017-10-26 10:26:24 +00:00
|
|
|
if(LINUX)
|
|
|
|
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_GNU_SOURCE")
|
|
|
|
endif()
|
|
|
|
set(SAVE_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
|
|
|
|
set(CMAKE_REQUIRED_LIBRARIES ${GPERFTOOLS_TCMALLOC_LIBRARY})
|
2017-10-31 09:39:02 +00:00
|
|
|
CHECK_CXX_SOURCE_RUNS("
|
2017-10-26 10:26:24 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
#if defined(_ISOC11_SOURCE)
|
|
|
|
void* buf = aligned_alloc(64, 42);
|
|
|
|
free(buf);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
" HAVE_ALIGNED_ALLOC)
|
|
|
|
set(CMAKE_REQUIRED_FLAGS ${SAVE_CMAKE_REQUIRED_FLAGS})
|
|
|
|
set(CMAKE_REQUIRED_LIBRARIES ${SAVE_CMAKE_REQUIRED_LIBRARIES})
|
|
|
|
|
|
|
|
if(NOT HAVE_ALIGNED_ALLOC)
|
|
|
|
message(SEND_ERROR
|
|
|
|
"Incompatible tcmalloc v${TCMALLOC_VERSION_STRING} and rocksdb "
|
|
|
|
"v${ROCKSDB_VERSION_STRING}, please install gperf-tools 2.5 (not 2.5.93) "
|
|
|
|
"or >= 2.6.2, or switch to another allocator using "
|
|
|
|
"'cmake -DALLOCATOR=libc'.")
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
2017-09-19 03:56:15 +00:00
|
|
|
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)
|
2017-09-19 05:07:59 +00:00
|
|
|
foreach(ver "MAJOR" "MINOR" "PATCH")
|
|
|
|
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
|
|
|
|
"${ROCKSDB_VERSION_MAJOR}.${ROCKSDB_VERSION_MINOR}.${ROCKSDB_VERSION_PATCH}")
|
cmake: error out if rocksdb is incompatible w/ tcmalloc
the commit d406f228 in gperf implements a c11 feature used by a
recent change in rocksdb: 16e03882, which uses aligned_alloc().
and 16e03882 in rocksdb was merged after v5.7 was tagged, while
16e03882 in gperf was merged after v2.6.1 was tagged.
because aligned_alloc() is not implemented by tcmalloc until the
not-yet-released 2.6.2, if we call aligned_alloc() in an application
linked against tcmalloc, what gets called will be the glibc's
aligned_alloc(). but if we free() the memory chunk allocated by
aligned_alloc(), the tcmalloc's implementation kicks in, then
InvalidFree() is called, because the memory chunk being freed was
allocated by tcmalloc. in short, "mixing allocators", quote from
Dan Mick.
in rocksdb, aligned_alloc() is used if _ISOC11_SOURCE is defined, this
makes sense, because aligned_alloc() is a C11 function. we could avoid
using it by not defining _ISOC11_SOURCE. but as long as _GNU_SOURCE is
defined, glibc defines _ISOC11_SOURCE. and libstdc++ requires
_GNU_SOURCE, because it uses a fair amount of GNU extensions.
Fixes: http://tracker.ceph.com/issues/21422
Signed-off-by: Kefu Chai <kchai@redhat.com>
2017-09-19 04:23:44 +00:00
|
|
|
|
|
|
|
if(ALLOCATOR MATCHES "tcmalloc(_minimal)?")
|
|
|
|
# see http://tracker.ceph.com/issues/21422
|
|
|
|
if(ROCKSDB_VERSION_STRING VERSION_GREATER 5.7 AND
|
|
|
|
TCMALLOC_VERSION_STRING VERSION_GREATER 2.5 AND
|
|
|
|
TCMALLOC_VERSION_STRING VERSION_LESS 2.6.2)
|
2017-10-26 10:26:24 +00:00
|
|
|
check_aligned_alloc()
|
cmake: error out if rocksdb is incompatible w/ tcmalloc
the commit d406f228 in gperf implements a c11 feature used by a
recent change in rocksdb: 16e03882, which uses aligned_alloc().
and 16e03882 in rocksdb was merged after v5.7 was tagged, while
16e03882 in gperf was merged after v2.6.1 was tagged.
because aligned_alloc() is not implemented by tcmalloc until the
not-yet-released 2.6.2, if we call aligned_alloc() in an application
linked against tcmalloc, what gets called will be the glibc's
aligned_alloc(). but if we free() the memory chunk allocated by
aligned_alloc(), the tcmalloc's implementation kicks in, then
InvalidFree() is called, because the memory chunk being freed was
allocated by tcmalloc. in short, "mixing allocators", quote from
Dan Mick.
in rocksdb, aligned_alloc() is used if _ISOC11_SOURCE is defined, this
makes sense, because aligned_alloc() is a C11 function. we could avoid
using it by not defining _ISOC11_SOURCE. but as long as _GNU_SOURCE is
defined, glibc defines _ISOC11_SOURCE. and libstdc++ requires
_GNU_SOURCE, because it uses a fair amount of GNU extensions.
Fixes: http://tracker.ceph.com/issues/21422
Signed-off-by: Kefu Chai <kchai@redhat.com>
2017-09-19 04:23:44 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
2017-09-19 03:56:15 +00:00
|
|
|
endmacro()
|