fix: Add Homebrew Apple Silicon path detection in cmake finder modules#2474
Merged
an-tao merged 2 commits intodrogonframework:masterfrom Mar 27, 2026
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.cmakeFindBrotli.cmakeFindSQLite3.cmakeFindHiredis.cmakeFindpg.cmakeI 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 runsbrew --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.