mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-06 05:40:54 -06:00
IPO: Consider support for each language separately
We only define `INTERPROCEDURAL_OPTIMIZATION` behavior for C, CXX, and Fortran languages. Do not try to enable support for other languages. Furthermore, each language builds with a different compiler, so check for support by CMake and the compiler for each language independently. Fixes: #16944
This commit is contained in:
@@ -207,15 +207,17 @@ function(check_ipo_supported)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT _CMAKE_IPO_SUPPORTED_BY_CMAKE)
|
||||
_ipo_not_supported("CMake doesn't support IPO for current compiler")
|
||||
return()
|
||||
endif()
|
||||
foreach(lang ${languages})
|
||||
if(NOT _CMAKE_${lang}_IPO_SUPPORTED_BY_CMAKE)
|
||||
_ipo_not_supported("CMake doesn't support IPO for current ${lang} compiler")
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(NOT _CMAKE_IPO_MAY_BE_SUPPORTED_BY_COMPILER)
|
||||
_ipo_not_supported("Compiler doesn't support IPO")
|
||||
return()
|
||||
endif()
|
||||
if(NOT _CMAKE_${lang}_IPO_MAY_BE_SUPPORTED_BY_COMPILER)
|
||||
_ipo_not_supported("${lang} compiler doesn't support IPO")
|
||||
return()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(CMAKE_GENERATOR MATCHES "^Visual Studio ")
|
||||
_ipo_not_supported("CMake doesn't support IPO for current generator")
|
||||
|
||||
@@ -30,8 +30,8 @@ else()
|
||||
set(CMAKE_${lang}_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN "--gcc-toolchain=")
|
||||
endif()
|
||||
|
||||
set(_CMAKE_IPO_SUPPORTED_BY_CMAKE YES)
|
||||
set(_CMAKE_IPO_MAY_BE_SUPPORTED_BY_COMPILER YES)
|
||||
set(_CMAKE_${lang}_IPO_SUPPORTED_BY_CMAKE YES)
|
||||
set(_CMAKE_${lang}_IPO_MAY_BE_SUPPORTED_BY_COMPILER YES)
|
||||
|
||||
string(COMPARE EQUAL "${CMAKE_${lang}_COMPILER_ID}" "AppleClang" __is_apple_clang)
|
||||
|
||||
|
||||
@@ -48,14 +48,14 @@ macro(__compiler_gnu lang)
|
||||
set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-isystem ")
|
||||
endif()
|
||||
|
||||
set(_CMAKE_IPO_SUPPORTED_BY_CMAKE YES)
|
||||
set(_CMAKE_IPO_MAY_BE_SUPPORTED_BY_COMPILER NO)
|
||||
set(_CMAKE_${lang}_IPO_SUPPORTED_BY_CMAKE YES)
|
||||
set(_CMAKE_${lang}_IPO_MAY_BE_SUPPORTED_BY_COMPILER NO)
|
||||
|
||||
# '-flto' introduced since GCC 4.5:
|
||||
# * https://gcc.gnu.org/onlinedocs/gcc-4.4.7/gcc/Option-Summary.html (no)
|
||||
# * 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_IPO_MAY_BE_SUPPORTED_BY_COMPILER YES)
|
||||
set(_CMAKE_${lang}_IPO_MAY_BE_SUPPORTED_BY_COMPILER YES)
|
||||
set(__lto_flags -flto)
|
||||
|
||||
if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 4.7)
|
||||
|
||||
@@ -13,8 +13,8 @@ macro(__compiler_qcc lang)
|
||||
set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-Wp,-isystem,")
|
||||
set(CMAKE_DEPFILE_FLAGS_${lang} "-Wc,-MD,<DEPFILE>,-MT,<OBJECT>,-MF,<DEPFILE>")
|
||||
|
||||
set(_CMAKE_IPO_SUPPORTED_BY_CMAKE NO)
|
||||
set(_CMAKE_IPO_MAY_BE_SUPPORTED_BY_COMPILER NO)
|
||||
set(_CMAKE_${lang}_IPO_SUPPORTED_BY_CMAKE NO)
|
||||
set(_CMAKE_${lang}_IPO_MAY_BE_SUPPORTED_BY_COMPILER NO)
|
||||
|
||||
unset(CMAKE_${lang}_COMPILE_OPTIONS_IPO)
|
||||
unset(CMAKE_${lang}_ARCHIVE_CREATE_IPO)
|
||||
|
||||
@@ -30,7 +30,7 @@ macro(__linux_compiler_intel lang)
|
||||
# executables that use dlopen but do not set ENABLE_EXPORTS.
|
||||
set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "-rdynamic")
|
||||
|
||||
set(_CMAKE_IPO_SUPPORTED_BY_CMAKE YES)
|
||||
set(_CMAKE_${lang}_IPO_SUPPORTED_BY_CMAKE YES)
|
||||
|
||||
if(XIAR)
|
||||
# INTERPROCEDURAL_OPTIMIZATION
|
||||
@@ -38,10 +38,10 @@ macro(__linux_compiler_intel lang)
|
||||
set(CMAKE_${lang}_CREATE_STATIC_LIBRARY_IPO
|
||||
"${XIAR} cr <TARGET> <LINK_FLAGS> <OBJECTS> "
|
||||
"${XIAR} -s <TARGET> ")
|
||||
set(_CMAKE_IPO_MAY_BE_SUPPORTED_BY_COMPILER YES)
|
||||
set(_CMAKE_IPO_LEGACY_BEHAVIOR YES)
|
||||
set(_CMAKE_${lang}_IPO_MAY_BE_SUPPORTED_BY_COMPILER YES)
|
||||
set(_CMAKE_${lang}_IPO_LEGACY_BEHAVIOR YES)
|
||||
else()
|
||||
set(_CMAKE_IPO_MAY_BE_SUPPORTED_BY_COMPILER NO)
|
||||
set(_CMAKE_${lang}_IPO_MAY_BE_SUPPORTED_BY_COMPILER NO)
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 12.0)
|
||||
|
||||
Reference in New Issue
Block a user