From 809e387a132bb78471ec591cc33a6498b504c1df Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 2 Dec 2025 16:40:22 -0500 Subject: [PATCH] cmGeneratorTarget: Revert "always provide a compile PDB filename" Revert commit 1a8712d31a (cmGeneratorTarget: always provide a compile PDB filename, 2025-11-24). It changed our long-standing conditions for when a naming a compiler-generated `.pdb` file is explicitly named. It also caused some `BuildDepends` and `RunCMake.BuildDepends` failures in VS builds that went unnoticed before merging. Issue: #27401 --- Source/cmGeneratorTarget.cxx | 13 +++++++++---- Tests/MSVCDebugInformationFormat/CMakeLists.txt | 8 -------- .../PdbCompileFileName.c | 15 --------------- 3 files changed, 9 insertions(+), 27 deletions(-) delete mode 100644 Tests/MSVCDebugInformationFormat/PdbCompileFileName.c diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 2fdf06098d..3ff37b8df1 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -1312,10 +1312,15 @@ std::string cmGeneratorTarget::GetCompilePDBName( return components.prefix + pdbName + ".pdb"; } - // Always use a name for the compile-time database. - NameComponents const& components = - GetFullNameInternalComponents(config, cmStateEnums::RuntimeBinaryArtifact); - return cmStrCat(components.prefix, this->GetName(), ".pdb"); + // If the target is PCH-reused, we need a stable name for the PDB file so + // that reusing targets can construct a stable name for it. + if (this->PchReused) { + NameComponents const& components = GetFullNameInternalComponents( + config, cmStateEnums::RuntimeBinaryArtifact); + return cmStrCat(components.prefix, this->GetName(), ".pdb"); + } + + return ""; } std::string cmGeneratorTarget::GetCompilePDBPath( diff --git a/Tests/MSVCDebugInformationFormat/CMakeLists.txt b/Tests/MSVCDebugInformationFormat/CMakeLists.txt index 4b3f28092d..b09bc6c416 100644 --- a/Tests/MSVCDebugInformationFormat/CMakeLists.txt +++ b/Tests/MSVCDebugInformationFormat/CMakeLists.txt @@ -79,11 +79,3 @@ endif() if(CMake_TEST_Fortran) verify(Fortran verify.F90) endif() - -# Issue 27401; 4.2.0 regression -add_library(PdbCompileFileName PdbCompileFileName.c) -target_compile_definitions(PdbCompileFileName - PRIVATE - "TARGET_DIRECTORY=\"$\"") -set_property(TARGET PdbCompileFileName PROPERTY - MSVC_DEBUG_INFORMATION_FORMAT "ProgramDatabase") diff --git a/Tests/MSVCDebugInformationFormat/PdbCompileFileName.c b/Tests/MSVCDebugInformationFormat/PdbCompileFileName.c deleted file mode 100644 index 6c7678b751..0000000000 --- a/Tests/MSVCDebugInformationFormat/PdbCompileFileName.c +++ /dev/null @@ -1,15 +0,0 @@ -#include - -int main(int argc, char* argv[]) -{ - int ret = 0; - char const* fname = TARGET_DIRECTORY "/PdbCompileFileName.pdb"; - FILE* f = fopen(fname, "r"); - if (f) { - fclose(f); - } else { - printf("Failed to open PDB file '%s'\n", fname); - ret = 1; - } - return ret; -}