Skip to content

fix: Add Homebrew Apple Silicon path detection in cmake finder modules#2474

Merged
an-tao merged 2 commits intodrogonframework:masterfrom
archanasondur:fix/apple-silicon-homebrew-cmake-paths
Mar 27, 2026
Merged

fix: Add Homebrew Apple Silicon path detection in cmake finder modules#2474
an-tao merged 2 commits intodrogonframework:masterfrom
archanasondur:fix/apple-silicon-homebrew-cmake-paths

Conversation

@archanasondur
Copy link
Copy Markdown
Contributor

Issue

On Apple Silicon Macs (M1/M2/M3), Homebrew installs packages to /opt/homebrew/ instead of /usr/local/ which is where Intel Macs install them. The cmake finder modules were only searching the default paths which on Mac point to Intel Homebrew locations. This caused build failures on Apple Silicon with errors like:

fatal error: 'json/json.h' file not found
Could NOT find BROTLI

This issue was reported in #2413 but was never resolved.

What I Found

While trying to build Drogon on a MacBook Air M3, I noticed the cmake finder modules in cmake_modules/ had no Apple Silicon path detection. The affected files were:

  • FindJsoncpp.cmake
  • FindBrotli.cmake
  • FindSQLite3.cmake
  • FindHiredis.cmake
  • Findpg.cmake

I also looked into the history and found that PR #1345 tried to fix the Homebrew OpenSSL path but was closed after PR #1505 made OpenSSL optional. However the underlying cmake path problem for other dependencies was never addressed.

Fix

I added an if(APPLE) block in each finder module that runs brew --prefix <package> to dynamically detect the Homebrew installation path. This works automatically on both Intel and Apple Silicon Macs without requiring any manual cmake flags from the user.

Testing

Tested on MacBook Air M3 running macOS with Apple Silicon.

Before this fix the build required manual flags:
cmake .. -DBUILD_EXAMPLES=ON -DCMAKE_PREFIX_PATH="/usr/local;/opt/homebrew" -DOPENSSL_ROOT_DIR=$(brew --prefix openssl)

After this fix it works with just:
cmake .. -DBUILD_EXAMPLES=ON

cmake output confirms automatic detection:
-- Found Jsoncpp: /opt/homebrew/opt/jsoncpp/include
-- Found Brotli: /opt/homebrew/opt/brotli/lib/libbrotlidec.dylib

Closes #2413

Note: clang-format was not applied as the changes are only in cmake finder modules, not C++ source files.

On Apple Silicon Macs, Homebrew installs packages to /opt/homebrew
instead of /usr/local (Intel Macs). The cmake finder modules were only
searching Intel paths, causing build failures on Apple Silicon.

This fix detects the Homebrew prefix dynamically using brew --prefix
for each dependency, making builds work automatically on both Intel
and Apple Silicon Macs without any manual cmake flags.

Fixes drogonframework#2413
@an-tao an-tao merged commit cd7efef into drogonframework:master Mar 27, 2026
34 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.

Unable to make on Mac OS X

2 participants