diff --git a/CMakeLists.txt b/CMakeLists.txt index ba3120d5dff..0f7fb06390f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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( + $<$:-fno-builtin-malloc> + $<$:-fno-builtin-calloc> + $<$:-fno-builtin-realloc> + $<$:-fno-builtin-free>) +endif() # Mingw generates incorrect entry points when using "-pie". if(WIN32 OR (HAVE_LIBTCMALLOC AND WITH_STATIC_LIBSTDCXX)) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5684361dcad..563f0851315 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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($<$:-fno-builtin-malloc>) - add_compile_options($<$:-fno-builtin-calloc>) - add_compile_options($<$:-fno-builtin-realloc>) - add_compile_options($<$:-fno-builtin-free>) -elseif(ALLOCATOR STREQUAL "tcmalloc_minimal") - set(ALLOC_LIBS gperftools::tcmalloc_minimal) - add_compile_options($<$:-fno-builtin-malloc>) - add_compile_options($<$:-fno-builtin-calloc>) - add_compile_options($<$:-fno-builtin-realloc>) - add_compile_options($<$:-fno-builtin-free>) -elseif(ALLOCATOR STREQUAL "jemalloc") - set(ALLOC_LIBS JeMalloc::JeMalloc) - add_compile_options($<$:-fno-builtin-malloc>) - add_compile_options($<$:-fno-builtin-calloc>) - add_compile_options($<$:-fno-builtin-realloc>) - add_compile_options($<$:-fno-builtin-free>) -endif() - if (WITH_BLKIN) add_subdirectory(blkin/blkin-lib) endif(WITH_BLKIN)