1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-19 11:18:40 +08:00

cmGeneratorTarget: factor out reuse target computation

This commit is contained in:
Ben Boeckel
2025-06-15 00:22:26 +02:00
parent 99bdf2ae16
commit 6e7da8aa95
2 changed files with 35 additions and 20 deletions

View File

@@ -2799,6 +2799,26 @@ std::string cmGeneratorTarget::GetClangTidyExportFixesDirectory(
return cmSystemTools::CollapseFullPath(path); return cmSystemTools::CollapseFullPath(path);
} }
cmGeneratorTarget const* cmGeneratorTarget::GetPchReuseTarget() const
{
cmValue pchReuseFrom = this->GetProperty("PRECOMPILE_HEADERS_REUSE_FROM");
if (!pchReuseFrom) {
return nullptr;
}
// Guaranteed to exist because `SetProperty` does a target lookup.
return this->GetGlobalGenerator()->FindGeneratorTarget(*pchReuseFrom);
}
cmGeneratorTarget* cmGeneratorTarget::GetPchReuseTarget()
{
cmValue pchReuseFrom = this->GetProperty("PRECOMPILE_HEADERS_REUSE_FROM");
if (!pchReuseFrom) {
return nullptr;
}
// Guaranteed to exist because `SetProperty` does a target lookup.
return this->GetGlobalGenerator()->FindGeneratorTarget(*pchReuseFrom);
}
std::vector<std::string> cmGeneratorTarget::GetPchArchs( std::vector<std::string> cmGeneratorTarget::GetPchArchs(
std::string const& config, std::string const& lang) const std::string const& config, std::string const& lang) const
{ {
@@ -2826,24 +2846,21 @@ std::string cmGeneratorTarget::GetPchHeader(std::string const& config,
return std::string(); return std::string();
} }
cmGeneratorTarget const* generatorTarget = this; cmGeneratorTarget const* generatorTarget = this;
cmValue pchReuseFrom = cmGeneratorTarget const* reuseTarget = this->GetPchReuseTarget();
generatorTarget->GetProperty("PRECOMPILE_HEADERS_REUSE_FROM"); if (reuseTarget) {
generatorTarget = reuseTarget;
}
auto const inserted = auto const inserted =
this->PchHeaders.insert(std::make_pair(language + config + arch, "")); this->PchHeaders.insert(std::make_pair(language + config + arch, ""));
if (inserted.second) { if (inserted.second) {
std::vector<BT<std::string>> const headers = std::vector<BT<std::string>> const headers =
this->GetPrecompileHeaders(config, language); this->GetPrecompileHeaders(config, language);
if (headers.empty() && !pchReuseFrom) { if (headers.empty() && !reuseTarget) {
return std::string(); return std::string();
} }
std::string& filename = inserted.first->second; std::string& filename = inserted.first->second;
if (pchReuseFrom) {
generatorTarget =
this->GetGlobalGenerator()->FindGeneratorTarget(*pchReuseFrom);
}
std::map<std::string, std::string> const languageToExtension = { std::map<std::string, std::string> const languageToExtension = {
{ "C", ".h" }, { "C", ".h" },
{ "CXX", ".hxx" }, { "CXX", ".hxx" },
@@ -2862,7 +2879,7 @@ std::string cmGeneratorTarget::GetPchHeader(std::string const& config,
languageToExtension.at(language)); languageToExtension.at(language));
std::string const filename_tmp = cmStrCat(filename, ".tmp"); std::string const filename_tmp = cmStrCat(filename, ".tmp");
if (!pchReuseFrom) { if (!reuseTarget) {
cmValue pchPrologue = cmValue pchPrologue =
this->Makefile->GetDefinition("CMAKE_PCH_PROLOGUE"); this->Makefile->GetDefinition("CMAKE_PCH_PROLOGUE");
cmValue pchEpilogue = cmValue pchEpilogue =
@@ -2937,11 +2954,9 @@ std::string cmGeneratorTarget::GetPchSource(std::string const& config,
std::string& filename = inserted.first->second; std::string& filename = inserted.first->second;
cmGeneratorTarget const* generatorTarget = this; cmGeneratorTarget const* generatorTarget = this;
cmValue pchReuseFrom = cmGeneratorTarget const* reuseTarget = this->GetPchReuseTarget();
generatorTarget->GetProperty("PRECOMPILE_HEADERS_REUSE_FROM"); if (reuseTarget) {
if (pchReuseFrom) { generatorTarget = reuseTarget;
generatorTarget =
this->GetGlobalGenerator()->FindGeneratorTarget(*pchReuseFrom);
} }
filename = filename =
@@ -2968,7 +2983,7 @@ std::string cmGeneratorTarget::GetPchSource(std::string const& config,
} }
std::string const filename_tmp = cmStrCat(filename, ".tmp"); std::string const filename_tmp = cmStrCat(filename, ".tmp");
if (!pchReuseFrom) { if (!reuseTarget) {
{ {
cmGeneratedFileStream file(filename_tmp); cmGeneratedFileStream file(filename_tmp);
file << "/* generated by CMake */\n"; file << "/* generated by CMake */\n";
@@ -3034,11 +3049,9 @@ std::string cmGeneratorTarget::GetPchFile(std::string const& config,
}; };
cmGeneratorTarget* generatorTarget = this; cmGeneratorTarget* generatorTarget = this;
cmValue pchReuseFrom = cmGeneratorTarget* reuseTarget = this->GetPchReuseTarget();
generatorTarget->GetProperty("PRECOMPILE_HEADERS_REUSE_FROM"); if (reuseTarget) {
if (pchReuseFrom) { generatorTarget = reuseTarget;
generatorTarget =
this->GetGlobalGenerator()->FindGeneratorTarget(*pchReuseFrom);
} }
std::string const pchFileObject = std::string const pchFileObject =

View File

@@ -692,6 +692,8 @@ public:
std::vector<BT<std::string>> GetPrecompileHeaders( std::vector<BT<std::string>> GetPrecompileHeaders(
std::string const& config, std::string const& language) const; std::string const& config, std::string const& language) const;
cmGeneratorTarget const* GetPchReuseTarget() const;
cmGeneratorTarget* GetPchReuseTarget();
std::vector<std::string> GetPchArchs(std::string const& config, std::vector<std::string> GetPchArchs(std::string const& config,
std::string const& lang) const; std::string const& lang) const;
std::string GetPchHeader(std::string const& config, std::string GetPchHeader(std::string const& config,