Skip to content

cmake: locate tcmalloc via gperftools header and library#473

Open
GauthamPrabhuM wants to merge 1 commit into
BioDynaMo:masterfrom
GauthamPrabhuM:fix/tcmalloc-header-lookup
Open

cmake: locate tcmalloc via gperftools header and library#473
GauthamPrabhuM wants to merge 1 commit into
BioDynaMo:masterfrom
GauthamPrabhuM:fix/tcmalloc-header-lookup

Conversation

@GauthamPrabhuM

Copy link
Copy Markdown

Summary

Fixes #396.

cmake/Findtcmalloc.cmake located tcmalloc by searching for the header
google/tcmalloc.h — a path gperftools deprecated more than a decade ago.
Current gperftools releases ship gperftools/tcmalloc.h instead, so on modern
systems find_path failed. Because TCMALLOC_INCLUDE_DIR was a required
argument to FIND_PACKAGE_HANDLE_STANDARD_ARGS, tcmalloc was reported as not
found
even when libtcmalloc was installed and linkable.

As the issue reporter notes, BioDynaMo only links against tcmalloc
(-ltcmalloc) and never #includes its headers, so the include directory is
not needed to build at all.

Changes

  • Search for gperftools/tcmalloc.h first, keeping google/tcmalloc.h as a
    fallback. The header is now used only as a hint to locate the pprof
    binary, not as a hard requirement.
  • Drop TCMALLOC_INCLUDE_DIR from the required arguments of
    FIND_PACKAGE_HANDLE_STANDARD_ARGS, so detection is based on the library
    alone.

I confirmed TCMALLOC_INCLUDE_DIR / TCMALLOC_INCLUDE_DIRS are never consumed
by any compile/include path in the project (only TCMALLOC_FOUND and the
-ltcmalloc linker flags are used), so dropping the header requirement cannot
affect compilation.

Testing

Verified against gperftools 2.18.1, which ships only gperftools/tcmalloc.h
(no google/tcmalloc.h), using a minimal find_package(tcmalloc) harness:

Module Result
before Could NOT find tcmalloc (missing: TCMALLOC_INCLUDE_DIR)TCMALLOC_FOUND=FALSE (despite libtcmalloc.dylib being found)
after Found tcmalloc: .../libtcmalloc.dylib;.../libprofiler.dylibTCMALLOC_FOUND=TRUE

The change is confined to cmake/Findtcmalloc.cmake; tcmalloc is OFF by
default, so default builds are unaffected.

🤖 Generated with Claude Code

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 BioDynaMo#396

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Please stop locating tcmalloc headers via google/tcmalloc.h

1 participant