diff options
author | Brad King <brad.king@kitware.com> | 2022-06-09 16:23:42 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2022-06-10 13:12:43 (GMT) |
commit | ec08bc17526a7e22c1a18d5262ca0ca0c391ec6e (patch) | |
tree | e33877fe390be5eb20055badeb8edd4b35a7c6d0 /Modules | |
parent | 7d73e88d3a7490cf1047369da8292a57c0b60bce (diff) | |
download | CMake-ec08bc17526a7e22c1a18d5262ca0ca0c391ec6e.zip CMake-ec08bc17526a7e22c1a18d5262ca0ca0c391ec6e.tar.gz CMake-ec08bc17526a7e22c1a18d5262ca0ca0c391ec6e.tar.bz2 |
CheckIPOSupported: Compile check using flags of calling project
Forward `CMAKE_<LANG>_FLAGS` and `CMAKE_<LANG>_FLAGS_DEBUG` from the
calling project into the test project. The set of flags may affect the
availability of IPO support. Since this may change the result of the
check for existing projects, add a policy for compatibility.
This was discovered after commit 5fcadc481e (MSVC: Default to -ZI
instead of /Zi for x86 and x64, 2022-05-24) introduced policy CMP0138 to
switch our default for MSVC's debug info flag. The `-ZI` flag is
incompatible with the `-GL` flag used for IPO, so CMP0138 was reverted
pending future work on an alternative solution. Re-use the CMP0138
policy number for this change to CheckIPOSupported instead.
Fixes: #23607
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/CheckIPOSupported.cmake | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Modules/CheckIPOSupported.cmake b/Modules/CheckIPOSupported.cmake index 0bc3c92..cca1be9 100644 --- a/Modules/CheckIPOSupported.cmake +++ b/Modules/CheckIPOSupported.cmake @@ -36,6 +36,11 @@ module will return error in this case. See policy :policy:`CMP0069` for details. .. versionadded:: 3.13 Add support for Visual Studio generators. +.. versionadded:: 3.24 + The check uses the caller's :variable:`CMAKE_<LANG>_FLAGS` + and :variable:`CMAKE_<LANG>_FLAGS_<CONFIG>` values. + See policy :policy:`CMP0138`. + Examples ^^^^^^^^ @@ -117,6 +122,16 @@ macro(_ipo_run_language_check language) ) endforeach() + if(ipo_CMP0138 STREQUAL "NEW") + set(CMAKE_TRY_COMPILE_CONFIGURATION Debug) + set(_CMAKE_LANG_FLAGS + "-DCMAKE_${language}_FLAGS:STRING=${CMAKE_${language}_FLAGS}" + "-DCMAKE_${language}_FLAGS_DEBUG:STRING=${CMAKE_${language}_FLAGS_DEBUG}" + ) + else() + set(_CMAKE_LANG_FLAGS "") + endif() + try_compile( _IPO_LANGUAGE_CHECK_RESULT "${bindir}" @@ -125,6 +140,7 @@ macro(_ipo_run_language_check language) CMAKE_FLAGS "-DCMAKE_VERBOSE_MAKEFILE=ON" "-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON" + ${_CMAKE_LANG_FLAGS} OUTPUT_VARIABLE output ) set(_IPO_LANGUAGE_CHECK_RESULT "${_IPO_LANGUAGE_CHECK_RESULT}") @@ -155,6 +171,11 @@ function(check_ipo_supported) message(FATAL_ERROR "Policy CMP0069 set to OLD") endif() + # Save policy setting for condition in _ipo_run_language_check. + cmake_policy(GET CMP0138 ipo_CMP0138 + PARENT_SCOPE # undocumented, do not use outside of CMake + ) + set(optional) set(one RESULT OUTPUT) set(multiple LANGUAGES) |