diff options
author | Ben Boeckel <ben.boeckel@kitware.com> | 2023-01-28 15:52:22 (GMT) |
---|---|---|
committer | Ben Boeckel <ben.boeckel@kitware.com> | 2023-01-31 15:07:02 (GMT) |
commit | fd295dd26328c5771c9cf02f495049be844302e0 (patch) | |
tree | 521ef9af947ebe41a53e52fcba211beb454adc2e /Source/cmTarget.cxx | |
parent | b21ab2638fa2d3f4de8280df5165036659b768ab (diff) | |
download | CMake-fd295dd26328c5771c9cf02f495049be844302e0.zip CMake-fd295dd26328c5771c9cf02f495049be844302e0.tar.gz CMake-fd295dd26328c5771c9cf02f495049be844302e0.tar.bz2 |
cmTarget: refactor SOURCES usage requirements
Diffstat (limited to 'Source/cmTarget.cxx')
-rw-r--r-- | Source/cmTarget.cxx | 51 |
1 files changed, 19 insertions, 32 deletions
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index f6a3119..60e72a7 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -305,7 +305,6 @@ public: std::map<std::string, BTs<std::string>> LanguageStandardProperties; std::map<cmTargetExport const*, std::vector<std::string>> InstallIncludeDirectoriesEntries; - std::vector<BT<std::string>> SourceEntries; std::vector<BT<std::string>> LinkOptionsEntries; std::vector<BT<std::string>> LinkDirectoriesEntries; std::vector<BT<std::string>> LinkImplementationPropertyEntries; @@ -322,6 +321,7 @@ public: UsageRequirementProperty CompileFeatures; UsageRequirementProperty CompileDefinitions; UsageRequirementProperty PrecompileHeaders; + UsageRequirementProperty Sources; FileSetType HeadersFileSets; FileSetType CxxModulesFileSets; @@ -363,6 +363,7 @@ cmTargetInternals::cmTargetInternals() , CompileFeatures("COMPILE_FEATURES"_s) , CompileDefinitions("COMPILE_DEFINITIONS"_s) , PrecompileHeaders("PRECOMPILE_HEADERS"_s) + , Sources("SOURCES"_s, UsageRequirementProperty::AppendEmpty::Yes) , HeadersFileSets("HEADERS"_s, "HEADER_DIRS"_s, "HEADER_SET"_s, "HEADER_DIRS_"_s, "HEADER_SET_"_s, "Header"_s, "The default header set"_s, "Header set"_s, @@ -1098,15 +1099,15 @@ void cmTarget::AddPostBuildCommand(cmCustomCommand&& cmd) void cmTarget::AddTracedSources(std::vector<std::string> const& srcs) { if (!srcs.empty()) { - cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); - this->impl->SourceEntries.emplace_back(cmJoin(srcs, ";"), lfbt); + this->impl->Sources.WriteDirect(this->impl.get(), {}, + cmValue(cmJoin(srcs, ";")), + UsageRequirementProperty::Action::Append); } } void cmTarget::AddSources(std::vector<std::string> const& srcs) { - std::string srcFiles; - const char* sep = ""; + std::vector<std::string> srcFiles; for (auto filename : srcs) { if (!cmGeneratorExpression::StartsWithGeneratorExpression(filename)) { if (!filename.empty()) { @@ -1117,14 +1118,9 @@ void cmTarget::AddSources(std::vector<std::string> const& srcs) } this->impl->Makefile->GetOrCreateSource(filename); } - srcFiles += sep; - srcFiles += filename; - sep = ";"; - } - if (!srcFiles.empty()) { - cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); - this->impl->SourceEntries.emplace_back(std::move(srcFiles), lfbt); + srcFiles.emplace_back(filename); } + this->AddTracedSources(srcFiles); } std::string cmTargetInternals::ProcessSourceItemCMP0049( @@ -1228,13 +1224,13 @@ cmSourceFile* cmTarget::AddSource(const std::string& src, bool before) { cmSourceFileLocation sfl(this->impl->Makefile, src, cmSourceFileLocationKind::Known); - if (std::find_if( - this->impl->SourceEntries.begin(), this->impl->SourceEntries.end(), - TargetPropertyEntryFinder(sfl)) == this->impl->SourceEntries.end()) { - cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); - this->impl->SourceEntries.insert(before ? this->impl->SourceEntries.begin() - : this->impl->SourceEntries.end(), - BT<std::string>(src, lfbt)); + auto const& sources = this->impl->Sources.Entries; + if (std::find_if(sources.begin(), sources.end(), + TargetPropertyEntryFinder(sfl)) == sources.end()) { + this->impl->Sources.WriteDirect( + this->impl.get(), {}, cmValue(src), + before ? UsageRequirementProperty::Action::Prepend + : UsageRequirementProperty::Action::Append); } if (cmGeneratorExpression::Find(src) != std::string::npos) { return nullptr; @@ -1487,7 +1483,7 @@ cmBTStringRange cmTarget::GetPrecompileHeadersEntries() const cmBTStringRange cmTarget::GetSourceEntries() const { - return cmMakeRange(this->impl->SourceEntries); + return cmMakeRange(this->impl->Sources.Entries); } cmBTStringRange cmTarget::GetLinkOptionsEntries() const @@ -1649,7 +1645,7 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) UsageRequirementProperty* usageRequirements[] = { &this->impl->IncludeDirectories, &this->impl->CompileOptions, &this->impl->CompileFeatures, &this->impl->CompileDefinitions, - &this->impl->PrecompileHeaders, + &this->impl->PrecompileHeaders, &this->impl->Sources, }; for (auto* usageRequirement : usageRequirements) { @@ -1709,12 +1705,6 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) this->impl->LinkInterfaceDirectExcludePropertyEntries.emplace_back(value, lfbt); } - } else if (prop == propSOURCES) { - this->impl->SourceEntries.clear(); - if (value) { - cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); - this->impl->SourceEntries.emplace_back(value, lfbt); - } } else if (prop == propIMPORTED_GLOBAL) { if (!cmIsOn(value)) { std::ostringstream e; @@ -1833,7 +1823,7 @@ void cmTarget::AppendProperty(const std::string& prop, UsageRequirementProperty* usageRequirements[] = { &this->impl->IncludeDirectories, &this->impl->CompileOptions, &this->impl->CompileFeatures, &this->impl->CompileDefinitions, - &this->impl->PrecompileHeaders, + &this->impl->PrecompileHeaders, &this->impl->Sources, }; for (auto* usageRequirement : usageRequirements) { @@ -1887,9 +1877,6 @@ void cmTarget::AppendProperty(const std::string& prop, this->impl->LinkInterfaceDirectExcludePropertyEntries.emplace_back(value, lfbt); } - } else if (prop == "SOURCES") { - cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); - this->impl->SourceEntries.emplace_back(value, lfbt); } else if (cmHasLiteralPrefix(prop, "IMPORTED_LIBNAME")) { this->impl->Makefile->IssueMessage( MessageType::FATAL_ERROR, prop + " property may not be APPENDed."); @@ -2322,7 +2309,7 @@ cmValue cmTarget::GetProperty(const std::string& prop) const UsageRequirementProperty const* usageRequirements[] = { &this->impl->IncludeDirectories, &this->impl->CompileOptions, &this->impl->CompileFeatures, &this->impl->CompileDefinitions, - &this->impl->PrecompileHeaders, + &this->impl->PrecompileHeaders, &this->impl->Sources, }; for (auto const* usageRequirement : usageRequirements) { |