Skip to content

build: Fix issues when looking for libraries installed with homebrew

Backport of D7441

This diff fixes a few issues with the current usage of the brew prefix:

  • The brew prefix is added to the search path for the libraries files as HINTS, which cause it to be searched before system libraries. However this path does not follow the same rule as the other paths, as the include or lib subdirectories are not traversed. These suffixes needs to be added manually for the search to succeed.
  • The find_brew_prefix() function checks if the variable name is defined to prevent calling brew multiple times. The find package modules all use the same BREW_HINT variable name, which can cause shadowing issues if they are called from the same scope (which happens).
  • There is a copy/paste issue in the FindEvent package which looks for the wrong prefix.

These bugs have been revealed as some brew packages (namely Berkeley DB) stopped putting symlinks to the standard system path, and caused the macOS build to fail.

Test Plan

Install latest version of BerkleyDB available in brew on OS X. Observe it doesn't work without this patch. Without this patch, the following error occurs:

-- Found BerkeleyDB component CXX: /usr/local/lib/libdb_cxx.dylib
CMake Error at /usr/local/Cellar/cmake/3.19.1/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:218 (message):
  Could NOT find BerkeleyDB: Found unsuitable version "/*-

<.. long header file ..>

  ", but required is at least "5.3" (found
  /Library/Developer/CommandLineTools/SDKs/MacOSX11.0.sdk/usr/include, found
  components: CXX)
Call Stack (most recent call first):
  /usr/local/Cellar/cmake/3.19.1/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:575 (_FPHSA_FAILURE_MESSAGE)
  cmake/modules/FindBerkeleyDB.cmake:161 (find_package_handle_standard_args)
  src/wallet/CMakeLists.txt:6 (find_package)

Differential Revision: https://reviews.bitcoinabc.org/D7441

Merge request reports