cmake: check for aligned_alloc()

in case developer is using patched tcmalloc.

Signed-off-by: Kefu Chai <kchai@redhat.com>
This commit is contained in:
Kefu Chai 2017-10-26 18:26:24 +08:00
parent 3f6e0b6e80
commit 16f0a67d83

View File

@ -1,3 +1,5 @@
include(CheckCXXSourceCompiles)
function(do_build_rocksdb)
set(ROCKSDB_CMAKE_ARGS -DCMAKE_POSITION_INDEPENDENT_CODE=ON)
@ -38,6 +40,37 @@ function(do_build_rocksdb)
ALWAYS 1)
endfunction()
function(check_aligned_alloc)
set(SAVE_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
set(CMAKE_REQUIRED_FLAGS "-std=c++11 -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free -nostdlib")
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})
CHECK_CXX_SOURCE_COMPILES("
#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()
macro(build_rocksdb)
do_build_rocksdb()
add_library(rocksdb STATIC IMPORTED)
@ -60,11 +93,7 @@ macro(build_rocksdb)
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)
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'.")
check_aligned_alloc()
endif()
endif()
endmacro()