From 83a1a33d664fb659fe0f85ee8d46977de7853a04 Mon Sep 17 00:00:00 2001 From: Richard Biely Date: Wed, 13 Dec 2023 07:26:32 +0100 Subject: [PATCH] Fixed: Non-xcode build workaround for macos with xcode 15 or later installed --- README.md | 9 +++++++++ src/CMakeLists.txt | 22 ++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/README.md b/README.md index b539cd36..85c24dd7 100644 --- a/README.md +++ b/README.md @@ -1324,6 +1324,15 @@ cmake -G Xcode ... cmake -G Ninja ``` +>**NOTE**
+When using MacOS you might run into a few issues caused by the specifics of the platform unrelated to Gaia-ECS. Quick way to fix them is listed bellow. +> +> CMake issue:
+> After you update to a new version of Xcode you might start getting "Ignoring CMAKE_OSX_SYSROOT value: ..." warnings when building the project. Residual cmake cache is to blame here. A solution is to delete files generated by cmake. +> +> Linker issue:
+> When not bulding the project from Xcode and using ***ld*** as your linker, if XCode 15 or later is installed on your system you will most likely run into various issues: https://developer.apple.com/documentation/xcode-release-notes/xcode-15-release-notes#Linking. In the CMake project a workaround is implemented which adds "-Wl,-ld_classic" to linker settings but if you use a different build system or settings you might want to do same. + ### Project settings Following is a list of parameters you can use to customize your build diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 182c6b94..143c9859 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -51,6 +51,28 @@ if(MSVC) enable_cxx_compiler_flag_if_supported("/permissive-") else() + # MacOS + if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") + # Workaround for the new linker starting with XCode 15 + # https://developer.apple.com/documentation/xcode-release-notes/xcode-15-release-notes#Linking + # We need to use -Wl,-ld_classic for the linker for the backwards compatibility when buiding + # outside of XCode because they messed things up. + if(NOT CMAKE_GENERATOR MATCHES "Xcode") + # Make sure xcodebuild is installed. Otherwise we won't be able to tell is the workaround + # needs to be applied + find_program(XCODEBUILD_EXECUTABLE NAMES xcodebuild) + + if(XCODEBUILD_EXECUTABLE) + execute_process(COMMAND xcodebuild -version OUTPUT_VARIABLE XCODE_VERSION_STRING OUTPUT_STRIP_TRAILING_WHITESPACE) + string(REGEX MATCH "([0-9]+)\\.[0-9]+" XCODE_MAJOR_VERSION ${XCODE_VERSION_STRING}) + + if(XCODE_MAJOR_VERSION GREATER_EQUAL "15") + add_link_options("-Wl,-ld_classic") + endif() + endif() + endif() + endif() + enable_cxx_compiler_flag_if_supported("-fno-exceptions") # strictness rules