Skip to content

forward ccache to cmake via CMAKE_<LANG>_COMPILER_LAUNCHER - #267

Merged
kevinushey merged 1 commit into
masterfrom
bugfix/ccache-compiler-launcher
Jul 27, 2026
Merged

forward ccache to cmake via CMAKE_<LANG>_COMPILER_LAUNCHER#267
kevinushey merged 1 commit into
masterfrom
bugfix/ccache-compiler-launcher

Conversation

@kevinushey

Copy link
Copy Markdown
Contributor

Problem

When R is configured with a compiler launcher baked into CXX (or CC) -- e.g. CXX = "ccache g++" -- building the bundled oneTBB fails during cmake configuration with:

CMake Error at cmake/compilers/GNU.cmake:65 (math):
  math cannot parse the expression: "/usr/bin/ccache: invalid option -- 'W' *
  1000 + /usr/bin/ccache: invalid option -- 'W'": syntax error, ...

Root cause

splitCompilerVar() in src/install.libs.R treats the first token of CXX as the compiler, so CXX = "ccache g++" was forwarded to cmake as CMAKE_CXX_COMPILER=ccache with g++ demoted into CMAKE_CXX_FLAGS. oneTBB's GNU.cmake then probes the assembler with ${CMAKE_CXX_COMPILER} ... -Wa,-v, i.e. ccache ... -Wa,-v. ccache rejects -W (invalid option -- 'W'), the version regex fails to match, and the leftover error text is fed to cmake's math(), which aborts the build.

Fix

CMake models compiler launchers via the dedicated CMAKE_<LANG>_COMPILER_LAUNCHER variable, not as part of the compiler command. This PR adds extractCompilerLauncher(), which pulls a leading ccache/sccache launcher (path- and .exe-tolerant) out of CC/CXX before splitting, and forwards it via -DCMAKE_C_COMPILER_LAUNCHER= / -DCMAKE_CXX_COMPILER_LAUNCHER=. The real compiler is left in place, so cmake's compiler/assembler probes run against it as intended, while ccache still wraps the actual compilation.

Tests

Adds cases to tests/test-install-libs.R covering launcher extraction (ccache, path-qualified ccache with trailing flags, sccache), and the no-op paths (plain compiler, unset variable).

When CXX/CC is configured with a leading compiler launcher (e.g.
CXX='ccache g++'), splitCompilerVar treated 'ccache' as the compiler
and demoted the real compiler to a flag. CMake then ran the launcher
directly during its assembler probe (ccache ... -Wa,-v), which ccache
rejects with 'invalid option -- W', aborting the oneTBB build.

Extract a leading ccache/sccache launcher from CC/CXX and forward it
via CMAKE_<LANG>_COMPILER_LAUNCHER, the variable CMake provides for
exactly this purpose.
@kevinushey
kevinushey merged commit a3c7cd7 into master Jul 27, 2026
5 checks passed
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.

1 participant