From c3224b947e37e9cb054dd230a929aaba6a929a9b Mon Sep 17 00:00:00 2001 From: Rintaro Ishizaki Date: Mon, 29 Jul 2024 17:22:12 -0700 Subject: [PATCH] [CMake] Enable package CMO only in newer compiler (cherry picked from commit 3cb628504357e361a5e7130c794bfd296d916cec) --- cmake/modules/SwiftCompilerCapability.cmake | 22 +++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/cmake/modules/SwiftCompilerCapability.cmake b/cmake/modules/SwiftCompilerCapability.cmake index 951e563a49c..d62e387184f 100644 --- a/cmake/modules/SwiftCompilerCapability.cmake +++ b/cmake/modules/SwiftCompilerCapability.cmake @@ -22,6 +22,19 @@ macro(swift_supports_implicit_module module_name out_var) ) endmacro() +function(swift_get_swiftlang_version out_var) + execute_process( + COMMAND "${CMAKE_Swift_COMPILER}" -version + OUTPUT_VARIABLE output ERROR_VARIABLE output + RESULT_VARIABLE result + TIMEOUT 10 + ) + + if(output MATCHES [[swiftlang-([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)]]) + set("${out_var}" "${CMAKE_MATCH_1}" PARENT_SCOPE) + endif() +endfunction() + # Get "package cross-module-optimization" compiler arguments suitable for the compiler. function(swift_get_package_cmo_support out_var) # > 6.0 : Fixed feature. @@ -43,8 +56,13 @@ function(swift_get_package_cmo_support out_var) -Xfrontend -experimental-package-bypass-resilience ) if(result) - set(${out_var} EXPERIMENTAL PARENT_SCOPE) - return() + # Package CMO is implmented in Xcode 16 Beta 4 (swiftlang-6.0.0.6.8) or later. + # Consider it's not supported in non Xcode toolchain with "-experimental" options. + swift_get_swiftlang_version(swiftlang_version) + if(swiftlang_version AND swiftlang_version VERSION_GREATER_EQUAL 6.0.0.6) + set(${out_var} EXPERIMENTAL PARENT_SCOPE) + return() + endif() endif() # < 6.0 : Not supported.