From ed7e5656546a28873ebd4e15d1343bbc68dca31f Mon Sep 17 00:00:00 2001 From: Daniel Jones Date: Mon, 28 Oct 2024 17:11:44 +0000 Subject: [PATCH] macOS build fixes --- CMakeLists.txt | 51 +++++++++++-------- .../cibuildwheel/make-macos-x86-arm64.sh | 20 +++++--- docs/installation/{macos => }/easy.md | 0 3 files changed, 44 insertions(+), 27 deletions(-) rename docs/installation/{macos => }/easy.md (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 786cb4a2..76b75122 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,42 +4,47 @@ #------------------------------------------------------------------------------- cmake_minimum_required(VERSION 3.15.0) +#-------------------------------------------------------------------------------- +# Allow deployment on older versions of macOS (back to 10.14 Mojave), +# and default to the include/lib paths of the current Python virtualenv +# (important for cross-compiling wheels) +#-------------------------------------------------------------------------------- +set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Minimum macOS deployment version" FORCE) +set(Python_FIND_VIRTUALENV STANDARD) +set(Python_FIND_FRAMEWORKS LAST) + +#------------------------------------------------------------------------------- +# Note that project() call should come after set CMAKE_OSX_DEPLOYMENT_TARGET, +# but CMAKE_SYSTEM_NAME is only available *after* project(), so any platform- +# dependent code should come later on. +#------------------------------------------------------------------------------- +project(SignalFlow C CXX) +if (NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Develop) +endif() + if (CMAKE_SYSTEM_NAME STREQUAL "Darwin") #------------------------------------------------------------------------------- # On Apple, build the current native system by default #------------------------------------------------------------------------------- if (NOT CMAKE_OSX_ARCHITECTURES) execute_process(COMMAND uname -m - OUTPUT_VARIABLE CMAKE_OSX_ARCHITECTURES - OUTPUT_STRIP_TRAILING_WHITESPACE) + OUTPUT_VARIABLE CMAKE_OSX_ARCHITECTURES + OUTPUT_STRIP_TRAILING_WHITESPACE) endif() #------------------------------------------------------------------------------- - # Select the appropriate homebrew prefix by architecture + # Select the appropriate homebrew prefix by architecture. + # This is necessary so that the library is correctly linked against + # dependencies later on. #------------------------------------------------------------------------------- if (CMAKE_OSX_ARCHITECTURES STREQUAL "arm64") set(CMAKE_PREFIX_PATH /opt/homebrew) else() set(CMAKE_PREFIX_PATH /usr/local) endif() - - #-------------------------------------------------------------------------------- - # Allow deployment on older versions of macOS (back to 10.14 Mojave), - # and default to the include/lib paths of the current Python virtualenv - # (important for cross-compiling wheels) - #-------------------------------------------------------------------------------- - set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Minimum macOS deployment version" FORCE) - set(Python_FIND_VIRTUALENV STANDARD) - set(Python_FIND_FRAMEWORKS LAST) endif() -# project call should come after set CMAKE_OSX_DEPLOYMENT_TARGET -project(SignalFlow C CXX) -if (NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Develop) -endif() - - #-------------------------------------------------------------------------------- # Print config setup to help with debugging #-------------------------------------------------------------------------------- @@ -54,7 +59,9 @@ cmake_print_variables(CMAKE_PREFIX_PATH) set(CMAKE_CXX_STANDARD 11) set(CMAKE_MACOSX_RPATH 1) - +#------------------------------------------------------------------------------- +# Compiler flags for optimisations, warnings, etc. +#------------------------------------------------------------------------------- if (MSVC) #------------------------------------------------------------------------------- # Windows Visual C: Enable parallelisation @@ -81,7 +88,6 @@ else() endif() endif() - include_directories( /usr/local/include /opt/homebrew/include @@ -90,6 +96,9 @@ include_directories( source/lib/pybind11/include ) +#------------------------------------------------------------------------------- +# Compiler flags for debug vs release vs dev mode +#------------------------------------------------------------------------------- if (${CMAKE_BUILD_TYPE} STREQUAL "Debug") message("Building in debug mode") if (CMAKE_SYSTEM_NAME STREQUAL "Windows") diff --git a/auxiliary/cibuildwheel/make-macos-x86-arm64.sh b/auxiliary/cibuildwheel/make-macos-x86-arm64.sh index 1c1b4f55..b407b240 100755 --- a/auxiliary/cibuildwheel/make-macos-x86-arm64.sh +++ b/auxiliary/cibuildwheel/make-macos-x86-arm64.sh @@ -8,22 +8,30 @@ ROOT=auxiliary/cibuildwheel -for VERSION in 38 39 310 311 312 +for VERSION in 38 39 310 312 313 313 do rm -r build export CIBW_BUILD="cp${VERSION}-*" - export CIBW_BUILD_VERBOSITY=2 + export CIBW_BUILD_VERBOSITY=1 . $ROOT/venv-$VERSION/bin/activate - pip3 install cibuildwheel + pip3 install cibuildwheel delocate + + # For some reason, Python 3.13 seems to do additional validation on delocate which + # throws an exception when dependencies have a deployment target version set too high, + # and many of the dependencies on my build machine have a target of macOS 13 (Ventura). + # Need to verify whether the pre-3.13 builds are actually truly compatible with pre-Ventura! + if [ "$VERSION" == "313" ]; then + export MACOSX_DEPLOYMENT_TARGET=13.0 + fi #-------------------------------------------------------------------------------- - # Make x86 + # Make x86. #-------------------------------------------------------------------------------- export REPAIR_LIBRARY_PATH=/usr/local/lib export CIBW_ARCHS_MACOS="x86_64" export CMAKE_OSX_ARCHITECTURES=x86_64 - export CIBW_REPAIR_WHEEL_COMMAND_MACOS="DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-wheel --require-archs {delocate_archs} -w {dest_dir} -v {wheel}" + export CIBW_REPAIR_WHEEL_COMMAND_MACOS="DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-wheel -w {dest_dir} -v {wheel}" python3 -m cibuildwheel --output-dir wheelhouse --platform macos @@ -33,7 +41,7 @@ do export REPAIR_LIBRARY_PATH=/opt/homebrew/lib export CIBW_ARCHS_MACOS="arm64" export CMAKE_OSX_ARCHITECTURES=arm64 - export CIBW_REPAIR_WHEEL_COMMAND_MACOS="DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-wheel --require-archs {delocate_archs} -w {dest_dir} -v {wheel}" + export CIBW_REPAIR_WHEEL_COMMAND_MACOS="DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-wheel -w {dest_dir} -v {wheel}" python3 -m cibuildwheel --output-dir wheelhouse --platform macos done diff --git a/docs/installation/macos/easy.md b/docs/installation/easy.md similarity index 100% rename from docs/installation/macos/easy.md rename to docs/installation/easy.md