summaryrefslogtreecommitdiffstats
path: root/cmake/modules/Findgperftools.cmake
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
commit19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch)
tree42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /cmake/modules/Findgperftools.cmake
parentInitial commit. (diff)
downloadceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.tar.xz
ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.zip
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'cmake/modules/Findgperftools.cmake')
-rw-r--r--cmake/modules/Findgperftools.cmake76
1 files changed, 76 insertions, 0 deletions
diff --git a/cmake/modules/Findgperftools.cmake b/cmake/modules/Findgperftools.cmake
new file mode 100644
index 000000000..52e2df0de
--- /dev/null
+++ b/cmake/modules/Findgperftools.cmake
@@ -0,0 +1,76 @@
+# Try to find gperftools
+# Once done, this will define
+#
+# 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
+# GPERFTOOLS_TCMALLOC_MINIMAL_LIBRARY - link it to use tcmalloc_minimal
+# GPERFTOOLS_PROFILER_LIBRARY - link it to use Profiler
+# TCMALLOC_VERSION_STRING
+# TCMALLOC_VERSION_MAJOR
+# TCMALLOC_VERSION_MINOR
+# TCMALLOC_VERSION_PATCH
+
+find_path(GPERFTOOLS_INCLUDE_DIR gperftools/profiler.h
+ HINTS $ENV{GPERF_ROOT}/include)
+find_path(Tcmalloc_INCLUDE_DIR gperftools/tcmalloc.h
+ HINTS $ENV{GPERF_ROOT}/include)
+
+if(Tcmalloc_INCLUDE_DIR AND EXISTS "${Tcmalloc_INCLUDE_DIR}/gperftools/tcmalloc.h")
+ foreach(ver "MAJOR" "MINOR" "PATCH")
+ file(STRINGS "${Tcmalloc_INCLUDE_DIR}/gperftools/tcmalloc.h" TC_VER_${ver}_LINE
+ REGEX "^#define[ \t]+TC_VERSION_${ver}[ \t]+[^ \t]+$")
+ string(REGEX REPLACE "^#define[ \t]+TC_VERSION_${ver}[ \t]+(\".)?([0-9]*)\"?$"
+ "\\2" TCMALLOC_VERSION_${ver} "${TC_VER_${ver}_LINE}")
+ unset(TC_VER_${ver}_LINE)
+ endforeach()
+ set(TCMALLOC_VERSION_STRING "${TCMALLOC_VERSION_MAJOR}.${TCMALLOC_VERSION_MINOR}")
+ if(NOT TCMALLOC_VERSION_PATCH STREQUAL "")
+ set(TCMALLOC_VERSION_STRING "${TCMALLOC_VERSION_STRING}.${TCMALLOC_VERSION_PATCH}")
+ endif()
+endif()
+
+foreach(component tcmalloc tcmalloc_minimal profiler)
+ string(TOUPPER ${component} COMPONENT)
+ find_library(GPERFTOOLS_${COMPONENT}_LIBRARY ${component}
+ HINTS $ENV{GPERF_ROOT}/lib)
+ 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
+ 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()