]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: detect gperf-tools' version
authorKefu Chai <kchai@redhat.com>
Tue, 19 Sep 2017 04:23:13 +0000 (12:23 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 19 Sep 2017 05:46:50 +0000 (13:46 +0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
cmake/modules/Findgperftools.cmake

index 17c9a71bce5179bf99de9509c7732a3b39b656b6..a06e4aac7c583953b677325c0c47933b5ac84d55 100644 (file)
@@ -7,12 +7,28 @@
 # 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}.${TCMALLOC_VERSION_PATCH}")
+endif()
+
 foreach(component tcmalloc tcmalloc_minimal profiler)
   string(TOUPPER ${component} COMPONENT)
   find_library(GPERFTOOLS_${COMPONENT}_LIBRARY ${component}
@@ -21,6 +37,8 @@ foreach(component tcmalloc tcmalloc_minimal profiler)
 endforeach()
 
 include(FindPackageHandleStandardArgs)
-find_package_handle_standard_args(gperftools DEFAULT_MSG GPERFTOOLS_LIBRARIES GPERFTOOLS_INCLUDE_DIR)
+find_package_handle_standard_args(gperftools
+  REQUIRED_VARS GPERFTOOLS_LIBRARIES GPERFTOOLS_INCLUDE_DIR
+  VERSION_VAR TCMALLOC_VERSION_STRING)
 
 mark_as_advanced(GPERFTOOLS_LIBRARIES GPERFTOOLS_INCLUDE_DIR)