CMP0141: Fix PCH REUSE_FROM when MSVC_DEBUG_INFORMATION_FORMAT is empty

Under the policy's NEW behavior, `[CMAKE_]MSVC_DEBUG_INFORMATION_FORMAT`
may be explicitly set to an empty string to tell CMake not to add any
flags for this abstraction.  In this case, fall back to checking the
language-wide flags as we do in the OLD behavior.

This revises commit 183b9a9eca (CMP0141: Fix PCH REUSE_FROM under policy
NEW behavior, 2022-10-31, v3.25.0-rc3~4^2).

Issue: #24106
This commit is contained in:
Brad King
2022-11-15 06:29:53 -05:00
parent 3555265f1d
commit 94164ea55e
3 changed files with 11 additions and 2 deletions

View File

@@ -2677,8 +2677,10 @@ void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target)
bool editAndContinueDebugInfo = false;
bool programDatabaseDebugInfo = false;
if (cm::optional<std::string> msvcDebugInformationFormat =
this->GetMSVCDebugFormatName(config, target)) {
cm::optional<std::string> msvcDebugInformationFormat =
this->GetMSVCDebugFormatName(config, target);
if (msvcDebugInformationFormat &&
!msvcDebugInformationFormat->empty()) {
editAndContinueDebugInfo =
*msvcDebugInformationFormat == "EditAndContinue";
programDatabaseDebugInfo =

View File

@@ -0,0 +1,4 @@
cmake_policy(SET CMP0141 NEW)
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "")
string(APPEND CMAKE_C_FLAGS_DEBUG_INIT " -Zi")
include(PchReuseFrom-common.cmake)

View File

@@ -17,6 +17,9 @@ run_test(SkipPrecompileHeaders)
run_test(CXXnotC)
run_test(PchReuseFrom-CMP0141-OLD)
run_test(PchReuseFrom-CMP0141-NEW)
if(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
run_test(PchReuseFrom-CMP0141-NEW-empty)
endif()
run_test(PchReuseFromPrefixed)
run_test(PchReuseFromSubdir)
run_cmake(PchMultilanguage)