Skip to content

Commit cd7efef

Browse files
fix: Add Homebrew Apple Silicon path detection in cmake finder modules (#2474)
1 parent 182c862 commit cd7efef

6 files changed

Lines changed: 77 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ CMakeSettings.json
4747
install
4848
trace.json
4949
.cache/
50+
build_examples/

cmake_modules/FindBrotli.cmake

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,21 @@
2121
# ##############################################################################
2222
include(FindPackageHandleStandardArgs)
2323

24+
# On Apple Silicon Macs, Homebrew installs to /opt/homebrew instead of
25+
# /usr/local (Intel Macs). Detect the prefix dynamically so cmake finds
26+
# dependencies regardless of Mac architecture.
27+
if(APPLE)
28+
execute_process(
29+
COMMAND brew --prefix brotli
30+
OUTPUT_VARIABLE HOMEBREW_BROTLI_PREFIX
31+
OUTPUT_STRIP_TRAILING_WHITESPACE
32+
ERROR_QUIET
33+
)
34+
if(HOMEBREW_BROTLI_PREFIX)
35+
list(APPEND CMAKE_PREFIX_PATH ${HOMEBREW_BROTLI_PREFIX})
36+
endif()
37+
endif()
38+
2439
find_path(BROTLI_INCLUDE_DIR "brotli/decode.h")
2540

2641
find_library(BROTLICOMMON_LIBRARY NAMES brotlicommon brotlicommon-static)

cmake_modules/FindHiredis.cmake

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@
55
# HIREDIS_INCLUDE_DIRS - hiredis include directories
66
# HIREDIS_LIBRARIES - libraries need to use hiredis
77

8+
# On Apple Silicon Macs, Homebrew installs to /opt/homebrew instead of
9+
# /usr/local (Intel Macs). Detect the prefix dynamically so cmake finds
10+
# dependencies regardless of Mac architecture.
11+
if(APPLE)
12+
execute_process(
13+
COMMAND brew --prefix hiredis
14+
OUTPUT_VARIABLE HOMEBREW_HIREDIS_PREFIX
15+
OUTPUT_STRIP_TRAILING_WHITESPACE
16+
ERROR_QUIET
17+
)
18+
if(HOMEBREW_HIREDIS_PREFIX)
19+
list(APPEND CMAKE_PREFIX_PATH ${HOMEBREW_HIREDIS_PREFIX})
20+
endif()
21+
endif()
22+
823
if (HIREDIS_INCLUDE_DIRS AND HIREDIS_LIBRARIES)
924
set(HIREDIS_FIND_QUIETLY TRUE)
1025
set(Hiredis_FOUND TRUE)

cmake_modules/FindJsoncpp.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,22 @@
1010
# false, do not try to use jsoncpp.
1111
# Jsoncpp_lib - The imported target library.
1212

13+
# On Apple Silicon Macs, Homebrew installs to /opt/homebrew instead of
14+
# /usr/local (Intel Macs). Detect the prefix dynamically so cmake finds
15+
# dependencies regardless of Mac architecture.
16+
if(APPLE)
17+
execute_process(
18+
COMMAND brew --prefix jsoncpp
19+
OUTPUT_VARIABLE HOMEBREW_JSONCPP_PREFIX
20+
OUTPUT_STRIP_TRAILING_WHITESPACE
21+
ERROR_QUIET
22+
)
23+
if(HOMEBREW_JSONCPP_PREFIX)
24+
list(APPEND CMAKE_PREFIX_PATH ${HOMEBREW_JSONCPP_PREFIX})
25+
endif()
26+
endif()
27+
28+
1329
# only look in default directories
1430
find_path(JSONCPP_INCLUDE_DIRS
1531
NAMES json/json.h

cmake_modules/FindSQLite3.cmake

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@
1313
# SQLite3_FOUND - True if sqlite3 found.
1414
# SQLite3_lib - The imported target library.
1515

16+
# On Apple Silicon Macs, Homebrew installs to /opt/homebrew instead of
17+
# /usr/local (Intel Macs). Detect the prefix dynamically so cmake finds
18+
# dependencies regardless of Mac architecture.
19+
if(APPLE)
20+
execute_process(
21+
COMMAND brew --prefix sqlite3
22+
OUTPUT_VARIABLE HOMEBREW_SQLITE3_PREFIX
23+
OUTPUT_STRIP_TRAILING_WHITESPACE
24+
ERROR_QUIET
25+
)
26+
if(HOMEBREW_SQLITE3_PREFIX)
27+
list(APPEND CMAKE_PREFIX_PATH ${HOMEBREW_SQLITE3_PREFIX})
28+
endif()
29+
endif()
30+
1631
# Look for the header file.
1732
find_path(SQLITE3_INCLUDE_DIRS NAMES sqlite3.h)
1833

cmake_modules/Findpg.cmake

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,21 @@
77
# PostgreSQL.
88
# pg_lib - The imported target library.
99

10+
# On Apple Silicon Macs, Homebrew installs to /opt/homebrew instead of
11+
# /usr/local (Intel Macs). Detect the prefix dynamically so cmake finds
12+
# dependencies regardless of Mac architecture.
13+
if(APPLE)
14+
execute_process(
15+
COMMAND brew --prefix libpq
16+
OUTPUT_VARIABLE HOMEBREW_PG_PREFIX
17+
OUTPUT_STRIP_TRAILING_WHITESPACE
18+
ERROR_QUIET
19+
)
20+
if(HOMEBREW_PG_PREFIX)
21+
list(APPEND CMAKE_PREFIX_PATH ${HOMEBREW_PG_PREFIX})
22+
endif()
23+
endif()
24+
1025
find_package(PostgreSQL)
1126
if(PostgreSQL_FOUND)
1227
set(PG_LIBRARIES ${PostgreSQL_LIBRARIES})

0 commit comments

Comments
 (0)