Skip to content

Commit

Permalink
macOS build fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ideoforms committed Oct 28, 2024
1 parent 7474168 commit ed7e565
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 27 deletions.
51 changes: 30 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
#--------------------------------------------------------------------------------
Expand All @@ -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
Expand All @@ -81,7 +88,6 @@ else()
endif()
endif()


include_directories(
/usr/local/include
/opt/homebrew/include
Expand All @@ -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")
Expand Down
20 changes: 14 additions & 6 deletions auxiliary/cibuildwheel/make-macos-x86-arm64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
File renamed without changes.

0 comments on commit ed7e565

Please sign in to comment.