From cdc851141dbaf159c39764462d2a2717bea68a2e Mon Sep 17 00:00:00 2001 From: R-Goc Date: Sat, 14 Jun 2025 11:04:43 +0200 Subject: [PATCH] Meta: Increase compilation speed with clang-cl This commit increases compilation speed when using clang-cl. It also decreases object size as well as adds -fstrict-aliasing to match the default on linux. The linker option added is not recognized by link.exe so we enable lld-link by default, which will also increase compilation speed by itself, and allow for LTO. --- Meta/CMake/common_compile_options.cmake | 11 +++++++++++ Meta/CMake/use_linker.cmake | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/Meta/CMake/common_compile_options.cmake b/Meta/CMake/common_compile_options.cmake index c6956797e3f..0dd4a727bf3 100644 --- a/Meta/CMake/common_compile_options.cmake +++ b/Meta/CMake/common_compile_options.cmake @@ -72,6 +72,17 @@ if (MSVC) add_link_options(/STACK:0x800000) # disable floating-point expression contraction add_cxx_compile_options(/fp:precise) + # reduces object size + add_cxx_compile_options(/Zc:inline) + # equivalent of -fvisibility-inlines-hidden + add_cxx_compile_options(/Zc:dllexportInlines-) + # clang-cl has this off by default unlike other clang versions + add_cxx_compile_options(-fstrict-aliasing) + add_cxx_compile_options(/Gw) + if (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" OR "Debug") + add_cxx_compile_options(-gcodeview-ghash) + add_cxx_link_options(/DEBUG:GHASH) + endif() else() add_cxx_compile_options(-Wall -Wextra) add_cxx_compile_options(-fno-exceptions) diff --git a/Meta/CMake/use_linker.cmake b/Meta/CMake/use_linker.cmake index 904fbe169c7..3f0619e957a 100644 --- a/Meta/CMake/use_linker.cmake +++ b/Meta/CMake/use_linker.cmake @@ -18,6 +18,12 @@ if (NOT APPLE AND NOT ANDROID AND NOT WIN32 AND NOT LAGOM_USE_LINKER) endif() endif() +if(WIN32 AND NOT LAGOM_USE_LINKER) + # We do not need to check for its presence. + # We know it is there with the installation of clang-cl which we require. + set(LAGOM_USE_LINKER "lld" CACHE STRING "" FORCE) +endif() + if (LAGOM_USE_LINKER) # FIXME: Move to only setting CMAKE_LINKER_TYPE once we drop support for CMake < 3.29 if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.29)