From cd92cbae7e817ba649a6c563b1bb63764a4c0c65 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 4 Dec 2025 11:02:28 -0500 Subject: MSVC: Restore pre-4.2 default PDB paths Only force a compile PDB directory when PCH reusing. This avoids affecting behavior in unrelated situations. However, PCH reuse requires a known path so that the `copy_idb_pdb` logic can accurately generate the copy instructions so that MSVC's rule that PCH use must use the same PDB file can be adhered to. Also revert the test suite adaptations from commit f78f592b78 (pchreuse: defer target existence enforcement to generation time, 2025-06-16, v4.2.0-rc1~481^2~4). Fixes: #27401 --- Source/cmGeneratorTarget.cxx | 16 ++++++++++------ Tests/PDBDirectoryAndName/CMakeLists.txt | 12 +----------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 3ff37b8..a59186c 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -1312,15 +1312,17 @@ 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) { + // If the target is PCH-reused or PCH-reuses, we need a stable name for the + // PDB file so that reusing targets can construct a stable name for it. + cmGeneratorTarget const* reuseTarget = this->GetPchReuseTarget(); + bool const hasReuse = reuseTarget && reuseTarget != this; + if (this->PchReused || hasReuse) { NameComponents const& components = GetFullNameInternalComponents( config, cmStateEnums::RuntimeBinaryArtifact); return cmStrCat(components.prefix, this->GetName(), ".pdb"); } - return ""; + return std::string{}; } std::string cmGeneratorTarget::GetCompilePDBPath( @@ -4657,8 +4659,10 @@ bool cmGeneratorTarget::ComputePDBOutputDir(std::string const& kind, } } if (out.empty()) { - // Compile output should always have a path. - if (kind == "COMPILE_PDB"_s) { + cmGeneratorTarget const* reuseTarget = this->GetPchReuseTarget(); + bool const hasReuse = reuseTarget && reuseTarget != this; + // Compiler-generated PDB output always needed for REUSE_FROM. + if (kind == "COMPILE_PDB"_s && (this->PchReused || hasReuse)) { out = this->GetSupportDirectory(); } else { return false; diff --git a/Tests/PDBDirectoryAndName/CMakeLists.txt b/Tests/PDBDirectoryAndName/CMakeLists.txt index 9f98a7e..de287d8 100644 --- a/Tests/PDBDirectoryAndName/CMakeLists.txt +++ b/Tests/PDBDirectoryAndName/CMakeLists.txt @@ -76,26 +76,16 @@ endif() set(pdbs "") foreach(t ${my_targets}) - set(with_compile 0) get_property(pdb_name TARGET ${t} PROPERTY PDB_NAME) get_property(pdb_dir TARGET ${t} PROPERTY PDB_OUTPUT_DIRECTORY) if(NOT pdb_name) - set(with_compile 1) get_property(pdb_name TARGET ${t} PROPERTY COMPILE_PDB_NAME) endif() if(NOT pdb_dir) get_property(pdb_dir TARGET ${t} PROPERTY COMPILE_PDB_OUTPUT_DIRECTORY) endif() if(NOT pdb_dir) - if (NOT with_compile) - set(pdb_dir ${CMAKE_CURRENT_BINARY_DIR}) - elseif (CMAKE_GENERATOR MATCHES "Ninja|Makefiles|FASTBuild") - set(pdb_dir ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${t}.dir) - elseif (CMAKE_GENERATOR MATCHES "Visual Studio") - set(pdb_dir ${CMAKE_CURRENT_BINARY_DIR}/${t}.dir) - else () - set(pdb_dir ${CMAKE_CURRENT_BINARY_DIR}/${t}.dir) - endif () + set(pdb_dir ${CMAKE_CURRENT_BINARY_DIR}) endif() if (pdb_dir MATCHES "\\$<.*>") # Skip per-configuration subdirectory if the value contained -- cgit v0.12