Skip to content

[CMake] Enable package CMO only in newer compiler #2764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions cmake/modules/SwiftCompilerCapability.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down