Skip to content

Add CCACHE_FOUND=OFF to default CMake flags#22902

Merged
MikeMcQuaid merged 1 commit into
Homebrew:mainfrom
matteosecli:patch-1
Jul 4, 2026
Merged

Add CCACHE_FOUND=OFF to default CMake flags#22902
MikeMcQuaid merged 1 commit into
Homebrew:mainfrom
matteosecli:patch-1

Conversation

@matteosecli

Copy link
Copy Markdown
Contributor

  • Have you followed our Contributing guidelines?
  • Have you checked for other open Pull Requests for the same change?
  • Have you explained what your changes do? Performance claims (e.g. "this is faster") must include Hyperfine benchmarks.
  • Have you explained why you'd like these changes included, not just what they do?
  • For bug fixes, have you given step-by-step brew commands to reproduce the bug?
  • Have you written new tests (excluding integration tests)? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) locally?

  • AI was used to generate or assist with generating this PR.

As discussed with @SMillerDev in https://github.com/orgs/Homebrew/discussions/6920, some formulae fail to build if ccache is installed. Simple example:

docker run --rm -it ghcr.io/homebrew/ubuntu24.04:main \
bash -lc 'brew install --yes ccache && brew install --yes --build-from-source ada-url'

This is due to the fact that ccache integration in several formulae is typically handled as e.g.:

find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
  message(STATUS "Ccache found: using it as compiler launcher.")
  set(CMAKE_C_COMPILER_LAUNCHER ccache)
  set(CMAKE_CXX_COMPILER_LAUNCHER ccache)
endif()

instead of e.g.:

find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
  message(STATUS "Using ccache: ${CCACHE_FOUND}")
  set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_FOUND})
  set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_FOUND})
endif()

So, if ccache is not on $PATH, the build will fail.

This is certainly an upstream problem. However, as a matter of fact, it currently affects at least 20 Homebrew formulae (minimum, these are just the ones I could find): ada-url, apache-arrow, cppinsights, exiv2, kingfisher, libff, librealsense, libwbxml, lief, merve, musikcube, osrm-backend, ppsspp, rapidjson, rocksdb, rtags, taglib, tdlib, vectorscan, yalantinglibs.

As the CMake snippets above seem to be a fairly standard approach even for formulae not currently packaged by Homebrew, as it can be quickly verified by a code search, this PR proposes to add -DCCACHE_FOUND=OFF to the standard CMake flags. For the same formula as before, this will now work if using the proposed additional flag:

docker run --rm -it ghcr.io/homebrew/ubuntu24.04:main \
bash -lc 'set -euo pipefail; export HOMEBREW_NO_AUTO_UPDATE=1; curl -fsSL https://raw.githubusercontent.com/matteosecli/brew/344b6d838de7caf9457c4c58db879b8481d929b8/Library/Homebrew/formula.rb > "$(brew --repository)/Library/Homebrew/formula.rb"; brew install --yes ccache && brew install --yes --build-from-source ada-url'

Adding this flag will also be beneficial if other formulae, in the future, decide to include the same CMake snippet or to enable ccache discovery by default in their CMake files, or if newer CI build images will happen to ship with ccache preinstalled.

Copilot AI review requested due to automatic review settings June 28, 2026 22:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Homebrew’s shared std_cmake_args (used by formulae that invoke CMake) to explicitly disable projects’ ad-hoc ccache detection via a commonly used find_program(CCACHE_FOUND ccache) pattern, avoiding build failures when ccache is discoverable at configure-time but not reliably invokable at build-time.

Changes:

  • Add -DCCACHE_FOUND=OFF to the default CMake arguments returned by Formula#std_cmake_args.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@carlocab carlocab left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not opposed to this, but I am slightly hesitant because it only affects local source builds.

Does doing brew unlink ccache not prevent cmake from finding your ccache installation when building from source?

@matteosecli

Copy link
Copy Markdown
Contributor Author

Hi @carlocab, thanks for taking a look.

Does doing brew unlink ccache not prevent cmake from finding your ccache installation when building from source?

Yes, unlinking ccache does avoid this specific failure when ccache was installed by Homebrew.

However, I don’t think that is an ideal solution from a user’s point of view: if ccache happens to be installed, I would still expect brew install --build-from-source <formula> to work without having to know that I first need to unlink another formula.

It also only fixes the Homebrew-installed ccache case. If ccache comes from outside Homebrew, CMake can still find it and use it. For example, this succeeds:

docker run --rm -it ghcr.io/homebrew/ubuntu24.04:main \
bash -lc 'sudo apt update && sudo apt install --yes ccache && brew install --yes --build-from-source --verbose ada-url'

However, it succeeds because /usr/bin/ccache is on the system PATH: CMake finds it, and the verbose build shows compilation going through ccache. That still seems contrary to Homebrew’s own best practices: brew builds are not meant to rely on ccache, since it can prevent some software from compiling.

The proposed change makes the default behavior consistent: Homebrew CMake builds should not accidentally discover and use ccache just because it happens to be installed somewhere.

@MikeMcQuaid MikeMcQuaid left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me, thanks!

@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue Jul 4, 2026
Merged via the queue into Homebrew:main with commit 8abeca7 Jul 4, 2026
41 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.

4 participants