diff options
author | Brad King <brad.king@kitware.com> | 2023-11-19 16:47:22 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2023-11-19 16:47:37 (GMT) |
commit | 1f7a653e90e2e037867a4121c9edd2bd04997cbd (patch) | |
tree | 1e0e21481343a1599d9b4ca934750b808eb02b01 /Modules | |
parent | 67be468693c19cdc5377d0d090c055d58f484ed2 (diff) | |
parent | 0f80101b73c175dd0272097a5ef9d58f7c35b093 (diff) | |
download | CMake-1f7a653e90e2e037867a4121c9edd2bd04997cbd.zip CMake-1f7a653e90e2e037867a4121c9edd2bd04997cbd.tar.gz CMake-1f7a653e90e2e037867a4121c9edd2bd04997cbd.tar.bz2 |
Merge topic 'swift-compilation-mode'
0f80101b73 Tests: Update Swift tests to use CMP0157 NEW behavior
c1d787e473 Swift: Add abstraction for compilation mode
c39384f540 Tests: Simplify RunCMake.Swift conditions to enable use of Swift
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !8918
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/CMakeSwiftInformation.cmake | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/Modules/CMakeSwiftInformation.cmake b/Modules/CMakeSwiftInformation.cmake index 1c6f0df..9f4ed34 100644 --- a/Modules/CMakeSwiftInformation.cmake +++ b/Modules/CMakeSwiftInformation.cmake @@ -68,30 +68,42 @@ set(CMAKE_Swift_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL -libc MD) set(CMAKE_Swift_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebug -libc MTd) set(CMAKE_Swift_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebugDLL -libc MDd) +set(CMAKE_Swift_FLAGS_DEBUG_INIT "-Onone -g") +set(CMAKE_Swift_FLAGS_RELEASE_INIT "-O") +set(CMAKE_Swift_FLAGS_RELWITHDEBINFO_INIT "-O -g") +set(CMAKE_Swift_FLAGS_MINSIZEREL_INIT "-Osize") + if(CMAKE_GENERATOR STREQUAL "Xcode") + string(APPEND CMAKE_Swift_FLAGS_DEBUG_INIT " ${CMAKE_Swift_FLAGS_DEBUG_LINKER_FLAGS}") + string(APPEND CMAKE_Swift_FLAGS_RELWITHDEBINFO_INIT " ${CMAKE_Swift_FLAGS_RELWITHDEBINFO_LINKER_FLAGS}") +endif() + +# Warns if unset and uses old policy. +# Old policy flag-smashes the wmo and incremental flags onto the compiler flags. +# New policy respects the Swift_COMPILATION_MODE target property to add +# incremental and wholemodule optimization flags as appropriate. +cmake_policy(GET CMP0157 __SWIFT_COMP_MODE_CMP0157) +if(__SWIFT_COMP_MODE_CMP0157 STREQUAL "NEW") + set(CMAKE_Swift_COMPILATION_MODE_DEFAULT "incremental") +else() # Xcode has a separate Xcode project option (SWIFT_COMPILATION_MODE) used to set # whether compiling with whole-module optimizations or incrementally. Setting # these options here will have no effect when compiling with the built-in driver, # and will explode violently, leaving build products in the source directory, when - # using the old swift driver. - set(CMAKE_Swift_FLAGS_DEBUG_INIT "-Onone -g ${CMAKE_Swift_FLAGS_DEBUG_LINKER_FLAGS}") - set(CMAKE_Swift_FLAGS_RELEASE_INIT "-O") - set(CMAKE_Swift_FLAGS_RELWITHDEBINFO_INIT "-O -g ${CMAKE_Swift_FLAGS_RELWITHDEBINFO_LINKER_FLAGS}") - set(CMAKE_Swift_FLAGS_MINSIZEREL_INIT "-Osize") -else() - set(CMAKE_Swift_FLAGS_DEBUG_INIT "-Onone -g -incremental") - set(CMAKE_Swift_FLAGS_RELEASE_INIT "-O") - set(CMAKE_Swift_FLAGS_RELWITHDEBINFO_INIT "-O -g") - set(CMAKE_Swift_FLAGS_MINSIZEREL_INIT "-Osize") - - # Enable Whole Module Optimization by default unless the old - # C++ driver is being used, which behaves differently under WMO. - if(NOT CMAKE_Swift_COMPILER_USE_OLD_DRIVER) - string(APPEND CMAKE_Swift_FLAGS_RELEASE_INIT " -wmo") - string(APPEND CMAKE_Swift_FLAGS_RELWITHDEBINFO_INIT " -wmo") - string(APPEND CMAKE_Swift_FLAGS_MINSIZEREL_INIT " -wmo") + # using the old swift driver. Don't append `-incremental` or `-wmo` to the + # flags in the Xcode generator. + if(NOT CMAKE_GENERATOR STREQUAL "Xcode") + # Enable Whole Module Optimization by default unless the old + # C++ driver is being used, which behaves differently under WMO. + if(NOT CMAKE_Swift_COMPILER_USE_OLD_DRIVER) + string(APPEND CMAKE_Swift_FLAGS_RELEASE_INIT " -wmo") + string(APPEND CMAKE_Swift_FLAGS_RELWITHDEBINFO_INIT " -wmo") + string(APPEND CMAKE_Swift_FLAGS_MINSIZEREL_INIT " -wmo") + endif() + string(APPEND CMAKE_Swift_FLAGS_DEBUG_INIT " -incremental") endif() endif() +unset(__SWIFT_COMP_MODE_CMP0157) if(CMAKE_EXECUTABLE_FORMAT STREQUAL "ELF") if(NOT DEFINED CMAKE_Swift_LINK_WHAT_YOU_USE_FLAG) |