[GH-ISSUE #1039] Honour $HOMEBREW_PREFIX or brew --prefix openssl when looking for deps #824

Open
opened 2026-05-05 07:11:11 -06:00 by gitea-mirror · 1 comment
Owner

Originally created by @caitp on GitHub (Jan 27, 2021).
Original GitHub issue: https://github.com/debauchee/barrier/issues/1039

On a fresh installation of homebrew (specifically on an M1 Mac mini, though I doubt that's important), the link in /usr/local doesn't seem to be present anymore (resulting in linker errors during the build). I've gotten around this locally by editing CMakeLists.txt locally to honour ENV{HOMEBREW_PREFIX} (or point directly to /opt/homebrew, or any number of alternatives).

There's also the option of invoking brew --prefix <package> to figure out where to look.

A pretty quick fix:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index c56b30be..da91d359 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -320,6 +320,16 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
     find_program(BREW_PROGRAM "brew")
     find_program(PORT_PROGRAM "port")
 
+    if (NOT DEFINED ${HOMEBREW_PREFIX})
+        if (DEFINED ENV{HOMEBREW_PREFIX} AND IS_DIRECTORY ENV{HOMEBREW_PREFIX})
+            set(HOMEBREW_PREFIX ENV{HOMEBREW_PREFIX})
+        elseif(IS_DIRECTORY /opt/homebrew)
+            set(HOMEBREW_PREFIX /opt/homebrew)
+        else()
+            set(HOMEBREW_PREFIX /usr/local)
+        endif()
+    endif()
+
     if (IS_DIRECTORY /opt/local AND PORT_PROGRAM)
         # macports
         set (OPENSSL_ROOT /opt/local)
@@ -329,9 +339,9 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
             ${OPENSSL_ROOT}/lib/libcrypto.a
             z
         )
-    elseif (IS_DIRECTORY /usr/local/opt/openssl AND BREW_PROGRAM)
+    elseif (IS_DIRECTORY "${HOMEBREW_PREFIX}/opt/openssl" AND BREW_PROGRAM)
         # brew
-        set (OPENSSL_ROOT /usr/local/opt/openssl)
+        set (OPENSSL_ROOT ${HOMEBREW_PREFIX}/opt/openssl)
 
         include_directories (BEFORE SYSTEM ${OPENSSL_ROOT}/include)

It might be a nice idea to do that so that new homebrew installations are able to build

Originally created by @caitp on GitHub (Jan 27, 2021). Original GitHub issue: https://github.com/debauchee/barrier/issues/1039 On a fresh installation of homebrew (specifically on an M1 Mac mini, though I doubt that's important), the link in /usr/local doesn't seem to be present anymore (resulting in linker errors during the build). I've gotten around this locally by editing CMakeLists.txt locally to honour ENV{HOMEBREW_PREFIX} (or point directly to /opt/homebrew, or any number of alternatives). There's also the option of invoking `brew --prefix <package>` to figure out where to look. A pretty quick fix: ```diff diff --git a/CMakeLists.txt b/CMakeLists.txt index c56b30be..da91d359 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -320,6 +320,16 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") find_program(BREW_PROGRAM "brew") find_program(PORT_PROGRAM "port") + if (NOT DEFINED ${HOMEBREW_PREFIX}) + if (DEFINED ENV{HOMEBREW_PREFIX} AND IS_DIRECTORY ENV{HOMEBREW_PREFIX}) + set(HOMEBREW_PREFIX ENV{HOMEBREW_PREFIX}) + elseif(IS_DIRECTORY /opt/homebrew) + set(HOMEBREW_PREFIX /opt/homebrew) + else() + set(HOMEBREW_PREFIX /usr/local) + endif() + endif() + if (IS_DIRECTORY /opt/local AND PORT_PROGRAM) # macports set (OPENSSL_ROOT /opt/local) @@ -329,9 +339,9 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") ${OPENSSL_ROOT}/lib/libcrypto.a z ) - elseif (IS_DIRECTORY /usr/local/opt/openssl AND BREW_PROGRAM) + elseif (IS_DIRECTORY "${HOMEBREW_PREFIX}/opt/openssl" AND BREW_PROGRAM) # brew - set (OPENSSL_ROOT /usr/local/opt/openssl) + set (OPENSSL_ROOT ${HOMEBREW_PREFIX}/opt/openssl) include_directories (BEFORE SYSTEM ${OPENSSL_ROOT}/include) ``` It might be a nice idea to do that so that new homebrew installations are able to build
Author
Owner

@palkoc commented on GitHub (May 21, 2021):

Thanks @caitp , it helped me to build barrier on Macbook Air M1 macOS 11.2.3.

Pavol

<!-- gh-comment-id:846035719 --> @palkoc commented on GitHub (May 21, 2021): Thanks @caitp , it helped me to build barrier on Macbook Air M1 macOS 11.2.3. Pavol
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/barrier#824
No description provided.