Skip to content

cmake: make ccache opt-in when Tracy is consumed as a subdirectory dependency#1413

Open
blozano-tt wants to merge 1 commit into
wolfpld:masterfrom
blozano-tt:fix/ccache-opt-in-when-subdirectory
Open

cmake: make ccache opt-in when Tracy is consumed as a subdirectory dependency#1413
blozano-tt wants to merge 1 commit into
wolfpld:masterfrom
blozano-tt:fix/ccache-opt-in-when-subdirectory

Conversation

@blozano-tt

Copy link
Copy Markdown

Problem

cmake/config.cmake sets the global CMake property RULE_LAUNCH_COMPILE ccache whenever ccache is found and NO_CCACHE is off (the default). This is appropriate when building Tracy directly, but when Tracy is consumed as a subdirectory dependency via add_subdirectory(), the global property leaks into the parent build.

If the parent project already manages ccache — for example via CMAKE_CXX_COMPILER_LAUNCHER — both mechanisms activate at the same time. CMake then generates Ninja rules that double-wrap the compiler:

```
ccache cmake -E env CCACHE_SLOPPINESS=... ccache clang++ -c foo.cpp
```

The outer ccache invocation sees cmake (not clang++) as the compiler and rejects every translation unit with "Multiple source files".

Real-world impact: after integrating Tracy into tenstorrent/tt-metal, 1856 of 2248 compilations became uncacheable (82.6% miss rate). The project was forced to work around it with set(NO_CCACHE ON) before the Tracy add_subdirectory calls (tenstorrent/tt-metal#47617). This fix addresses the root cause upstream.

Fix

Detect whether Tracy is the top-level CMake project at configure time:

  • Top-level: NO_CCACHE defaults to OFF — ccache enabled, existing behavior preserved for Tracy CLI users building Tracy directly.
  • Subdirectory dependency: NO_CCACHE defaults to ON — the global RULE_LAUNCH_COMPILE property is not set, preventing leakage into the parent build. Parent projects that explicitly want Tracy's ccache can still pass -DNO_CCACHE=OFF.

This makes ccache opt-in when Tracy is used as a dependency, matching the principle of least surprise for CMake consumers.

Testing

Build Tracy CLI tools directly — behaviour unchanged (ccache still active by default).

Consume Tracy as a subdirectory in a project that sets CMAKE_CXX_COMPILER_LAUNCHER=ccache — no more double-wrapping; the parent's ccache operates correctly.

Tracy's config.cmake sets RULE_LAUNCH_COMPILE ccache as a GLOBAL CMake
property. When Tracy is consumed via add_subdirectory() by a parent project
that already manages ccache (e.g. via CMAKE_CXX_COMPILER_LAUNCHER), both
mechanisms activate simultaneously. The compiler gets double-wrapped:

    ccache cmake -E env CCACHE_SLOPPINESS=... ccache clang++ -c foo.cpp

The outer ccache sees 'cmake' as the compiler and rejects every translation
unit as 'Multiple source files'. This caused 82.6% cache-miss rate in
tenstorrent/tt-metal after Tracy was integrated as a subdirectory dependency
(1856/2248 compilations uncacheable). See:
tenstorrent/tt-metal#47617

Fix: detect whether Tracy is the top-level project at configure time. If it
is, NO_CCACHE defaults to OFF (existing behavior, ccache enabled). If it is
a subdirectory, NO_CCACHE defaults to ON, suppressing the global property.
Parent projects that explicitly want Tracy's ccache can still set
-DNO_CCACHE=OFF; the override semantics of set_option are unchanged.

This makes the ccache integration opt-in when Tracy is used as a
dependency, matching the principle of least surprise for CMake consumers.
@wolfpld

wolfpld commented Jun 22, 2026

Copy link
Copy Markdown
Owner

Why are you trying to build Tracy tools as a part of some external project?

@mo-tenstorrent

Copy link
Copy Markdown

We use them to systematically capture and export tracy runs. Single build builds them all. If they have tracy enabled they are going to need the tools as well.

@wolfpld

wolfpld commented Jun 22, 2026

Copy link
Copy Markdown
Owner

I don't think adapting to any possible external build configuration is what I want to do (except for the client, of course).

https://cmake.org/cmake/help/latest/module/ExternalProject.html is probably the solution you're looking for.

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.

3 participants