Skip to content

Commit

Permalink
Fix MacOS build on 11.x SDK and Catalyst build (#54506)
Browse files Browse the repository at this point in the history
* Fix MacOS build on 11.x SDK and Catalyst build

The configure.cmake was not getting the minimum supported OS version because
it was being set via set_compile_options and the config functions can only
get options from CMAKE_XXX_FLAGS.

* Add comment explaining why we set the macOS options via CMAKE_XXX_FLAGS
  • Loading branch information
janvorli authored Jun 27, 2021
1 parent 02f70d0 commit 385b6f3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
19 changes: 11 additions & 8 deletions eng/native/configurecompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -393,30 +393,33 @@ if (CLR_CMAKE_HOST_UNIX)
# replaced with a default value, and always gets expanded to an OS version.
# https://gitlab.kitware.com/cmake/cmake/-/issues/20132
# We need to disable the warning that -tagret replaces -mmacosx-version-min
add_compile_options(-Wno-overriding-t-option)
set(DISABLE_OVERRIDING_MIN_VERSION_ERROR -Wno-overriding-t-option)
add_link_options(-Wno-overriding-t-option)
if(CLR_CMAKE_HOST_ARCH_ARM64)
add_compile_options(-target arm64-apple-ios14.2-macabi)
set(MACOS_VERSION_MIN_FLAGS "-target arm64-apple-ios14.2-macabi")
add_link_options(-target arm64-apple-ios14.2-macabi)
elseif(CLR_CMAKE_HOST_ARCH_AMD64)
add_compile_options(-target x86_64-apple-ios13.5-macabi)
set(MACOS_VERSION_MIN_FLAGS "-target x86_64-apple-ios13.5-macabi")
add_link_options(-target x86_64-apple-ios13.5-macabi)
else()
clr_unknown_arch()
endif()
# These options are intentionally set using the CMAKE_XXX_FLAGS instead of
# add_compile_options so that they take effect on the configuration functions
# in various configure.cmake files.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MACOS_VERSION_MIN_FLAGS} ${DISABLE_OVERRIDING_MIN_VERSION_ERROR}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MACOS_VERSION_MIN_FLAGS} ${DISABLE_OVERRIDING_MIN_VERSION_ERROR}")
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} ${MACOS_VERSION_MIN_FLAGS} ${DISABLE_OVERRIDING_MIN_VERSION_ERROR}")
else()
if(CLR_CMAKE_HOST_ARCH_ARM64)
# 'pthread_jit_write_protect_np' is only available on macOS 11.0 or newer
set(MACOS_VERSION_MIN_FLAGS -mmacosx-version-min=11.0)
set(CMAKE_OSX_DEPLOYMENT_TARGET "11.0")
add_compile_options(-arch arm64)
elseif(CLR_CMAKE_HOST_ARCH_AMD64)
set(MACOS_VERSION_MIN_FLAGS -mmacosx-version-min=10.13)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13")
add_compile_options(-arch x86_64)
else()
clr_unknown_arch()
endif()
add_compile_options(${MACOS_VERSION_MIN_FLAGS})
add_linker_flag(${MACOS_VERSION_MIN_FLAGS})
endif(CLR_CMAKE_TARGET_MACCATALYST)
endif(CLR_CMAKE_HOST_OSX OR CLR_CMAKE_HOST_MACCATALYST)

Expand Down
14 changes: 11 additions & 3 deletions src/libraries/Native/Unix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,23 @@ endif()
if(CLR_CMAKE_TARGET_MACCATALYST)
# -target overrides -mmacosx-version-min so suppress warning about that
# https://gitlab.kitware.com/cmake/cmake/-/issues/20132
add_compile_options(-Wno-overriding-t-option)
set(DISABLE_OVERRIDING_MIN_VERSION_ERROR -Wno-overriding-t-option)
add_link_options(-Wno-overriding-t-option)
if (CLR_CMAKE_TARGET_ARCH_AMD64)
add_compile_options(-target x86_64-apple-ios13.5-macabi)
set(MACOS_VERSION_MIN_FLAGS "-target x86_64-apple-ios13.5-macabi")
add_link_options(-target x86_64-apple-ios13.5-macabi)
elseif (CLR_CMAKE_TARGET_ARCH_ARM64)
add_compile_options(-target arm64-apple-ios14.2-macabi)
set(MACOS_VERSION_MIN_FLAGS "-target arm64-apple-ios14.2-macabi")
add_link_options(-target arm64-apple-ios14.2-macabi)
endif()

# These options are intentionally set using the CMAKE_XXX_FLAGS instead of
# add_compile_options so that they take effect on the configuration functions
# in various configure.cmake files.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MACOS_VERSION_MIN_FLAGS} ${DISABLE_OVERRIDING_MIN_VERSION_ERROR}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MACOS_VERSION_MIN_FLAGS} ${DISABLE_OVERRIDING_MIN_VERSION_ERROR}")
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} ${MACOS_VERSION_MIN_FLAGS} ${DISABLE_OVERRIDING_MIN_VERSION_ERROR}")

endif()

if(CLR_CMAKE_TARGET_TVOS)
Expand Down
4 changes: 4 additions & 0 deletions src/libraries/Native/Unix/System.Native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ if (NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CM
add_definitions(-DHAS_CONSOLE_SIGNALS)
endif ()

if (CLR_CMAKE_TARGET_OSX)
add_definitions(-D_DARWIN_C_SOURCE)
endif ()

include_directories("${CLR_SRC_NATIVE_DIR}/common")

set(NATIVE_SOURCES
Expand Down
6 changes: 5 additions & 1 deletion src/libraries/Native/build-native.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ fi

if [[ "$__TargetOS" == OSX ]]; then
# set default OSX deployment target
__CMakeArgs="-DCMAKE_OSX_DEPLOYMENT_TARGET=10.13 $__CMakeArgs"
if [[ "$__BuildArch" == x64 ]]; then
__CMakeArgs="-DCMAKE_OSX_DEPLOYMENT_TARGET=10.13 $__CMakeArgs"
else
__CMakeArgs="-DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 $__CMakeArgs"
fi
elif [[ "$__TargetOS" == Android && -z "$ROOTFS_DIR" ]]; then
if [[ -z "$ANDROID_NDK_ROOT" ]]; then
echo "Error: You need to set the ANDROID_NDK_ROOT environment variable pointing to the Android NDK root."
Expand Down

0 comments on commit 385b6f3

Please sign in to comment.