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 /Tests | |
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 'Tests')
9 files changed, 42 insertions, 0 deletions
diff --git a/Tests/RunCMake/CheckIPOSupported/CMP0138-Common.cmake b/Tests/RunCMake/CheckIPOSupported/CMP0138-Common.cmake new file mode 100644 index 0000000..508e6c3 --- /dev/null +++ b/Tests/RunCMake/CheckIPOSupported/CMP0138-Common.cmake @@ -0,0 +1,9 @@ +enable_language(C) +string(APPEND CMAKE_C_FLAGS " -DFOO") +string(APPEND CMAKE_C_FLAGS_DEBUG " -DBAR") +check_ipo_supported(RESULT ipo_supported) +file(STRINGS "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/_CMakeLTOTest-C/bin/CMakeCache.txt" + cached_flags REGEX "^CMAKE_C_FLAGS(_DEBUG)?:") +foreach(line IN LISTS cached_flags) + message(STATUS "${line}") +endforeach() diff --git a/Tests/RunCMake/CheckIPOSupported/CMP0138-NEW-stdout.txt b/Tests/RunCMake/CheckIPOSupported/CMP0138-NEW-stdout.txt new file mode 100644 index 0000000..aa150a8 --- /dev/null +++ b/Tests/RunCMake/CheckIPOSupported/CMP0138-NEW-stdout.txt @@ -0,0 +1,5 @@ +-- CMAKE_C_FLAGS:STRING=[^ +]*-DFOO +-- CMAKE_C_FLAGS_DEBUG:STRING=[^ +]*-DBAR +-- diff --git a/Tests/RunCMake/CheckIPOSupported/CMP0138-NEW.cmake b/Tests/RunCMake/CheckIPOSupported/CMP0138-NEW.cmake new file mode 100644 index 0000000..6611504 --- /dev/null +++ b/Tests/RunCMake/CheckIPOSupported/CMP0138-NEW.cmake @@ -0,0 +1,2 @@ +cmake_policy(SET CMP0138 NEW) +include(CMP0138-Common.cmake) diff --git a/Tests/RunCMake/CheckIPOSupported/CMP0138-OLD-stdout.txt b/Tests/RunCMake/CheckIPOSupported/CMP0138-OLD-stdout.txt new file mode 100644 index 0000000..c80b208 --- /dev/null +++ b/Tests/RunCMake/CheckIPOSupported/CMP0138-OLD-stdout.txt @@ -0,0 +1,3 @@ +-- CMAKE_C_FLAGS:STRING=([^-]|-[^D]|-D[^F]|-DF[^O]|-DFO[^O])* +-- CMAKE_C_FLAGS_DEBUG:STRING=([^-]|-[^D]|-D[^B]|-DB[^A]|-DBA[^R])* +-- diff --git a/Tests/RunCMake/CheckIPOSupported/CMP0138-OLD.cmake b/Tests/RunCMake/CheckIPOSupported/CMP0138-OLD.cmake new file mode 100644 index 0000000..b16ac9f --- /dev/null +++ b/Tests/RunCMake/CheckIPOSupported/CMP0138-OLD.cmake @@ -0,0 +1,2 @@ +cmake_policy(SET CMP0138 OLD) +include(CMP0138-Common.cmake) diff --git a/Tests/RunCMake/CheckIPOSupported/CMP0138-WARN-stdout.txt b/Tests/RunCMake/CheckIPOSupported/CMP0138-WARN-stdout.txt new file mode 100644 index 0000000..c80b208 --- /dev/null +++ b/Tests/RunCMake/CheckIPOSupported/CMP0138-WARN-stdout.txt @@ -0,0 +1,3 @@ +-- CMAKE_C_FLAGS:STRING=([^-]|-[^D]|-D[^F]|-DF[^O]|-DFO[^O])* +-- CMAKE_C_FLAGS_DEBUG:STRING=([^-]|-[^D]|-D[^B]|-DB[^A]|-DBA[^R])* +-- diff --git a/Tests/RunCMake/CheckIPOSupported/CMP0138-WARN.cmake b/Tests/RunCMake/CheckIPOSupported/CMP0138-WARN.cmake new file mode 100644 index 0000000..01118ee --- /dev/null +++ b/Tests/RunCMake/CheckIPOSupported/CMP0138-WARN.cmake @@ -0,0 +1,2 @@ +# (leave CMP0138 unset) +include(CMP0138-Common.cmake) diff --git a/Tests/RunCMake/CheckIPOSupported/Inspect.cmake b/Tests/RunCMake/CheckIPOSupported/Inspect.cmake new file mode 100644 index 0000000..07e4258 --- /dev/null +++ b/Tests/RunCMake/CheckIPOSupported/Inspect.cmake @@ -0,0 +1,5 @@ +enable_language(C) +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/info.cmake" " +set(_CMAKE_C_IPO_SUPPORTED_BY_CMAKE \"${_CMAKE_C_IPO_SUPPORTED_BY_CMAKE}\") +set(_CMAKE_C_IPO_MAY_BE_SUPPORTED_BY_COMPILER \"${_CMAKE_C_IPO_MAY_BE_SUPPORTED_BY_COMPILER}\") +") diff --git a/Tests/RunCMake/CheckIPOSupported/RunCMakeTest.cmake b/Tests/RunCMake/CheckIPOSupported/RunCMakeTest.cmake index b7d524c..2fb159e 100644 --- a/Tests/RunCMake/CheckIPOSupported/RunCMakeTest.cmake +++ b/Tests/RunCMake/CheckIPOSupported/RunCMakeTest.cmake @@ -1,5 +1,8 @@ include(RunCMake) +run_cmake(Inspect) +include("${RunCMake_BINARY_DIR}/Inspect-build/info.cmake") + run_cmake(unparsed-arguments) run_cmake(user-lang-unknown) run_cmake(default-lang-none) @@ -8,6 +11,14 @@ run_cmake(not-supported-by-compiler) run_cmake(save-to-result) run_cmake(cmp0069-is-old) +if(_CMAKE_C_IPO_SUPPORTED_BY_CMAKE + AND _CMAKE_C_IPO_MAY_BE_SUPPORTED_BY_COMPILER + AND NOT RunCMake_GENERATOR MATCHES "^Visual Studio 9 ") + run_cmake(CMP0138-WARN) + run_cmake(CMP0138-OLD) + run_cmake(CMP0138-NEW) +endif() + if(RunCMake_GENERATOR MATCHES "^Visual Studio 9 ") run_cmake(not-supported-by-generator) endif() |