]> git.proxmox.com Git - ceph.git/blob - ceph/cmake/modules/Findgperftools.cmake
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / cmake / modules / Findgperftools.cmake
1 # Try to find gperftools
2 # Once done, this will define
3 #
4 # gperftools_FOUND - system has Profiler
5 # GPERFTOOLS_INCLUDE_DIR - the Profiler include directories
6 # Tcmalloc_INCLUDE_DIR - where to find Tcmalloc.h
7 # GPERFTOOLS_TCMALLOC_LIBRARY - link it to use tcmalloc
8 # GPERFTOOLS_TCMALLOC_MINIMAL_LIBRARY - link it to use tcmalloc_minimal
9 # GPERFTOOLS_PROFILER_LIBRARY - link it to use Profiler
10 # TCMALLOC_VERSION_STRING
11 # TCMALLOC_VERSION_MAJOR
12 # TCMALLOC_VERSION_MINOR
13 # TCMALLOC_VERSION_PATCH
14
15 find_path(GPERFTOOLS_INCLUDE_DIR gperftools/profiler.h
16 HINTS $ENV{GPERF_ROOT}/include)
17 find_path(Tcmalloc_INCLUDE_DIR gperftools/tcmalloc.h
18 HINTS $ENV{GPERF_ROOT}/include)
19
20 if(Tcmalloc_INCLUDE_DIR AND EXISTS "${Tcmalloc_INCLUDE_DIR}/gperftools/tcmalloc.h")
21 foreach(ver "MAJOR" "MINOR" "PATCH")
22 file(STRINGS "${Tcmalloc_INCLUDE_DIR}/gperftools/tcmalloc.h" TC_VER_${ver}_LINE
23 REGEX "^#define[ \t]+TC_VERSION_${ver}[ \t]+[^ \t]+$")
24 string(REGEX REPLACE "^#define[ \t]+TC_VERSION_${ver}[ \t]+(\".)?([0-9]*)\"?$"
25 "\\2" TCMALLOC_VERSION_${ver} "${TC_VER_${ver}_LINE}")
26 unset(TC_VER_${ver}_LINE)
27 endforeach()
28 set(TCMALLOC_VERSION_STRING "${TCMALLOC_VERSION_MAJOR}.${TCMALLOC_VERSION_MINOR}")
29 if(NOT TCMALLOC_VERSION_PATCH STREQUAL "")
30 set(TCMALLOC_VERSION_STRING "${TCMALLOC_VERSION_STRING}.${TCMALLOC_VERSION_PATCH}")
31 endif()
32 endif()
33
34 foreach(component tcmalloc tcmalloc_minimal profiler)
35 string(TOUPPER ${component} COMPONENT)
36 find_library(GPERFTOOLS_${COMPONENT}_LIBRARY ${component}
37 HINTS $ENV{GPERF_ROOT}/lib)
38 list(APPEND GPERFTOOLS_LIBRARIES GPERFTOOLS_${COMPONENT}_LIBRARY)
39 endforeach()
40
41 set(_gperftools_FIND_REQUIRED_VARS "GPERFTOOLS_INCLUDE_DIR")
42 if(gperftools_FIND_COMPONENTS)
43 foreach(component ${gperftools_FIND_COMPONENTS})
44 string(TOUPPER ${component} COMPONENT)
45 list(APPEND _gperftools_FIND_REQUIRED_VARS "GPERFTOOLS_${COMPONENT}_LIBRARY")
46 endforeach()
47 else()
48 list(APPEND _gperftools_FIND_REQUIRED_VARS "GPERFTOOLS_LIBRARIES")
49 endif()
50
51 include(FindPackageHandleStandardArgs)
52 find_package_handle_standard_args(gperftools
53 FOUND_VAR gperftools_FOUND
54 REQUIRED_VARS ${_gperftools_FIND_REQUIRED_VARS}
55 VERSION_VAR TCMALLOC_VERSION_STRING)
56
57 mark_as_advanced(${GPERFTOOLS_LIBRARIES} GPERFTOOLS_INCLUDE_DIR)
58
59 if(gperftools_FOUND)
60 foreach(component tcmalloc tcmalloc_minimal profiler)
61 if(NOT (TARGET gperftools::${component}))
62 string(TOUPPER ${component} COMPONENT)
63 add_library(gperftools::${component} UNKNOWN IMPORTED)
64 set_target_properties(gperftools::${component} PROPERTIES
65 INTERFACE_INCLUDE_DIRECTORIES "${GPERFTOOLS_INCLUDE_DIR}"
66 IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
67 IMPORTED_LOCATION "${GPERFTOOLS_${COMPONENT}_LIBRARY}")
68 endif()
69 endforeach()
70 foreach(component tcmalloc tcmalloc_minimal)
71 if(NOT (TARGET gperftools::${component}))
72 set_target_properties(gperftools::${component} PROPERTIES
73 INTERFACE_COMPILE_OPTIONS "-fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free")
74 endif()
75 endforeach()
76 endif()