Skip to content

Commit

Permalink
Merge pull request #749 from ANTsX/fix_mac_wheel
Browse files Browse the repository at this point in the history
COMP: Set CMAKE_OSX_SYSROOT 

This allows ANTsPy to compile on Macs with different developer toolsets. Github runners have XCode, so hard-coded paths for the XCode Command Line Tools break the actions build.
  • Loading branch information
cookpa authored Feb 10, 2025
2 parents 4e279f0 + 08fcc14 commit 1aebfb3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
24 changes: 16 additions & 8 deletions .github/workflows/wheels_faster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,27 @@ jobs:

# Windows 64-bit
- os: windows-latest
python: '3.11'
cibw_python: 311
python: '3.12'
cibw_python: 312
platform_id: win_amd64

# Linux 64-bit
- os: ubuntu-latest
python: '3.11'
cibw_python: 311
python: '3.12'
cibw_python: 312
platform_id: manylinux_x86_64

# macOS on Intel 64-bit
- os: macos-13
python: '3.11'
cibw_python: 311
python: '3.12'
cibw_python: 312
arch: x86_64
platform_id: macosx_x86_64

# macOS on Apple M1 64-bit, supported for Python 3.10 and later
- os: macos-14
python: '3.11'
cibw_python: 311
python: '3.12'
cibw_python: 312
arch: arm64
platform_id: macosx_arm64

Expand Down Expand Up @@ -77,6 +77,14 @@ jobs:
run: |
macos_version=$(sw_vers -productVersion | awk -F '.' '{print $1".0"}')
echo "MACOSX_DEPLOYMENT_TARGET=${macos_version}" >> $GITHUB_ENV
echo -n "clang version : "
clang --version
echo -n "xcode version : "
xcode-select -p
echo -n "cmake version : "
cmake --version
echo -n "env : "
env
- name: Build wheels
env:
Expand Down
17 changes: 11 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ cmake_minimum_required(VERSION 3.16.3...3.26)

project(ants LANGUAGES CXX)

# Set the macOS SDK root
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
execute_process(
COMMAND xcrun --show-sdk-path
OUTPUT_VARIABLE SDK_PATH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(CMAKE_OSX_SYSROOT ${SDK_PATH})
message(STATUS "Using macOS SDK: ${CMAKE_OSX_SYSROOT}")
endif()

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# Try to import all Python components potentially needed by nanobind
Expand All @@ -25,12 +36,6 @@ set(ITK_DIR "./itkbuild")
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})

if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
include_directories(/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1)
set(ENV{PATH} "$ENV{PATH}:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1")
add_compile_options(-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1)
endif()

# ANTS
add_library(antsUtilities STATIC src/antscore/antsUtilities.cxx src/antscore/antsCommandLineOption.cxx src/antscore/antsCommandLineParser.cxx src/antscore/ReadWriteData.cxx src/antscore/ANTsVersion.cxx)
add_library(registrationUtilities STATIC src/antscore/antsRegistrationTemplateHeader.cxx
Expand Down
13 changes: 5 additions & 8 deletions scripts/configure_ITK.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,22 @@ cd ../
echo "Dependency;GitTag" > ./data/softwareVersions.csv
echo "ITK;${itktag}" >> ./data/softwareVersions.csv

# if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
# include_directories(/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1)
## set(ENV{PATH} "$ENV{PATH}:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1")
# add_compile_options(-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1)
# endif()

mkdir -p itkbuild
cd itkbuild
compflags=" -Wno-c++11-long-long -fPIC -O2 -DNDEBUG "
osx_sysroot=""

if [[ `uname` == 'Darwin' ]] ; then
compflags=" -Wno-c++11-long-long -fPIC -O2 -DNDEBUG -isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1 -stdlib=libc++ "
osx_sysroot=$(xcrun --sdk macosx --show-sdk-path)
fi

cmake \
-G"${ADD_G}" \
-DITK_USE_SYSTEM_PNG=ON \
-DCMAKE_SH:BOOL=OFF \
-DCMAKE_BUILD_TYPE:STRING="${CMAKE_BUILD_TYPE}" \
-DCMAKE_C_FLAGS="${CMAKE_C_FLAGS} -Wno-c++11-long-long -fPIC -O2 -DNDEBUG "\
-DCMAKE_OSX_SYSROOT="${osx_sysroot}" \
-DCMAKE_C_FLAGS="${CMAKE_C_FLAGS} ${compflags}"\
-DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS} ${compflags} "\
-DITK_USE_GIT_PROTOCOL:BOOL=OFF \
-DBUILD_SHARED_LIBS:BOOL=OFF \
Expand Down

0 comments on commit 1aebfb3

Please sign in to comment.