Skip to content

Commit c3224b9

Browse files
committed
[CMake] Enable package CMO only in newer compiler
(cherry picked from commit 3cb6285)
1 parent 82a453c commit c3224b9

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

cmake/modules/SwiftCompilerCapability.cmake

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ macro(swift_supports_implicit_module module_name out_var)
2222
)
2323
endmacro()
2424

25+
function(swift_get_swiftlang_version out_var)
26+
execute_process(
27+
COMMAND "${CMAKE_Swift_COMPILER}" -version
28+
OUTPUT_VARIABLE output ERROR_VARIABLE output
29+
RESULT_VARIABLE result
30+
TIMEOUT 10
31+
)
32+
33+
if(output MATCHES [[swiftlang-([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)]])
34+
set("${out_var}" "${CMAKE_MATCH_1}" PARENT_SCOPE)
35+
endif()
36+
endfunction()
37+
2538
# Get "package cross-module-optimization" compiler arguments suitable for the compiler.
2639
function(swift_get_package_cmo_support out_var)
2740
# > 6.0 : Fixed feature.
@@ -43,8 +56,13 @@ function(swift_get_package_cmo_support out_var)
4356
-Xfrontend -experimental-package-bypass-resilience
4457
)
4558
if(result)
46-
set(${out_var} EXPERIMENTAL PARENT_SCOPE)
47-
return()
59+
# Package CMO is implmented in Xcode 16 Beta 4 (swiftlang-6.0.0.6.8) or later.
60+
# Consider it's not supported in non Xcode toolchain with "-experimental" options.
61+
swift_get_swiftlang_version(swiftlang_version)
62+
if(swiftlang_version AND swiftlang_version VERSION_GREATER_EQUAL 6.0.0.6)
63+
set(${out_var} EXPERIMENTAL PARENT_SCOPE)
64+
return()
65+
endif()
4866
endif()
4967

5068
# < 6.0 : Not supported.

0 commit comments

Comments
 (0)