mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-18 17:31:57 +08:00
cmGeneratorTarget: factor out reuse target computation
This commit is contained in:
@@ -2799,6 +2799,26 @@ std::string cmGeneratorTarget::GetClangTidyExportFixesDirectory(
|
||||
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::string const& config, std::string const& lang) const
|
||||
{
|
||||
@@ -2826,24 +2846,21 @@ std::string cmGeneratorTarget::GetPchHeader(std::string const& config,
|
||||
return std::string();
|
||||
}
|
||||
cmGeneratorTarget const* generatorTarget = this;
|
||||
cmValue pchReuseFrom =
|
||||
generatorTarget->GetProperty("PRECOMPILE_HEADERS_REUSE_FROM");
|
||||
cmGeneratorTarget const* reuseTarget = this->GetPchReuseTarget();
|
||||
if (reuseTarget) {
|
||||
generatorTarget = reuseTarget;
|
||||
}
|
||||
|
||||
auto const inserted =
|
||||
this->PchHeaders.insert(std::make_pair(language + config + arch, ""));
|
||||
if (inserted.second) {
|
||||
std::vector<BT<std::string>> const headers =
|
||||
this->GetPrecompileHeaders(config, language);
|
||||
if (headers.empty() && !pchReuseFrom) {
|
||||
if (headers.empty() && !reuseTarget) {
|
||||
return std::string();
|
||||
}
|
||||
std::string& filename = inserted.first->second;
|
||||
|
||||
if (pchReuseFrom) {
|
||||
generatorTarget =
|
||||
this->GetGlobalGenerator()->FindGeneratorTarget(*pchReuseFrom);
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> const languageToExtension = {
|
||||
{ "C", ".h" },
|
||||
{ "CXX", ".hxx" },
|
||||
@@ -2862,7 +2879,7 @@ std::string cmGeneratorTarget::GetPchHeader(std::string const& config,
|
||||
languageToExtension.at(language));
|
||||
|
||||
std::string const filename_tmp = cmStrCat(filename, ".tmp");
|
||||
if (!pchReuseFrom) {
|
||||
if (!reuseTarget) {
|
||||
cmValue pchPrologue =
|
||||
this->Makefile->GetDefinition("CMAKE_PCH_PROLOGUE");
|
||||
cmValue pchEpilogue =
|
||||
@@ -2937,11 +2954,9 @@ std::string cmGeneratorTarget::GetPchSource(std::string const& config,
|
||||
std::string& filename = inserted.first->second;
|
||||
|
||||
cmGeneratorTarget const* generatorTarget = this;
|
||||
cmValue pchReuseFrom =
|
||||
generatorTarget->GetProperty("PRECOMPILE_HEADERS_REUSE_FROM");
|
||||
if (pchReuseFrom) {
|
||||
generatorTarget =
|
||||
this->GetGlobalGenerator()->FindGeneratorTarget(*pchReuseFrom);
|
||||
cmGeneratorTarget const* reuseTarget = this->GetPchReuseTarget();
|
||||
if (reuseTarget) {
|
||||
generatorTarget = reuseTarget;
|
||||
}
|
||||
|
||||
filename =
|
||||
@@ -2968,7 +2983,7 @@ std::string cmGeneratorTarget::GetPchSource(std::string const& config,
|
||||
}
|
||||
|
||||
std::string const filename_tmp = cmStrCat(filename, ".tmp");
|
||||
if (!pchReuseFrom) {
|
||||
if (!reuseTarget) {
|
||||
{
|
||||
cmGeneratedFileStream file(filename_tmp);
|
||||
file << "/* generated by CMake */\n";
|
||||
@@ -3034,11 +3049,9 @@ std::string cmGeneratorTarget::GetPchFile(std::string const& config,
|
||||
};
|
||||
|
||||
cmGeneratorTarget* generatorTarget = this;
|
||||
cmValue pchReuseFrom =
|
||||
generatorTarget->GetProperty("PRECOMPILE_HEADERS_REUSE_FROM");
|
||||
if (pchReuseFrom) {
|
||||
generatorTarget =
|
||||
this->GetGlobalGenerator()->FindGeneratorTarget(*pchReuseFrom);
|
||||
cmGeneratorTarget* reuseTarget = this->GetPchReuseTarget();
|
||||
if (reuseTarget) {
|
||||
generatorTarget = reuseTarget;
|
||||
}
|
||||
|
||||
std::string const pchFileObject =
|
||||
|
@@ -692,6 +692,8 @@ public:
|
||||
std::vector<BT<std::string>> GetPrecompileHeaders(
|
||||
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::string const& lang) const;
|
||||
std::string GetPchHeader(std::string const& config,
|
||||
|
Reference in New Issue
Block a user