From 2bb0a0a77cb09b05a07c8ec5eadd922a40dfaee0 Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 18 Dec 2020 23:59:40 +0100 Subject: [PATCH] CMake: Set default value for CMAKE_OSX_DEPLOYMENT_TARGET CMake versions older than 3.19 choose the sysroot based on the deployment target, so this does result in it choosing the 10.9 SDK even when targeting arm64, so we need to work around that. --- CMakeLists.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9870660adc..c50cbdc58a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,6 +51,22 @@ else() set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${_configs}) endif() +# Set defaults for macOS, must be before project(). +if(APPLE) + set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "Minimum macOS version to target") + set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++") + + if(CMAKE_VERSION VERSION_LESS "3.19" AND NOT CMAKE_OSX_SYSROOT) + # Older CMake chose SDK based on deployment target, against Apple's recommendations. + # However, we need to use the latest to be able to target arm64. + if(IS_DIRECTORY "/Library/Developer/CommandLineTools/SDKs/MacOSX11.1.sdk") + set(CMAKE_OSX_SYSROOT "/Library/Developer/CommandLineTools/SDKs/MacOSX11.1.sdk" CACHE STRING "") + elseif(IS_DIRECTORY "/Library/Developer/CommandLineTools/SDKs/MacOSX11.0.sdk") + set(CMAKE_OSX_SYSROOT "/Library/Developer/CommandLineTools/SDKs/MacOSX11.0.sdk" CACHE STRING "") + endif() + endif() +endif() + # Figure out the version set(_s "[\\t ]*") # CMake doesn't support \s* file(STRINGS "setup.cfg" _version REGEX "^version${_s}=${_s}")