Apply whole program optimization for certain targets

Only applied to certain targets to prevent bombing compile times; other projects don't really benefit of this.
This commit is contained in:
Kawe Mazidjatari 2023-05-13 11:57:57 +02:00
parent 5ba0beab40
commit e5a455e7c7
6 changed files with 36 additions and 5 deletions

View File

@ -75,3 +75,15 @@ macro( define_compiler_variables )
message( FATAL_ERROR "Unsupported compiler: ${CMAKE_CXX_COMPILER_ID}" )
endif()
endmacro()
# -----------------------------------------------------------------------------
# Apply whole program optimization for this target in release ( !slow! )
# -----------------------------------------------------------------------------
macro( whole_program_optimization )
target_compile_options( ${PROJECT_NAME} PRIVATE
$<$<CONFIG:Release>:/GL>
)
target_link_options( ${PROJECT_NAME} PRIVATE
$<$<CONFIG:Release>:/LTCG>
)
endmacro()

View File

@ -57,7 +57,11 @@ add_sources( SOURCE_GROUP "Math"
)
end_sources()
whole_program_optimization()
# Setup precompiled header
target_precompile_headers( ${PROJECT_NAME} PRIVATE mathlib_pch.h )
target_compile_definitions( ${PROJECT_NAME} PRIVATE -DBUILDING_MATHLIB )
target_precompile_headers( ${PROJECT_NAME} PRIVATE
"mathlib_pch.h"
)
target_compile_definitions( ${PROJECT_NAME} PRIVATE
"BUILDING_MATHLIB"
)

View File

@ -9,3 +9,4 @@ add_sources( SOURCE_GROUP "Core"
)
end_sources()
whole_program_optimization()

View File

@ -65,4 +65,8 @@ add_sources( SOURCE_GROUP "Include"
)
end_sources()
target_compile_definitions( ${PROJECT_NAME} PRIVATE WIN32 )
whole_program_optimization()
target_compile_definitions( ${PROJECT_NAME} PRIVATE
"WIN32"
)

View File

@ -22,7 +22,11 @@ add_sources( SOURCE_GROUP "Include"
)
end_sources()
target_precompile_headers( ${PROJECT_NAME} PRIVATE Pch.h )
whole_program_optimization()
target_precompile_headers( ${PROJECT_NAME} PRIVATE
"Pch.h"
)
# -----------------------------------------------------------------------------
# Detour runtime
@ -54,6 +58,7 @@ add_sources( SOURCE_GROUP "Include"
)
end_sources()
whole_program_optimization()
# -----------------------------------------------------------------------------
# Detour crowd
@ -83,6 +88,7 @@ add_sources( SOURCE_GROUP "Include"
)
end_sources()
whole_program_optimization()
# -----------------------------------------------------------------------------
# Detour tile cache
@ -102,6 +108,7 @@ add_sources( SOURCE_GROUP "Include"
)
end_sources()
whole_program_optimization()
# -----------------------------------------------------------------------------
# Recast runtime
@ -131,3 +138,4 @@ add_sources( SOURCE_GROUP "Include"
)
end_sources()
whole_program_optimization()

View File

@ -132,6 +132,8 @@ add_sources( SOURCE_GROUP "Sinks"
)
end_sources()
whole_program_optimization()
target_compile_definitions( ${PROJECT_NAME} PRIVATE
"SPDLOG_COMPILED_LIB"
"SPDLOG_NO_EXCEPTIONS"