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.
This commit is contained in:
R-Goc 2025-06-14 11:04:43 +02:00 committed by Andrew Kaster
commit cdc851141d
Notes: github-actions[bot] 2025-06-16 17:49:52 +00:00
2 changed files with 17 additions and 0 deletions

View file

@ -72,6 +72,17 @@ if (MSVC)
add_link_options(/STACK:0x800000) add_link_options(/STACK:0x800000)
# disable floating-point expression contraction # disable floating-point expression contraction
add_cxx_compile_options(/fp:precise) 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() else()
add_cxx_compile_options(-Wall -Wextra) add_cxx_compile_options(-Wall -Wextra)
add_cxx_compile_options(-fno-exceptions) add_cxx_compile_options(-fno-exceptions)

View file

@ -18,6 +18,12 @@ if (NOT APPLE AND NOT ANDROID AND NOT WIN32 AND NOT LAGOM_USE_LINKER)
endif() endif()
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) if (LAGOM_USE_LINKER)
# FIXME: Move to only setting CMAKE_LINKER_TYPE once we drop support for CMake < 3.29 # FIXME: Move to only setting CMAKE_LINKER_TYPE once we drop support for CMake < 3.29
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.29) if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.29)