debauchee / barrier

Open-source KVM software
Other
27.72k stars 1.52k forks source link

Honour $HOMEBREW_PREFIX or brew --prefix openssl when looking for deps #1039

Open caitp opened 3 years ago

caitp commented 3 years ago

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

palkoc commented 3 years ago

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

Pavol