diff options
author | Evan Wilde <etceterawilde@gmail.com> | 2023-11-06 00:36:28 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2023-11-17 13:43:21 (GMT) |
commit | c1d787e4734ca107e8ae084b3832e441651a6266 (patch) | |
tree | 9622a28a3c0e14caa452ac4ddb6733fa83564088 /Tests/SwiftOnly | |
parent | c39384f54019adce87d676a7ed6d8e772ce5b7f8 (diff) | |
download | CMake-c1d787e4734ca107e8ae084b3832e441651a6266.zip CMake-c1d787e4734ca107e8ae084b3832e441651a6266.tar.gz CMake-c1d787e4734ca107e8ae084b3832e441651a6266.tar.bz2 |
Swift: Add abstraction for compilation mode
Add a `CMAKE_Swift_COMPILATION_MODE` variable and corresponding
`Swift_COMPILATION_MODE` target property to control the compilation
mode. Select among `wholemodule`, `singlefile`, and `incremental`.
Add policy CMP0157 to remove the default `-wmo` flags in favor of the
abstract setting.
Issue: #25366
Diffstat (limited to 'Tests/SwiftOnly')
-rw-r--r-- | Tests/SwiftOnly/CMakeLists.txt | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Tests/SwiftOnly/CMakeLists.txt b/Tests/SwiftOnly/CMakeLists.txt index 13cf2b1..7de1e04 100644 --- a/Tests/SwiftOnly/CMakeLists.txt +++ b/Tests/SwiftOnly/CMakeLists.txt @@ -2,6 +2,9 @@ cmake_minimum_required(VERSION 3.3) if(POLICY CMP0126) cmake_policy(SET CMP0126 NEW) endif() +if(POLICY CMP0157) + cmake_policy(SET CMP0157 NEW) +endif() # NOTE: Force the Release mode configuration as there are some issues with the # debug information handling on macOS on certain Xcode builds. @@ -54,3 +57,20 @@ target_link_libraries(SwiftOnly PRIVATE SwiftIface) if(CMAKE_Swift_COMPILER_VERSION VERSION_GREATER_EQUAL 5.2) add_subdirectory("SwiftPlugin") endif() + +function(test_cmp0157_default mode) + + cmake_policy(GET CMP0157 cmp0157_wmo) + if(cmp0157_wmo STREQUAL "NEW") + set(CMAKE_Swift_COMPILATION_MODE "${mode}") + add_executable(hi_${mode} main.swift) + get_target_property(${mode}_swift_comp_mode hi_${mode} "Swift_COMPILATION_MODE") + if(NOT ${mode}_swift_comp_mode STREQUAL ${mode}) + message(SEND_ERROR "expected ${mode} -- found ${${mode}_swift_comp_mode}") + endif() + endif() +endfunction() + +test_cmp0157_default("wholemodule") +test_cmp0157_default("incremental") +test_cmp0157_default("singlefile") |