Skip to content
Snippets Groups Projects
Unverified Commit 977c5d95 authored by Tim Kaune's avatar Tim Kaune
Browse files

Fix matching of MacOS system and SDK versions

A newer XCode SDK on an older system can lead to a mismatch between the
text-based .dylib stubs and the actual Accelerate binary, leading to
linking errors.

Improve diagnostic output
Add linking to Accelerate to the CMAKE_{EXE|SHARED}_LINKER_FLAGS
parent 3fde0fc9
Branches
No related tags found
No related merge requests found
...@@ -25,7 +25,7 @@ SOFTWARE. ...@@ -25,7 +25,7 @@ SOFTWARE.
cmake_minimum_required(VERSION 3.12) cmake_minimum_required(VERSION 3.12)
set(CMAKE_MAXIMUM_SUPPORTED_VERSION 3.29) set(CMAKE_MAXIMUM_SUPPORTED_VERSION 3.30)
include("./cmake/HandlePolicies.cmake" NO_POLICY_SCOPE) include("./cmake/HandlePolicies.cmake" NO_POLICY_SCOPE)
...@@ -40,17 +40,67 @@ if (NOT IS_TOP_LEVEL) ...@@ -40,17 +40,67 @@ if (NOT IS_TOP_LEVEL)
endif () endif ()
if (CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin") if (CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
# The available binary Accelerate version is determined by the MacOS system
message(STATUS "The Darwin kernel version is: ${CMAKE_HOST_SYSTEM_VERSION}")
# Mac OS X 15.0 Sequoia # Mac OS X 15.0 Sequoia
if (CMAKE_HOST_SYSTEM_VERSION VERSION_GREATER_EQUAL 24.0) if (CMAKE_HOST_SYSTEM_VERSION VERSION_GREATER_EQUAL 24.0)
message(STATUS "The MacOS version is: >=15.0")
set(MINIMUM_MACOS_SDK_VERSION 15.0)
set(ACCELERATE_NEW_LAPACK_VERSION 3.11.0) set(ACCELERATE_NEW_LAPACK_VERSION 3.11.0)
# Mac OS X 13.3 Ventura # Mac OS X 13.3 Ventura
elseif (CMAKE_HOST_SYSTEM_VERSION VERSION_GREATER_EQUAL 22.4) elseif (CMAKE_HOST_SYSTEM_VERSION VERSION_GREATER_EQUAL 22.4)
message(STATUS "The MacOS version is: >=13.3,<15.0")
set(MINIMUM_MACOS_SDK_VERSION 13.3)
set(VALID_MACOS_SDK_VERSIONS 14.5 14.4 14.2 14.0 13.3)
set(ACCELERATE_NEW_LAPACK_VERSION 3.9.1) set(ACCELERATE_NEW_LAPACK_VERSION 3.9.1)
else () else ()
message(FATAL_ERROR "You need at least Mac OS X 13.3 Ventura for Accelerate with BLAS/LAPACK v3.9.1!") message(FATAL_ERROR "You need at least MacOS 13.3 Ventura for Accelerate with BLAS/LAPACK v3.9.1!")
endif ()
endif ()
string(REGEX MATCH [=[SDKs/MacOSX(.*)\.sdk$]=] _REGEX_DUMMY "${CMAKE_OSX_SYSROOT}")
set(DEFAULT_MACOS_SDK_VERSION "${CMAKE_MATCH_1}")
# The text-based .dylib stubs describing the Accelerate framework are provided
# by the MacOS SDK, which has to match the MacOS system. Otherwise, there might
# be newer symbols in the text-based .dylib stubs that are not provided by the
# Accelerate binary, leading to linking errors.
if (NOT DEFINED VALID_MACOS_SDK_VERSIONS)
# MacOS system supports the latest iteration of the new Accelerate
# BLAS/LAPACK. Use the default SDK, if it's recent enough.
if (DEFAULT_MACOS_SDK_VERSION VERSION_LESS MINIMUM_MACOS_SDK_VERSION)
message(STATUS "The MacOS SDK is: ${CMAKE_OSX_SYSROOT}")
message(STATUS "The minimum compatible MacOS SDK version is: ${MINIMUM_MACOS_SDK_VERSION}")
message(FATAL_ERROR "Please install a more recent XCode for a compatible MacOS SDK.")
endif ()
elseif (NOT DEFAULT_MACOS_SDK_VERSION IN_LIST VALID_MACOS_SDK_VERSIONS)
# MacOS system supports one of the past iterations of the new Accelerate
# BLAS/LAPACK. If the latest possible XCode is installed is installed on
# this older system, there might be a mismatch between the SDK and the
# system binary. Find a matching SDK from the Command Line Tools instead.
foreach (_MACOS_SDK_VERSION IN LISTS VALID_MACOS_SDK_VERSIONS)
find_path(VALID_MACOS_SDK NAMES "MacOSX${_MACOS_SDK_VERSION}.sdk" HINTS "/Library/Developer/CommandLineTools/SDKs" NO_CACHE)
if (VALID_MACOS_SDK)
set(VALID_MACOS_SDK "${VALID_MACOS_SDK}/MacOSX${_MACOS_SDK_VERSION}.sdk")
break ()
endif ()
endforeach ()
if (VALID_MACOS_SDK)
set(CMAKE_OSX_SYSROOT "${VALID_MACOS_SDK}" CACHE PATH "" FORCE)
else ()
message(STATUS "The MacOS SDK is: ${CMAKE_OSX_SYSROOT}")
message(STATUS "The compatible MacOS SDK versions are: ${VALID_MACOS_SDK_VERSIONS}")
message(FATAL_ERROR "Couldn't find a compatible MacOS SDK. Please install compatible XCode Command Line Tools.")
endif () endif ()
endif () endif ()
message(STATUS "The MacOS SDK is: ${CMAKE_OSX_SYSROOT}")
set(ENV{CMAKE_FRAMEWORK_PATH} "${CMAKE_OSX_SYSROOT}/System/Library/Frameworks")
set(BLA_VENDOR "Apple") set(BLA_VENDOR "Apple")
find_package(LAPACK MODULE) find_package(LAPACK MODULE)
......
...@@ -72,14 +72,14 @@ set(CBLAS OFF CACHE BOOL "") ...@@ -72,14 +72,14 @@ set(CBLAS OFF CACHE BOOL "")
set(LAPACKE ON CACHE BOOL "") set(LAPACKE ON CACHE BOOL "")
# Add the $NEWLAPACK symbols to the linker flags used in try_compile() # Add the $NEWLAPACK symbols to the linker flags used in try_compile()
set(CMAKE_EXE_LINKER_FLAGS "-Wl,-alias_list,${CMAKE_CURRENT_BINARY_DIR}/new-lapack.alias") set(CMAKE_EXE_LINKER_FLAGS "-framework Accelerate -Wl,-alias_list,${CMAKE_CURRENT_BINARY_DIR}/new-lapack.alias")
if (BUILD_INDEX64) if (BUILD_INDEX64)
# Add the $NEWLAPACK$ILP64 symbols to the linker flags used for shared libraries # Add the $NEWLAPACK$ILP64 symbols to the linker flags used for shared libraries
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-alias_list,${CMAKE_CURRENT_BINARY_DIR}/new-lapack-ilp64.alias") set(CMAKE_SHARED_LINKER_FLAGS "-framework Accelerate -Wl,-alias_list,${CMAKE_CURRENT_BINARY_DIR}/new-lapack-ilp64.alias")
else () else ()
# Add the $NEWLAPACK symbols to the linker flags used for shared libraries # Add the $NEWLAPACK symbols to the linker flags used for shared libraries
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-alias_list,${CMAKE_CURRENT_BINARY_DIR}/new-lapack.alias") set(CMAKE_SHARED_LINKER_FLAGS "-framework Accelerate -Wl,-alias_list,${CMAKE_CURRENT_BINARY_DIR}/new-lapack.alias")
endif () endif ()
FetchContent_Declare( FetchContent_Declare(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment