diff options
Diffstat (limited to 'Modules/Compiler/GNU.cmake')
-rw-r--r-- | Modules/Compiler/GNU.cmake | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/Modules/Compiler/GNU.cmake b/Modules/Compiler/GNU.cmake index 928e726..48639cd 100644 --- a/Modules/Compiler/GNU.cmake +++ b/Modules/Compiler/GNU.cmake @@ -18,6 +18,7 @@ set(__pch_header_OBJCXX "objective-c++-header") macro(__compiler_gnu lang) # Feature flags. set(CMAKE_${lang}_VERBOSE_FLAG "-v") + set(CMAKE_${lang}_COMPILE_OPTIONS_WARNING_AS_ERROR "-Werror") set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC") set (_CMAKE_${lang}_PIE_MAY_BE_SUPPORTED_BY_LINKER NO) if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 3.4) @@ -71,7 +72,25 @@ macro(__compiler_gnu lang) # * https://gcc.gnu.org/onlinedocs/gcc-4.5.4/gcc/Option-Summary.html (yes) if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 4.5) set(_CMAKE_${lang}_IPO_MAY_BE_SUPPORTED_BY_COMPILER YES) - set(__lto_flags -flto) + + set(__lto_flags "") + + # '-flto=auto' introduced since GCC 10.1: + # * https://gcc.gnu.org/onlinedocs/gcc-9.5.0/gcc/Optimize-Options.html#Optimize-Options (no) + # * https://gcc.gnu.org/onlinedocs/gcc-10.1.0/gcc/Optimize-Options.html#Optimize-Options (yes) + # Since GCC 12.1, the abundance of a parameter produces a warning if compiling multiple targets. + # FIXME: What version of GCC for Windows added support for -flto=auto? 10.3 does not have it. + if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 11.0) + list(APPEND __lto_flags -flto=auto) + elseif(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 10.1) + if (CMAKE_HOST_WIN32) + list(APPEND __lto_flags -flto=1) + else() + list(APPEND __lto_flags -flto=auto) + endif() + else() + list(APPEND __lto_flags -flto) + endif() if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 4.7) # '-ffat-lto-objects' introduced since GCC 4.7: @@ -119,4 +138,11 @@ macro(__compiler_gnu lang) set(CMAKE_${lang}_COMPILE_OPTIONS_USE_PCH -include <PCH_HEADER>) set(CMAKE_${lang}_COMPILE_OPTIONS_CREATE_PCH -x ${__pch_header_${lang}} -include <PCH_HEADER>) endif() + + # '-fdiagnostics-color=always' introduced since GCC 4.9 + # https://gcc.gnu.org/gcc-4.9/changes.html + if(CMAKE_${lang}_COMPILER_VERSION VERSION_GREATER_EQUAL 4.9) + set(CMAKE_${lang}_COMPILE_OPTIONS_COLOR_DIAGNOSTICS "-fdiagnostics-color=always") + set(CMAKE_${lang}_COMPILE_OPTIONS_COLOR_DIAGNOSTICS_OFF "-fno-diagnostics-color") + endif() endmacro() |