Use interprocedural optimization flags on every C++ compiler that supports it

This commit is contained in:
Username404-59 2021-09-22 15:49:07 +02:00
parent 82520e63ba
commit 1ee7b8dc7c
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
1 changed files with 8 additions and 3 deletions

View File

@ -51,7 +51,7 @@ if (${IS_GNU} OR ${IS_CLANG})
add_definitions(-D_GLIBCXX_PARALLEL)
endif()
endif()
set(CMAKE_CXX_FLAGS "-pthread -flto ${CMAKE_CXX_FLAGS} -fstrict-enums -pipe -fstack-protector-strong -fstack-clash-protection -funwind-tables -fasynchronous-unwind-tables -frtti -fexceptions")
set(CMAKE_CXX_FLAGS "-pthread ${CMAKE_CXX_FLAGS} -fstrict-enums -pipe -fstack-protector-strong -fstack-clash-protection -funwind-tables -fasynchronous-unwind-tables -frtti -fexceptions")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -ffunction-sections -fdata-sections -fmerge-all-constants -ftree-vectorize")
include(CheckCXXCompilerFlag)
set(CF_PROTECTION "-fcf-protection")
@ -61,17 +61,22 @@ if (${IS_GNU} OR ${IS_CLANG})
endif()
endif()
include(CheckIPOSupported)
check_ipo_supported(RESULT CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE LANGUAGES CXX)
if (${IS_GNU})
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${MINIMAL_GNU})
message(FATAL_ERROR "G++ ${MINIMAL_GNU} or higher is required.")
endif()
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -foptimize-strlen -fsched-pressure -flive-range-shrinkage -fpredictive-commoning -ftree-partial-pre -fzero-call-used-regs=used-gpr-arg -ftree-parallelize-loops=2 -fira-loop-pressure -ftree-loop-distribution -floop-interchange -fsplit-paths -fgcse-las -fgcse-sm -fipa-pta -fstdarg-opt -fivopts -s")
set(CMAKE_CXX_FLAGS "-fno-use-linker-plugin -fwhole-program ${CMAKE_CXX_FLAGS}")
if (${CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE})
set(CMAKE_CXX_FLAGS_RELEASE "-fwhole-program ${CMAKE_CXX_FLAGS_RELEASE}")
endif()
elseif(${IS_CLANG})
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${MINIMAL_CLANG})
message(FATAL_ERROR "Clang ${MINIMAL_CLANG} or higher is required.")
endif()
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fwhole-program-vtables -fstrict-vtable-pointers")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto=full -fwhole-program-vtables -fstrict-vtable-pointers")
endif()
if (MINGW OR MSVC)