]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: restructure allocator related code
authorKefu Chai <tchaikov@gmail.com>
Mon, 2 May 2022 02:46:05 +0000 (10:46 +0800)
committerKefu Chai <tchaikov@gmail.com>
Mon, 2 May 2022 03:54:08 +0000 (11:54 +0800)
before this change, the ALLOCATOR cmake option are handled at two
difference places: one to handle ALLOCATOR option, another to add
compilation options based on ALLOCATOR. after this change:

* the ALLOCATOR option is handled in a single place
* dedup the branches handling different ALLOCATORS into a single
  condition: (NOT ALLOCATOR STREQUAL "libc")
* add_compile_options() calls are consolidated into a single one

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
CMakeLists.txt
src/CMakeLists.txt

index ba3120d5dff41e06b0c9998152545dc490678f2a..0f7fb06390f72dc98984db9048cfd8e0c74fab70 100644 (file)
@@ -341,9 +341,11 @@ and then jemalloc. If neither of then is found. use the one in libc.")
 if(ALLOCATOR)
   if(${ALLOCATOR} MATCHES "tcmalloc(_minimal)?")
     find_package(gperftools 2.6.2 REQUIRED)
+    set(ALLOC_LIBS gperftools::${ALLOCATOR})
     set(HAVE_LIBTCMALLOC ON)
   elseif(${ALLOCATOR} STREQUAL "jemalloc")
     find_package(JeMalloc REQUIRED)
+    set(ALLOC_LIBS JeMalloc::JeMalloc)
     set(HAVE_JEMALLOC 1)
   elseif(NOT ALLOCATOR STREQUAL "libc")
     message(FATAL_ERROR "Unsupported allocator selected: ${ALLOCATOR}")
@@ -356,8 +358,10 @@ else(ALLOCATOR)
   endif()
   if(gperftools_FOUND)
     set(ALLOCATOR tcmalloc)
+    set(ALLOC_LIBS gperftools::tcmalloc)
   elseif(JeMalloc_FOUND)
     set(ALLOCATOR jemalloc)
+    set(ALLOC_LIBS JeMalloc::JeMalloc)
   else()
     if(NOT FREEBSD)
       # FreeBSD already has jemalloc as its default allocator
@@ -366,6 +370,13 @@ else(ALLOCATOR)
     set(ALLOCATOR "libc")
   endif(gperftools_FOUND)
 endif(ALLOCATOR)
+if(NOT ALLOCATOR STREQUAL "libc")
+  add_compile_options(
+    $<$<COMPILE_LANGUAGE:CXX>:-fno-builtin-malloc>
+    $<$<COMPILE_LANGUAGE:CXX>:-fno-builtin-calloc>
+    $<$<COMPILE_LANGUAGE:CXX>:-fno-builtin-realloc>
+    $<$<COMPILE_LANGUAGE:CXX>:-fno-builtin-free>)
+endif()
 
 # Mingw generates incorrect entry points when using "-pie".
 if(WIN32 OR (HAVE_LIBTCMALLOC AND WITH_STATIC_LIBSTDCXX))
index 5684361dcadcd1223fe70a3e7f683473c25eea61..563f08513150e75a707391e4215f736cd0bb4ce4 100644 (file)
@@ -276,27 +276,6 @@ if(WITH_CEPHFS_JAVA)
   add_subdirectory(java)
 endif()
 
-# sort out which allocator to use
-if(ALLOCATOR STREQUAL "tcmalloc")
-  set(ALLOC_LIBS gperftools::tcmalloc)
-  add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-builtin-malloc>)
-  add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-builtin-calloc>)
-  add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-builtin-realloc>)
-  add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-builtin-free>)
-elseif(ALLOCATOR STREQUAL "tcmalloc_minimal")
-  set(ALLOC_LIBS gperftools::tcmalloc_minimal)
-  add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-builtin-malloc>)
-  add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-builtin-calloc>)
-  add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-builtin-realloc>)
-  add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-builtin-free>)
-elseif(ALLOCATOR STREQUAL "jemalloc")
-  set(ALLOC_LIBS JeMalloc::JeMalloc)
-  add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-builtin-malloc>)
-  add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-builtin-calloc>)
-  add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-builtin-realloc>)
-  add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-builtin-free>)
-endif()
-
 if (WITH_BLKIN)
   add_subdirectory(blkin/blkin-lib)
 endif(WITH_BLKIN)