From 9d03e2966ab34d4931e07c7968d9974746436075 Mon Sep 17 00:00:00 2001 From: Gautham Prabhu Date: Sat, 27 Jun 2026 19:18:04 +0530 Subject: [PATCH] cmake: locate tcmalloc via gperftools header and library The Findtcmalloc module searched for the header `google/tcmalloc.h`, a path that gperftools deprecated over a decade ago. Current releases ship `gperftools/tcmalloc.h`, so on modern systems `find_path` failed and, because TCMALLOC_INCLUDE_DIR was a required argument to FIND_PACKAGE_HANDLE_STANDARD_ARGS, tcmalloc was reported as not found even when libtcmalloc was present and installable. BioDynaMo only links against tcmalloc (-ltcmalloc) and never includes its headers, so the include directory is not needed to build. This: - searches for `gperftools/tcmalloc.h` first, keeping `google/tcmalloc.h` as a fallback (used solely as a hint to locate the pprof binary), and - bases detection on the library alone, dropping TCMALLOC_INCLUDE_DIR from the required arguments. Verified against gperftools 2.18.1 (which ships only the gperftools/ header): the previous module reported TCMALLOC_FOUND=FALSE despite libtcmalloc.dylib being found, while the updated module reports TCMALLOC_FOUND=TRUE. Fixes #396 Co-Authored-By: Claude Opus 4.8 --- cmake/Findtcmalloc.cmake | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cmake/Findtcmalloc.cmake b/cmake/Findtcmalloc.cmake index 8633b494b..cbfff2e6c 100644 --- a/cmake/Findtcmalloc.cmake +++ b/cmake/Findtcmalloc.cmake @@ -12,7 +12,12 @@ # TCMALLOC_LIBRARY_DIRS (not cached) # PPROF_EXECUTABLE -find_path(TCMALLOC_INCLUDE_DIR google/tcmalloc.h) +# BioDynaMo only links against tcmalloc and never includes its headers, so the +# include directory is not required for the package to be considered found. We +# still try to locate a header to use as a hint for finding the pprof binary. +# Modern gperftools ships ; the legacy +# path has been deprecated for years but is kept as a fallback. +find_path(TCMALLOC_INCLUDE_DIR NAMES gperftools/tcmalloc.h google/tcmalloc.h) foreach(component tcmalloc profiler) find_library(TCMALLOC_${component}_LIBRARY NAMES ${component}) mark_as_advanced(TCMALLOC_${component}_LIBRARY) @@ -25,9 +30,10 @@ set(TCMALLOC_INCLUDE_DIRS ${TCMALLOC_INCLUDE_DIR}) set(TCMALLOC_LIBRARIES ${TCMALLOC_tcmalloc_LIBRARY} ${TCMALLOC_profiler_LIBRARY}) # handle the QUIETLY and REQUIRED arguments and set TCMALLOC_FOUND to TRUE if -# all listed variables are TRUE +# all listed variables are TRUE. Detection is based on the library alone, since +# the headers are not needed to build BioDynaMo. INCLUDE(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(tcmalloc DEFAULT_MSG TCMALLOC_INCLUDE_DIR TCMALLOC_LIBRARIES) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(tcmalloc DEFAULT_MSG TCMALLOC_LIBRARIES) mark_as_advanced(TCMALLOC_FOUND TCMALLOC_INCLUDE_DIR PPROF_EXECUTABLE)