From ce8ceaa952524180b4bce0a0cd6a3556b59dfa8e Mon Sep 17 00:00:00 2001 From: Jeremy Schonfeld <1004103+jmschonfeld@users.noreply.github.com> Date: Fri, 9 Aug 2024 14:54:26 -0700 Subject: [PATCH] Enable WMO (#832) * Enable whole-module-optimization in release builds * Address feedback * Fix build failures * Don't enable WMO on Windows --- CMakeLists.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index b99fcfa8f..fd8e463de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,6 +35,16 @@ if(NOT SWIFT_SYSTEM_NAME) endif() endif() +# Don't enable WMO on Windows due to linker failures +if(NOT CMAKE_SYSTEM_NAME STREQUAL Windows) + # Enable whole module optimization for release builds & incremental for debug builds + if(POLICY CMP0157) + set(CMAKE_Swift_COMPILATION_MODE "$,wholemodule,incremental>") + else() + add_compile_options($<$,$>:-wmo>) + endif() +endif() + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)