From f5f930e18646fcc24160731b7b8dba1a639332bb Mon Sep 17 00:00:00 2001 From: Mohamed Gaber Date: Mon, 10 Aug 2026 17:40:54 +0300 Subject: [PATCH] cmake: use homebrew from PATH The current version of UseHomebrew defaults to /opt/homebrew/Cellar and prioritizes it over anything currently existing in PATH. This has two issues: - On x86_64 installations of Homebrew (including when emulating on ARM), the path is /usr/local/Cellar - When building in a `nix develop` environment, the homebrew versions take priority, complicating testing This addresses this issue by using the output of `brew --prefix`, doing nothing if brew is not in `PATH`. Additionally, CMakeLists.txt was updated such that if YOSYS_ENABLE_HOMEBREW is defined as OFF, using Homebrew is skipped entirely. --- CMakeLists.txt | 2 +- cmake/UseHomebrew.cmake | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3771394b2..f358655c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/cmake/UseHomebrew.cmake b/cmake/UseHomebrew.cmake index e94441109..92ceb7377 100644 --- a/cmake/UseHomebrew.cmake +++ b/cmake/UseHomebrew.cmake @@ -2,13 +2,28 @@ # # use_homebrew([ROOT ]) # -# Includes all packages installed in `` (`/opt/homebrew/Cellar` if not specified) -# in `CMAKE_FIND_ROOT_PATH`. +# Includes all packages installed in `` (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/`