mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-04 13:19:51 -05:00
FASTBuild: Fix default MSVC compiler PDB paths
When we pass a PDB output directory to the compiler in a path that requires quoting, the trailing backslash must be escaped to be parsed correctly by the compiler, e.g., `cl /Fd"path\with space\\"`. However, `fbuild` does not parse this correctly when extracting `/Fd`. Work around that bug by using a trailing forward slash in quotes instead.
This commit is contained in:
@@ -68,6 +68,12 @@ std::string const UNITY_BUILD_BATCH_SIZE("UNITY_BUILD_BATCH_SIZE");
|
|||||||
std::string const SKIP_UNITY_BUILD_INCLUSION("SKIP_UNITY_BUILD_INCLUSION");
|
std::string const SKIP_UNITY_BUILD_INCLUSION("SKIP_UNITY_BUILD_INCLUSION");
|
||||||
std::string const UNITY_GROUP("UNITY_GROUP");
|
std::string const UNITY_GROUP("UNITY_GROUP");
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
char const kPATH_SLASH = '\\';
|
||||||
|
#else
|
||||||
|
char const kPATH_SLASH = '/';
|
||||||
|
#endif
|
||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
cmFastbuildNormalTargetGenerator::cmFastbuildNormalTargetGenerator(
|
cmFastbuildNormalTargetGenerator::cmFastbuildNormalTargetGenerator(
|
||||||
@@ -810,24 +816,31 @@ void cmFastbuildNormalTargetGenerator::ComputePaths(
|
|||||||
this->ConvertToFastbuildPath(linkerPDB));
|
this->ConvertToFastbuildPath(linkerPDB));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (GeneratorTarget->GetType() <= cmStateEnums::OBJECT_LIBRARY) {
|
std::string const compilerPDB = this->ComputeTargetCompilePDB(this->Config);
|
||||||
std::string const pdbDir = GeneratorTarget->GetCompilePDBDirectory(Config);
|
if (!compilerPDB.empty()) {
|
||||||
LogMessage("GetCompilePDBDirectory: " + pdbDir);
|
LogMessage("ComputeTargetCompilePDB: " + compilerPDB);
|
||||||
EnsureDirectoryExists(pdbDir);
|
std::string compilerPDBArg = cmSystemTools::ConvertToOutputPath(
|
||||||
std::string pdbName = this->GeneratorTarget->GetCompilePDBName(Config);
|
this->ConvertToFastbuildPath(compilerPDB));
|
||||||
LogMessage("GetCompilePDBName: " + pdbDir);
|
if (cmHasSuffix(compilerPDB, '/')) {
|
||||||
// If we don't have Compiler's PDB, we must add a trailing slash to satisfy
|
// The compiler will choose the .pdb file name.
|
||||||
// MSVC.
|
this->EnsureDirectoryExists(compilerPDB);
|
||||||
bool needTrailingSlash = false;
|
// ConvertToFastbuildPath dropped the trailing slash. Add it back.
|
||||||
if (pdbName.empty()) {
|
// We do this after ConvertToOutputPath so that we can use a forward
|
||||||
needTrailingSlash = true;
|
// slash in the case that the argument is quoted.
|
||||||
}
|
if (cmHasSuffix(compilerPDBArg, '"')) {
|
||||||
std::string const compilerPDB = cmStrCat(pdbDir, '\\', pdbName);
|
// A quoted trailing backslash requires escaping, e.g., `/Fd"dir\\"`,
|
||||||
if (!compilerPDB.empty()) {
|
// but fbuild does not parse such arguments correctly as of 1.15.
|
||||||
target.Variables["CompilerPDB"] = cmSystemTools::ConvertToOutputPath(
|
// Always use a forward slash.
|
||||||
this->ConvertToFastbuildPath(compilerPDB) +
|
compilerPDBArg.insert(compilerPDBArg.size() - 1, 1, '/');
|
||||||
(needTrailingSlash ? "\\ " : ""));
|
} else {
|
||||||
|
// An unquoted trailing slash or backslash is fine.
|
||||||
|
compilerPDBArg.push_back(kPATH_SLASH);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// We have an explicit .pdb path with file name.
|
||||||
|
this->EnsureParentDirectoryExists(compilerPDB);
|
||||||
}
|
}
|
||||||
|
target.Variables["CompilerPDB"] = std::move(compilerPDBArg);
|
||||||
}
|
}
|
||||||
std::string const impLibFullPath =
|
std::string const impLibFullPath =
|
||||||
GeneratorTarget->GetFullPath(Config, cmStateEnums::ImportLibraryArtifact);
|
GeneratorTarget->GetFullPath(Config, cmStateEnums::ImportLibraryArtifact);
|
||||||
|
|||||||
Reference in New Issue
Block a user