cmake: Additional optimization options

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2020-01-14 01:39:04 +01:00
parent ebc50dcefe
commit 844379f761

View file

@ -163,6 +163,34 @@ else()
endif()
endif()
set(${PropertyPrefix}BUILD_SIZE FALSE CACHE BOOL "Focus on small size instead of maximum performance in release builds.")
set(${PropertyPrefix}BUILD_SPEED TRUE CACHE BOOL "Focus on maximum performance instead of small size in release builds.")
if(${PropertyPrefix}BUILD_SIZE)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(_EXTRA_FLAGS "/O1 /Os /GF /GS- /Zp1 /arch:AVX /GR- /GL /LTCG:incremental /OPT:ICF")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${_EXTRA_FLAGS}")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} ${_EXTRA_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${_EXTRA_FLAGS}")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${_EXTRA_FLAGS}")
unset(_EXTRA_FLAGS)
endif()
elseif(${PropertyPrefix}BUILD_SPEED)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(_EXTRA_FLAGS "/O2 /Oi /Ot /Oy /GF /GS- /Zp4 /Qpar /arch:AVX /GR- /GL /LTCG:incremental /OPT:ICF")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${_EXTRA_FLAGS}")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} ${_EXTRA_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${_EXTRA_FLAGS}")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${_EXTRA_FLAGS}")
unset(_EXTRA_FLAGS)
endif()
endif()
################################################################################
# CMake / Compiler Dependencies
################################################################################