mirror of
https://github.com/ceph/ceph
synced 2025-04-17 13:03:42 +00:00
cmake: import allocator libraries in a better way
* instead expose the paths, it'd better to expose a library target. * remove HAVE_LIBJEMALLOC, as it not used anywhere. Signed-off-by: Kefu Chai <kchai@redhat.com>
This commit is contained in:
parent
8f33810bd2
commit
8db629a14b
@ -314,19 +314,17 @@ if(ALLOCATOR)
|
||||
set(HAVE_LIBTCMALLOC ON)
|
||||
elseif(${ALLOCATOR} STREQUAL "jemalloc")
|
||||
find_package(JeMalloc REQUIRED)
|
||||
set(HAVE_LIBJEMALLOC ${JEMALLOC_FOUND})
|
||||
set(HAVE_JEMALLOC 1)
|
||||
endif()
|
||||
else(ALLOCATOR)
|
||||
find_package(gperftools)
|
||||
set(HAVE_LIBTCMALLOC ${GPERFTOOLS_FOUND})
|
||||
if(NOT GPERFTOOLS_FOUND)
|
||||
set(HAVE_LIBTCMALLOC ${gperftools_FOUND})
|
||||
if(NOT gperftools_FOUND)
|
||||
find_package(JeMalloc)
|
||||
set(HAVE_LIBJEMALLOC ${JEMALLOC_FOUND})
|
||||
endif(NOT GPERFTOOLS_FOUND)
|
||||
if(GPERFTOOLS_FOUND)
|
||||
endif()
|
||||
if(gperftools_FOUND)
|
||||
set(ALLOCATOR tcmalloc)
|
||||
elseif(JEMALLOC_FOUND)
|
||||
elseif(JeMalloc_FOUND)
|
||||
set(ALLOCATOR jemalloc)
|
||||
else()
|
||||
if(NOT FREEBSD)
|
||||
@ -334,7 +332,7 @@ else(ALLOCATOR)
|
||||
message(WARNING "tcmalloc and jemalloc not found, falling back to libc")
|
||||
endif()
|
||||
set(ALLOCATOR "libc")
|
||||
endif(GPERFTOOLS_FOUND)
|
||||
endif(gperftools_FOUND)
|
||||
endif(ALLOCATOR)
|
||||
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
# JEMALLOC_INCLUDE_DIRS, where to find jemalloc.h, Set when
|
||||
# JEMALLOC_INCLUDE_DIR is found.
|
||||
# JEMALLOC_LIBRARIES, libraries to link against to use JeMalloc.
|
||||
# JEMALLOC_FOUND, If false, do not try to use JeMalloc.
|
||||
# JeMalloc_FOUND, If false, do not try to use JeMalloc.
|
||||
#
|
||||
|
||||
find_path(JEMALLOC_INCLUDE_DIR jemalloc/jemalloc.h)
|
||||
@ -11,10 +11,19 @@ find_path(JEMALLOC_INCLUDE_DIR jemalloc/jemalloc.h)
|
||||
find_library(JEMALLOC_LIBRARIES jemalloc)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(JeMalloc DEFAULT_MSG
|
||||
JEMALLOC_LIBRARIES JEMALLOC_INCLUDE_DIR)
|
||||
find_package_handle_standard_args(JeMalloc
|
||||
FOUND_VAR JeMalloc_FOUND
|
||||
REQUIRED_VARS JEMALLOC_LIBRARIES JEMALLOC_INCLUDE_DIR)
|
||||
|
||||
mark_as_advanced(
|
||||
JEMALLOC_INCLUDE_DIR
|
||||
JEMALLOC_LIBRARIES)
|
||||
|
||||
if(JeMalloc_FOUND AND NOT (TARGET JeMalloc::JeMalloc))
|
||||
add_library(JeMalloc::JeMalloc UNKNOWN IMPORTED)
|
||||
set_target_properties(JeMalloc::JeMalloc PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${JEMALLOC_INCLUDE_DIR}"
|
||||
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
|
||||
IMPORTED_LOCATION "${JEMALLOC_LIBRARIES}")
|
||||
endforeach()
|
||||
endif()
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Try to find gperftools
|
||||
# Once done, this will define
|
||||
#
|
||||
# GPERFTOOLS_FOUND - system has Profiler
|
||||
# gperftools_FOUND - system has Profiler
|
||||
# GPERFTOOLS_INCLUDE_DIR - the Profiler include directories
|
||||
# Tcmalloc_INCLUDE_DIR - where to find Tcmalloc.h
|
||||
# GPERFTOOLS_TCMALLOC_LIBRARY - link it to use tcmalloc
|
||||
@ -38,9 +38,39 @@ foreach(component tcmalloc tcmalloc_minimal profiler)
|
||||
list(APPEND GPERFTOOLS_LIBRARIES GPERFTOOLS_${COMPONENT}_LIBRARY)
|
||||
endforeach()
|
||||
|
||||
set(_gperftools_FIND_REQUIRED_VARS "GPERFTOOLS_INCLUDE_DIR")
|
||||
if(gperftools_FIND_COMPONENTS)
|
||||
foreach(component ${gperftools_FIND_COMPONENTS})
|
||||
string(TOUPPER ${component} COMPONENT)
|
||||
list(APPEND _gperftools_FIND_REQUIRED_VARS "GPERFTOOLS_${COMPONENT}_LIBRARY")
|
||||
endforeach()
|
||||
else()
|
||||
list(APPEND _gperftools_FIND_REQUIRED_VARS "GPERFTOOLS_LIBRARIES")
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(gperftools
|
||||
REQUIRED_VARS ${GPERFTOOLS_LIBRARIES} GPERFTOOLS_INCLUDE_DIR
|
||||
FOUND_VAR gperftools_FOUND
|
||||
REQUIRED_VARS ${_gperftools_FIND_REQUIRED_VARS}
|
||||
VERSION_VAR TCMALLOC_VERSION_STRING)
|
||||
|
||||
mark_as_advanced(${GPERFTOOLS_LIBRARIES} GPERFTOOLS_INCLUDE_DIR)
|
||||
|
||||
if(gperftools_FOUND)
|
||||
foreach(component tcmalloc tcmalloc_minimal profiler)
|
||||
if(NOT (TARGET gperftools::${component}))
|
||||
string(TOUPPER ${component} COMPONENT)
|
||||
add_library(gperftools::${component} UNKNOWN IMPORTED)
|
||||
set_target_properties(gperftools::${component} PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${GPERFTOOLS_INCLUDE_DIR}"
|
||||
IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
|
||||
IMPORTED_LOCATION "${GPERFTOOLS_${COMPONENT}_LIBRARY}")
|
||||
endif()
|
||||
endforeach()
|
||||
foreach(component tcmalloc tcmalloc_minimal)
|
||||
if(NOT (TARGET gperftools::${component}))
|
||||
set_target_properties(gperftools::${component} PROPERTIES
|
||||
INTERFACE_COMPILE_OPTIONS "-fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free")
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
@ -299,15 +299,15 @@ endif(HAVE_XIO)
|
||||
|
||||
# sort out which allocator to use
|
||||
if(ALLOCATOR STREQUAL "tcmalloc")
|
||||
set(ALLOC_LIBS ${GPERFTOOLS_TCMALLOC_LIBRARY})
|
||||
set(ALLOC_LIBS gperftools::tcmalloc)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free")
|
||||
set(TCMALLOC_srcs perfglue/heap_profiler.cc)
|
||||
elseif(ALLOCATOR STREQUAL "tcmalloc_minimal")
|
||||
set(ALLOC_LIBS ${GPERFTOOLS_TCMALLOC_MINIMAL_LIBRARY})
|
||||
set(ALLOC_LIBS gperftools::tcmalloc_minimal)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free")
|
||||
set(TCMALLOC_srcs perfglue/disabled_heap_profiler.cc)
|
||||
elseif(ALLOCATOR STREQUAL "jemalloc")
|
||||
set(ALLOC_LIBS ${JEMALLOC_LIBRARIES})
|
||||
set(ALLOC_LIBS JeMalloc::JeMalloc)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free")
|
||||
set(TCMALLOC_srcs perfglue/disabled_heap_profiler.cc)
|
||||
elseif(ALLOCATOR STREQUAL "libc")
|
||||
|
@ -117,9 +117,6 @@
|
||||
/* Define if you have tcmalloc */
|
||||
#cmakedefine HAVE_LIBTCMALLOC
|
||||
|
||||
/* Define if you have jemalloc */
|
||||
#cmakedefine HAVE_LIBJEMALLOC
|
||||
|
||||
/* Define if have curl_multi_wait() */
|
||||
#cmakedefine HAVE_CURL_MULTI_WAIT 1
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user