From ad6b82d2e7a4e549cbe58900958c8bea00f92775 Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 11 Oct 2023 18:33:58 +0100 Subject: [PATCH] CompilerSupport: Warn when deploying to older Apple platforms from Xcode 15 --- CMakeLists.txt | 24 -------------- .../juce_core/system/juce_CompilerSupport.h | 33 +++++++++++++++++++ 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 50fa35e20a..b8ff58e73a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,30 +27,6 @@ project(JUCE VERSION 7.0.7 LANGUAGES C CXX) include(CMakeDependentOption) -option(JUCE_SILENCE_XCODE_15_LINKER_WARNING - "By default, JUCE will warn when using a potentially dangerous combination of compiler and deployment target. - You can set this option to disable the warning if you're confident that your project is unaffected." - OFF) - -if(NOT JUCE_SILENCE_XCODE_15_LINKER_WARNING - AND CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" - AND CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 15.0) - message(WARNING "You are using Xcode 15.\n" - "If you're also using Link Time Optimisation (LTO), the resulting binary could be broken.\n" - "As a workaround, add either -Wl,-weak_reference_mismatches, or -Wl,-ld_classic to your linker flags.\n" - "You may set the option JUCE_SILENCE_XCODE_15_LINKER_WARNING to disable this warning after applying a workaround.\n" - "For more details see https://developer.apple.com/documentation/xcode-release-notes/xcode-15-release-notes#Linking.") - - if((CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS_EQUAL 12.0) - OR (CMAKE_SYSTEM_NAME STREQUAL "iOS" AND CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS_EQUAL 14.0)) - message(WARNING "You are using Xcode 15 to target an older Apple platform.\n" - "The linker in this version of Xcode may produce a binary that crashes on older Apple platforms.\n" - "As a workaround, either use a more recent deployment target, or add -Wl,-ld_classic to your linker flags.\n" - "You may set the option JUCE_SILENCE_XCODE_15_LINKER_WARNING to disable this warning after applying a workaround.\n" - "For more details see https://developer.apple.com/documentation/xcode-release-notes/xcode-15-release-notes#Linking.") - endif() -endif() - set_property(GLOBAL PROPERTY USE_FOLDERS YES) set(JUCE_MODULES_DIR "${JUCE_SOURCE_DIR}/modules" CACHE INTERNAL diff --git a/modules/juce_core/system/juce_CompilerSupport.h b/modules/juce_core/system/juce_CompilerSupport.h index c1e173c50e..b0d88cb4f1 100644 --- a/modules/juce_core/system/juce_CompilerSupport.h +++ b/modules/juce_core/system/juce_CompilerSupport.h @@ -63,6 +63,39 @@ #endif #endif + #if ! defined (JUCE_SILENCE_XCODE_15_LINKER_WARNING) \ + && defined (__apple_build_version__) \ + && __clang_major__ == 15 \ + && __clang_minor__ == 0 + // This is a warning because builds may be usable when LTO is disabled + #pragma GCC warning "If you are using Link Time Optimisation (LTO), the " \ + "new linker introduced in Xcode 15 may produce a broken binary.\n" \ + "As a workaround, add either '-Wl,-weak_reference_mismatches,weak' or " \ + "'-Wl,-ld_classic' to your linker flags.\n" \ + "Once you've selected a workaround, you can add " \ + "JUCE_SILENCE_XCODE_15_LINKER_WARNING to your preprocessor definitions " \ + "to silence this warning." + + #if ((defined (MAC_OS_X_VERSION_MIN_REQUIRED) \ + && MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_VERSION_13_0) \ + || (defined (__IPHONE_OS_VERSION_MIN_REQUIRED) \ + && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_15_0)) + // This is an error because the linker _will_ produce a binary that is + // broken on older platforms + static_assert (std::string_view (__clang_version__) + != std::string_view ("15.0.0 (clang-1500.0.40.1)"), + "The new linker introduced in Xcode 15.0 will produce " + "broken binaries when targeting older platforms.\n" + "To work around this issue, bump your deployment target to " + "macOS 13 or iOS 15, re-enable the old linker by adding " + "'-Wl,-ld_classic' to your link flags, or update to Xcode " + "15.1.\n" + "Once you've selected a workaround, you can add " + "JUCE_SILENCE_XCODE_15_LINKER_WARNING to your preprocessor " + "definitions to silence this warning."); + #endif + #endif + #define JUCE_CXX14_IS_AVAILABLE (__cplusplus >= 201402L) #define JUCE_CXX17_IS_AVAILABLE (__cplusplus >= 201703L)