]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
cmake: check for aligned_alloc()
authorKefu Chai <kchai@redhat.com>
Thu, 26 Oct 2017 10:26:24 +0000 (18:26 +0800)
committerKefu Chai <kchai@redhat.com>
Fri, 27 Oct 2017 03:13:15 +0000 (11:13 +0800)
in case developer is using patched tcmalloc.

Signed-off-by: Kefu Chai <kchai@redhat.com>
cmake/modules/BuildRocksDB.cmake

index 108db6b6da81a281b84928d1e80f8bf09566edca..da6e18d04e0878029439555867c189f853538eec 100644 (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()