Merge pull request #6102 from donn/homebrew_off

cmake: use homebrew from PATH
This commit is contained in:
Catherine 2026-08-10 20:16:55 +00:00 committed by GitHub
commit ff5817c34d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 4 deletions

View File

@ -171,7 +171,7 @@ if (MINGW AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSIO
endif()
# Required dependencies.
if (APPLE)
if (APPLE AND (NOT DEFINED YOSYS_ENABLE_HOMEBREW OR YOSYS_ENABLE_HOMEBREW))
# In practice, we can't expect paths to Homebrew packages to be configured.
use_homebrew()
endif()

View File

@ -2,13 +2,28 @@
#
# use_homebrew([ROOT <root>])
#
# Includes all packages installed in `<root>` (`/opt/homebrew/Cellar` if not specified)
# in `CMAKE_FIND_ROOT_PATH`.
# Includes all packages installed in `<root>` (output of brew --prefix if not
# specified) in `CMAKE_FIND_ROOT_PATH`.
#
function(use_homebrew)
cmake_parse_arguments(PARSE_ARGV 0 arg "" "ROOT" "")
if (NOT arg_ROOT)
set(arg_ROOT /opt/homebrew/Cellar)
execute_process(
COMMAND brew --prefix
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE brew_prefix_result
OUTPUT_VARIABLE brew_prefix_out
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
if (${brew_prefix_result} EQUAL 0)
set (arg_ROOT "${brew_prefix_out}/Cellar")
endif()
endif()
if (NOT arg_ROOT)
# unset and no brew binary available
return()
endif()
file(GLOB package_roots ${arg_ROOT}/*/*) # e.g. `/opt/homebrew/Cellar/bison/3.8.2/`