From 1a8712d31af6cafa90e5924e65c188b5967aa3e3 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 24 Nov 2025 21:15:50 -0500 Subject: [PATCH] cmGeneratorTarget: always provide a compile PDB filename As of commit f78f592b78 (pchreuse: defer target existence enforcement to generation time, 2025-06-16) via !10887, the compile PDB directory is always set. Some codepaths used the total computation as a signal to build the path themselves. But the filename was not specified, so the resulting filename ended up changing. Always create the filename as expected. Fixes: #27401 --- Source/cmGeneratorTarget.cxx | 13 ++++--------- Tests/MSVCDebugInformationFormat/CMakeLists.txt | 8 ++++++++ .../PdbCompileFileName.c | 15 +++++++++++++++ 3 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 Tests/MSVCDebugInformationFormat/PdbCompileFileName.c diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 3ff37b8df1..2fdf06098d 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -1312,15 +1312,10 @@ std::string cmGeneratorTarget::GetCompilePDBName( return components.prefix + pdbName + ".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 ""; + // Always use a name for the compile-time database. + NameComponents const& components = + GetFullNameInternalComponents(config, cmStateEnums::RuntimeBinaryArtifact); + return cmStrCat(components.prefix, this->GetName(), ".pdb"); } std::string cmGeneratorTarget::GetCompilePDBPath( diff --git a/Tests/MSVCDebugInformationFormat/CMakeLists.txt b/Tests/MSVCDebugInformationFormat/CMakeLists.txt index b09bc6c416..4b3f28092d 100644 --- a/Tests/MSVCDebugInformationFormat/CMakeLists.txt +++ b/Tests/MSVCDebugInformationFormat/CMakeLists.txt @@ -79,3 +79,11 @@ 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 new file mode 100644 index 0000000000..6c7678b751 --- /dev/null +++ b/Tests/MSVCDebugInformationFormat/PdbCompileFileName.c @@ -0,0 +1,15 @@ +#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; +}