From 1ee7b8dc7c495c48a7fbdc7d17bef9b34daf1d8f Mon Sep 17 00:00:00 2001 From: Username404-59 Date: Wed, 22 Sep 2021 15:49:07 +0200 Subject: [PATCH] Use interprocedural optimization flags on every C++ compiler that supports it --- CMakeLists.txt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 755d8ff..aa6e898 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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)