Skip to content

Commit

Permalink
Don't search for package managers if Nix is found
Browse files Browse the repository at this point in the history
On Darwin Nix builds will fail if either one of homebrew or macports is
not present. This commit adds a check which skips searching for
additional package managers if Elmer is being built in the Nix sandbox.
  • Loading branch information
mk3z committed Aug 19, 2024
1 parent 2b512e3 commit 2adb53e
Showing 1 changed file with 34 additions and 29 deletions.
63 changes: 34 additions & 29 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,41 @@ ENDIF()
# For building on OS X
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

# If the user doesn't tell us which package manager they're using
if(NOT DEFINED MACPORTS_PREFIX AND NOT DEFINED HOMEBREW_PREFIX)

# Try to find MacPorts path
find_program(MACPORTS_EXECUTABLE port)
if(EXISTS ${MACPORTS_EXECUTABLE})
string(REPLACE "/bin/port" ""
MACPORTS_PREFIX ${MACPORTS_EXECUTABLE})
message(STATUS "Detected MacPorts install at ${MACPORTS_PREFIX}")
endif(EXISTS ${MACPORTS_EXECUTABLE})

# Try to find Homebrew path
find_program(HOMEBREW_EXECUTABLE brew)
if(EXISTS ${HOMEBREW_EXECUTABLE})
string(REPLACE "/bin/brew" ""
HOMEBREW_PREFIX ${HOMEBREW_EXECUTABLE})
message(STATUS "Detected Homebrew install at ${HOMEBREW_PREFIX}")
# If Elmer is being built on Nix, all other checks can be skipped
if(DEFINED NIX_STORE)
message(STATUS "Detected Nix sandbox environment")
else()
# If the user doesn't tell us which package manager they're using
if(NOT DEFINED MACPORTS_PREFIX AND NOT DEFINED HOMEBREW_PREFIX)

# Try to find MacPorts path
find_program(MACPORTS_EXECUTABLE port)
if(EXISTS ${MACPORTS_EXECUTABLE})
string(REPLACE "/bin/port" ""
MACPORTS_PREFIX ${MACPORTS_EXECUTABLE})
message(STATUS "Detected MacPorts install at ${MACPORTS_PREFIX}")
endif(EXISTS ${MACPORTS_EXECUTABLE})

# Try to find Homebrew path
find_program(HOMEBREW_EXECUTABLE brew)
if(EXISTS ${HOMEBREW_EXECUTABLE})
string(REPLACE "/bin/brew" ""
HOMEBREW_PREFIX ${HOMEBREW_EXECUTABLE})
message(STATUS "Detected Homebrew install at ${HOMEBREW_PREFIX}")
endif()

endif(NOT DEFINED MACPORTS_PREFIX AND NOT DEFINED HOMEBREW_PREFIX)

# In case someone tries to shoot themselves in the foot
if(DEFINED MACPORTS_PREFIX AND DEFINED HOMEBREW_PREFIX)
message(SEND_ERROR "Multiple package management systems detected - ")
message(SEND_ERROR "define either MACPORTS_PREFIX or HOMEBREW_PREFIX")

# No package manager
elseif(NOT DEFINED MACPORTS_PREFIX AND NOT DEFINED HOMEBREW_PREFIX)
message(SEND_ERROR "No package manager detected - install MacPorts or Homebrew")
endif()

endif(NOT DEFINED MACPORTS_PREFIX AND NOT DEFINED HOMEBREW_PREFIX)

# In case someone tries to shoot themselves in the foot
if(DEFINED MACPORTS_PREFIX AND DEFINED HOMEBREW_PREFIX)
message(SEND_ERROR "Multiple package management systems detected - ")
message(SEND_ERROR "define either MACPORTS_PREFIX or HOMEBREW_PREFIX")

# No package manager
elseif(NOT DEFINED MACPORTS_PREFIX AND NOT DEFINED HOMEBREW_PREFIX)
message(SEND_ERROR "No package manager detected - install MacPorts or Homebrew")
endif()
endif(DEFINED NIX_STORE)
endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")


Expand Down

0 comments on commit 2adb53e

Please sign in to comment.