From 2adb53e0acc20e87c9d6d6017dc5e9fee99d6599 Mon Sep 17 00:00:00 2001 From: Matias Zwinger Date: Mon, 19 Aug 2024 14:12:21 +0300 Subject: [PATCH] Don't search for package managers if Nix is found 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. --- CMakeLists.txt | 63 +++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 33a7f54ebc..719710877d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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")