From 2fd62b70911d14d8c6ca9fd0301ff0f2e3a3ce0d Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sat, 13 May 2023 19:44:41 +0200 Subject: [PATCH] Enable LTCG for executables and shared libraries Enable Link Time Code Generation as some libraries are compiled using /GL (Whole Program Optimization) which requires the code generation to be delayed to link time. Not doing this will result in longer build times, as the linker has to terminate its progress if it links a library compiled with /GL, and restart this operation using /LTCG. --- r5dev/cmake/Macros.cmake | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/r5dev/cmake/Macros.cmake b/r5dev/cmake/Macros.cmake index bb064a47..e4ae03ca 100644 --- a/r5dev/cmake/Macros.cmake +++ b/r5dev/cmake/Macros.cmake @@ -48,8 +48,14 @@ macro( add_module MODULE_TYPE MODULE_NAME REUSE_PCH FOLDER_NAME ) add_library( ${PROJECT_NAME} ) elseif( ${MODULE_TYPE} STREQUAL "shared_lib" ) add_library( ${PROJECT_NAME} SHARED ) + target_link_options( ${PROJECT_NAME} PRIVATE + "$<$:/LTCG>" + ) elseif(${MODULE_TYPE} STREQUAL "exe") add_executable( ${PROJECT_NAME} ) + target_link_options( ${PROJECT_NAME} PRIVATE + "$<$:/LTCG>" + ) else() message( FATAL_ERROR "Invalid module type: ${MODULE_TYPE}; expected 'lib', 'shared_lib', or 'exe'." ) endif() @@ -83,7 +89,4 @@ macro( whole_program_optimization ) target_compile_options( ${PROJECT_NAME} PRIVATE $<$:/GL> ) - target_link_options( ${PROJECT_NAME} PRIVATE - $<$:/LTCG> - ) endmacro()