From b532911c9e4b5cc7ef0c22fe9e232d6677c7cac1 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 26 Jan 2023 22:47:25 -0500 Subject: cmTarget: simplify fileset type property management Instead of copy/pasting conditionals for each fileset type, just make an array of the structures and iterate over them. --- Source/cmTarget.cxx | 72 ++++++++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 37f9e98..59db8fc 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -1544,6 +1544,19 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) return; } + FileSetType* fileSetTypes[] = { + &this->impl->HeadersFileSets, + &this->impl->CxxModulesFileSets, + &this->impl->CxxModuleHeadersFileSets, + }; + + for (auto* fileSetType : fileSetTypes) { + if (fileSetType->WriteProperties(this, this->impl.get(), prop, value, + true)) { + return; + } + } + if (prop == propINCLUDE_DIRECTORIES) { this->impl->IncludeDirectoriesEntries.clear(); if (value) { @@ -1685,15 +1698,6 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) } else { this->impl->LanguageStandardProperties.erase(prop); } - } else if (this->impl->HeadersFileSets.WriteProperties( - this, this->impl.get(), prop, value, true)) { - /* Handled in the `if` condition. */ - } else if (this->impl->CxxModulesFileSets.WriteProperties( - this, this->impl.get(), prop, value, true)) { - /* Handled in the `if` condition. */ - } else if (this->impl->CxxModuleHeadersFileSets.WriteProperties( - this, this->impl.get(), prop, value, true)) { - /* Handled in the `if` condition. */ } else { this->impl->Properties.SetProperty(prop, value); } @@ -1731,6 +1735,20 @@ void cmTarget::AppendProperty(const std::string& prop, this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); return; } + + FileSetType* fileSetTypes[] = { + &this->impl->HeadersFileSets, + &this->impl->CxxModulesFileSets, + &this->impl->CxxModuleHeadersFileSets, + }; + + for (auto* fileSetType : fileSetTypes) { + if (fileSetType->WriteProperties(this, this->impl.get(), prop, value, + false)) { + return; + } + } + if (prop == "INCLUDE_DIRECTORIES") { if (!value.empty()) { cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); @@ -1806,16 +1824,6 @@ void cmTarget::AppendProperty(const std::string& prop, prop == "OBJC_STANDARD" || prop == "OBJCXX_STANDARD") { this->impl->Makefile->IssueMessage( MessageType::FATAL_ERROR, prop + " property may not be appended."); - } else if (this->impl->HeadersFileSets.WriteProperties( - this, this->impl.get(), prop, value, - false)) { // NOLINT(bugprone-branch-clone) - /* Handled in the `if` condition. */ - } else if (this->impl->CxxModulesFileSets.WriteProperties( - this, this->impl.get(), prop, value, false)) { - /* Handled in the `if` condition. */ - } else if (this->impl->CxxModuleHeadersFileSets.WriteProperties( - this, this->impl.get(), prop, value, false)) { - /* Handled in the `if` condition. */ } else { this->impl->Properties.AppendProperty(prop, value, asString); } @@ -2374,21 +2382,17 @@ cmValue cmTarget::GetProperty(const std::string& prop) const // Check fileset properties. { - auto headers = - this->impl->HeadersFileSets.ReadProperties(this, this->impl.get(), prop); - if (headers.first) { - return headers.second; - } - auto cxx_modules = this->impl->CxxModulesFileSets.ReadProperties( - this, this->impl.get(), prop); - if (cxx_modules.first) { - return cxx_modules.second; - } - auto cxx_module_headers = - this->impl->CxxModuleHeadersFileSets.ReadProperties( - this, this->impl.get(), prop); - if (cxx_module_headers.first) { - return cxx_module_headers.second; + FileSetType* fileSetTypes[] = { + &this->impl->HeadersFileSets, + &this->impl->CxxModulesFileSets, + &this->impl->CxxModuleHeadersFileSets, + }; + + for (auto* fileSetType : fileSetTypes) { + auto value = fileSetType->ReadProperties(this, this->impl.get(), prop); + if (value.first) { + return value.second; + } } } -- cgit v0.12 From 90d74fcc852ec9cec0a1d2aa90b581b9c63461e4 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 26 Jan 2023 22:52:33 -0500 Subject: cmTarget: use an enum for the action when writing fileset properties --- Source/cmTarget.cxx | 53 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 59db8fc..04492ba 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -213,9 +213,16 @@ struct FileSetType FileSetEntries SelfEntries; FileSetEntries InterfaceEntries; + enum class Action + { + Set, + Append, + }; + template bool WriteProperties(cmTarget* tgt, cmTargetInternals* impl, - const std::string& prop, ValueType value, bool clear); + const std::string& prop, ValueType value, + Action action); std::pair ReadProperties(cmTarget const* tgt, cmTargetInternals const* impl, const std::string& prop) const; @@ -285,11 +292,13 @@ public: template void AddDirectoryToFileSet(cmTarget* self, std::string const& fileSetName, ValueType value, cm::string_view fileSetType, - cm::string_view description, bool clear); + cm::string_view description, + FileSetType::Action action); template void AddPathToFileSet(cmTarget* self, std::string const& fileSetName, ValueType value, cm::string_view fileSetType, - cm::string_view description, bool clear); + cm::string_view description, + FileSetType::Action action); cmValue GetFileSetDirectories(cmTarget const* self, std::string const& fileSetName, cm::string_view fileSetType) const; @@ -328,17 +337,17 @@ cmTargetInternals::cmTargetInternals() template bool FileSetType::WriteProperties(cmTarget* tgt, cmTargetInternals* impl, const std::string& prop, ValueType value, - bool clear) + Action action) { if (prop == this->DefaultDirectoryProperty) { impl->AddDirectoryToFileSet(tgt, std::string(this->TypeName), value, this->TypeName, this->DefaultDescription, - clear); + action); return true; } if (prop == this->DefaultPathProperty) { impl->AddPathToFileSet(tgt, std::string(this->TypeName), value, - this->TypeName, this->DefaultDescription, clear); + this->TypeName, this->DefaultDescription, action); return true; } if (cmHasPrefix(prop, this->DirectoryPrefix)) { @@ -350,7 +359,8 @@ bool FileSetType::WriteProperties(cmTarget* tgt, cmTargetInternals* impl, } else { impl->AddDirectoryToFileSet( tgt, fileSetName, value, this->TypeName, - cmStrCat(this->ArbitraryDescription, " \"", fileSetName, "\""), clear); + cmStrCat(this->ArbitraryDescription, " \"", fileSetName, "\""), + action); } return true; } @@ -363,7 +373,8 @@ bool FileSetType::WriteProperties(cmTarget* tgt, cmTargetInternals* impl, } else { impl->AddPathToFileSet( tgt, fileSetName, value, this->TypeName, - cmStrCat(this->ArbitraryDescription, " \"", fileSetName, "\""), clear); + cmStrCat(this->ArbitraryDescription, " \"", fileSetName, "\""), + action); } return true; } @@ -1552,7 +1563,7 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) for (auto* fileSetType : fileSetTypes) { if (fileSetType->WriteProperties(this, this->impl.get(), prop, value, - true)) { + FileSetType::Action::Set)) { return; } } @@ -1744,7 +1755,7 @@ void cmTarget::AppendProperty(const std::string& prop, for (auto* fileSetType : fileSetTypes) { if (fileSetType->WriteProperties(this, this->impl.get(), prop, value, - false)) { + FileSetType::Action::Append)) { return; } } @@ -1839,9 +1850,12 @@ void cmTarget::SetProperty(const std::string& prop, cmValue value) } template -void cmTargetInternals::AddDirectoryToFileSet( - cmTarget* self, std::string const& fileSetName, ValueType value, - cm::string_view fileSetType, cm::string_view description, bool clear) +void cmTargetInternals::AddDirectoryToFileSet(cmTarget* self, + std::string const& fileSetName, + ValueType value, + cm::string_view fileSetType, + cm::string_view description, + FileSetType::Action action) { auto* fileSet = self->GetFileSet(fileSetName); if (!fileSet) { @@ -1857,7 +1871,7 @@ void cmTargetInternals::AddDirectoryToFileSet( "\".")); return; } - if (clear) { + if (action == FileSetType::Action::Set) { fileSet->ClearDirectoryEntries(); } if (!StringIsEmpty(value)) { @@ -1867,9 +1881,12 @@ void cmTargetInternals::AddDirectoryToFileSet( } template -void cmTargetInternals::AddPathToFileSet( - cmTarget* self, std::string const& fileSetName, ValueType value, - cm::string_view fileSetType, cm::string_view description, bool clear) +void cmTargetInternals::AddPathToFileSet(cmTarget* self, + std::string const& fileSetName, + ValueType value, + cm::string_view fileSetType, + cm::string_view description, + FileSetType::Action action) { auto* fileSet = self->GetFileSet(fileSetName); if (!fileSet) { @@ -1885,7 +1902,7 @@ void cmTargetInternals::AddPathToFileSet( "\".")); return; } - if (clear) { + if (action == FileSetType::Action::Set) { fileSet->ClearFileEntries(); } if (!StringIsEmpty(value)) { -- cgit v0.12 From c33d7d11626f1407a28744897378119284d27484 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 26 Jan 2023 23:04:31 -0500 Subject: cmTarget: use cmNonempty rather than local implementation --- Source/cmTarget.cxx | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 04492ba..1037af7 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -1492,26 +1492,6 @@ std::string ConvertToString(cmValue value) return std::string(*value); } -template -bool StringIsEmpty(ValueType const& value); - -template <> -bool StringIsEmpty(const char* const& value) -{ - return cmValue::IsEmpty(value); -} - -template <> -bool StringIsEmpty(cmValue const& value) -{ - return value.IsEmpty(); -} - -template <> -bool StringIsEmpty(std::string const& value) -{ - return value.empty(); -} } template @@ -1874,7 +1854,7 @@ void cmTargetInternals::AddDirectoryToFileSet(cmTarget* self, if (action == FileSetType::Action::Set) { fileSet->ClearDirectoryEntries(); } - if (!StringIsEmpty(value)) { + if (cmNonempty(value)) { fileSet->AddDirectoryEntry( BT(value, this->Makefile->GetBacktrace())); } @@ -1905,7 +1885,7 @@ void cmTargetInternals::AddPathToFileSet(cmTarget* self, if (action == FileSetType::Action::Set) { fileSet->ClearFileEntries(); } - if (!StringIsEmpty(value)) { + if (cmNonempty(value)) { fileSet->AddFileEntry( BT(value, this->Makefile->GetBacktrace())); } -- cgit v0.12 From f644fc8acab04fb7d7dd96648d0f153b12e2936b Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 27 Jan 2023 22:41:26 -0500 Subject: cmTarget: introduce a `UsageRequirementProperty` structure This structure will encapsulate the behaviors of usage requirements. There are a number of them now and they all behave very similarly, so try to reduce the code duplication as much as possible. --- Source/cmTarget.cxx | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 1037af7..8388181 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -230,6 +230,50 @@ struct FileSetType void AddFileSet(const std::string& name, cmFileSetVisibility vis, cmListFileBacktrace bt); }; + +struct UsageRequirementProperty +{ + enum class AppendEmpty + { + Yes, + No, + }; + + UsageRequirementProperty(cm::static_string_view name, + AppendEmpty appendEmpty = AppendEmpty::No) + : Name(name) + , AppendBehavior(appendEmpty) + { + } + + void CopyFromDirectory(cmBTStringRange directoryEntries) + { + return cm::append(this->Entries, directoryEntries); + } + + enum class Action + { + Set, + Prepend, + Append, + }; + + template + bool Write(cmTargetInternals const* impl, + cm::optional const& bt, + const std::string& prop, ValueType value, Action action); + template + void WriteDirect(cmTargetInternals const* impl, + cm::optional const& bt, + ValueType value, Action action); + void WriteDirect(BT value, Action action); + std::pair Read(const std::string& prop) const; + + cm::static_string_view const Name; + AppendEmpty const AppendBehavior; + + std::vector> Entries; +}; } class cmTargetInternals @@ -444,6 +488,67 @@ void FileSetType::AddFileSet(const std::string& name, cmFileSetVisibility vis, } } +template +bool UsageRequirementProperty::Write( + cmTargetInternals const* impl, cm::optional const& bt, + const std::string& prop, ValueType value, Action action) +{ + if (prop == this->Name) { + this->WriteDirect(impl, bt, value, action); + return true; + } + return false; +} + +template +void UsageRequirementProperty::WriteDirect( + cmTargetInternals const* impl, cm::optional const& bt, + ValueType value, Action action) +{ + if (action == Action::Set) { + this->Entries.clear(); + } + if (value) { + cmListFileBacktrace lfbt = impl->GetBacktrace(bt); + if (action == Action::Prepend) { + this->Entries.emplace(this->Entries.begin(), value, lfbt); + } else if (action == Action::Set || cmNonempty(value) || + this->AppendBehavior == AppendEmpty::Yes) { + this->Entries.emplace_back(value, lfbt); + } + } +} + +void UsageRequirementProperty::WriteDirect(BT value, + Action action) +{ + if (action == Action::Set) { + this->Entries.clear(); + } + if (action == Action::Prepend) { + this->Entries.emplace(this->Entries.begin(), std::move(value)); + } else { + this->Entries.emplace_back(std::move(value)); + } +} + +std::pair UsageRequirementProperty::Read( + const std::string& prop) const +{ + bool did_read = false; + cmValue value = nullptr; + if (prop == this->Name) { + if (!this->Entries.empty()) { + // Storage to back the returned `cmValue`. + static std::string output; + output = cmJoin(this->Entries, ";"); + value = cmValue(output); + } + did_read = true; + } + return { did_read, value }; +} + namespace { #define SETUP_COMMON_LANGUAGE_PROPERTIES(lang) \ initProp(#lang "_COMPILER_LAUNCHER"); \ -- cgit v0.12 From 91561103dea6831e3f829b4df1bfc03602cdb6c7 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 27 Jan 2023 22:46:36 -0500 Subject: cmTarget: refactor INCLUDE_DIRECTORIES usage requirements --- Source/cmTarget.cxx | 78 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 31 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 8388181..95b0042 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -303,7 +303,6 @@ public: std::set SystemIncludeDirectories; cmTarget::LinkLibraryVectorType OriginalLinkLibraries; std::map> LanguageStandardProperties; - std::vector> IncludeDirectoriesEntries; std::map> InstallIncludeDirectoriesEntries; std::vector> CompileOptionsEntries; @@ -322,6 +321,8 @@ public: std::map FileSets; cmListFileBacktrace Backtrace; + UsageRequirementProperty IncludeDirectories; + FileSetType HeadersFileSets; FileSetType CxxModulesFileSets; FileSetType CxxModuleHeadersFileSets; @@ -357,7 +358,8 @@ public: }; cmTargetInternals::cmTargetInternals() - : HeadersFileSets("HEADERS"_s, "HEADER_DIRS"_s, "HEADER_SET"_s, + : IncludeDirectories("INCLUDE_DIRECTORIES"_s) + , 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, FileSetEntries("HEADER_SETS"_s), @@ -831,8 +833,8 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, if (!this->IsImported()) { // Initialize the INCLUDE_DIRECTORIES property based on the current value // of the same directory property: - cm::append(this->impl->IncludeDirectoriesEntries, - this->impl->Makefile->GetIncludeDirectoriesEntries()); + this->impl->IncludeDirectories.CopyFromDirectory( + this->impl->Makefile->GetIncludeDirectoriesEntries()); { auto const& sysInc = this->impl->Makefile->GetSystemIncludeDirectories(); @@ -1456,7 +1458,7 @@ cmStringRange cmTarget::GetInstallIncludeDirectoriesEntries( cmBTStringRange cmTarget::GetIncludeDirectoriesEntries() const { - return cmMakeRange(this->impl->IncludeDirectoriesEntries); + return cmMakeRange(this->impl->IncludeDirectories.Entries); } cmBTStringRange cmTarget::GetCompileOptionsEntries() const @@ -1640,6 +1642,17 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) return; } + UsageRequirementProperty* usageRequirements[] = { + &this->impl->IncludeDirectories, + }; + + for (auto* usageRequirement : usageRequirements) { + if (usageRequirement->Write(this->impl.get(), {}, prop, value, + UsageRequirementProperty::Action::Set)) { + return; + } + } + FileSetType* fileSetTypes[] = { &this->impl->HeadersFileSets, &this->impl->CxxModulesFileSets, @@ -1653,13 +1666,7 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) } } - if (prop == propINCLUDE_DIRECTORIES) { - this->impl->IncludeDirectoriesEntries.clear(); - if (value) { - cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); - this->impl->IncludeDirectoriesEntries.emplace_back(value, lfbt); - } - } else if (prop == propCOMPILE_OPTIONS) { + if (prop == propCOMPILE_OPTIONS) { this->impl->CompileOptionsEntries.clear(); if (value) { cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); @@ -1832,6 +1839,17 @@ void cmTarget::AppendProperty(const std::string& prop, return; } + UsageRequirementProperty* usageRequirements[] = { + &this->impl->IncludeDirectories, + }; + + for (auto* usageRequirement : usageRequirements) { + if (usageRequirement->Write(this->impl.get(), bt, prop, cmValue(value), + UsageRequirementProperty::Action::Append)) { + return; + } + } + FileSetType* fileSetTypes[] = { &this->impl->HeadersFileSets, &this->impl->CxxModulesFileSets, @@ -1845,12 +1863,7 @@ void cmTarget::AppendProperty(const std::string& prop, } } - if (prop == "INCLUDE_DIRECTORIES") { - if (!value.empty()) { - cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); - this->impl->IncludeDirectoriesEntries.emplace_back(value, lfbt); - } - } else if (prop == "COMPILE_OPTIONS") { + if (prop == "COMPILE_OPTIONS") { if (!value.empty()) { cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); this->impl->CompileOptionsEntries.emplace_back(value, lfbt); @@ -2156,10 +2169,10 @@ void cmTarget::FinalizeTargetConfiguration( void cmTarget::InsertInclude(BT const& entry, bool before) { - auto position = before ? this->impl->IncludeDirectoriesEntries.begin() - : this->impl->IncludeDirectoriesEntries.end(); - - this->impl->IncludeDirectoriesEntries.insert(position, entry); + this->impl->IncludeDirectories.WriteDirect( + entry, + before ? UsageRequirementProperty::Action::Prepend + : UsageRequirementProperty::Action::Append); } void cmTarget::InsertCompileOption(BT const& entry, bool before) @@ -2338,6 +2351,18 @@ cmValue cmTarget::GetProperty(const std::string& prop) const } return cmValue(propertyIter->second.Value); } + + UsageRequirementProperty const* usageRequirements[] = { + &this->impl->IncludeDirectories, + }; + + for (auto const* usageRequirement : usageRequirements) { + auto value = usageRequirement->Read(prop); + if (value.first) { + return value.second; + } + } + if (prop == propLINK_LIBRARIES) { if (this->impl->LinkImplementationPropertyEntries.empty()) { return nullptr; @@ -2379,15 +2404,6 @@ cmValue cmTarget::GetProperty(const std::string& prop) const if (prop == propTYPE) { return cmValue(cmState::GetTargetTypeName(this->GetType())); } - if (prop == propINCLUDE_DIRECTORIES) { - if (this->impl->IncludeDirectoriesEntries.empty()) { - return nullptr; - } - - static std::string output; - output = cmJoin(this->impl->IncludeDirectoriesEntries, ";"); - return cmValue(output); - } if (prop == propCOMPILE_FEATURES) { if (this->impl->CompileFeaturesEntries.empty()) { return nullptr; -- cgit v0.12 From 03b9240d6be072dc67884aa50962454e50f0b8ca Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 28 Jan 2023 10:45:34 -0500 Subject: cmTarget: refactor COMPILE_OPTIONS usage requirements --- Source/cmTarget.cxx | 44 ++++++++++++++------------------------------ 1 file changed, 14 insertions(+), 30 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 95b0042..63860f1 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -305,7 +305,6 @@ public: std::map> LanguageStandardProperties; std::map> InstallIncludeDirectoriesEntries; - std::vector> CompileOptionsEntries; std::vector> CompileFeaturesEntries; std::vector> CompileDefinitionsEntries; std::vector> PrecompileHeadersEntries; @@ -322,6 +321,7 @@ public: cmListFileBacktrace Backtrace; UsageRequirementProperty IncludeDirectories; + UsageRequirementProperty CompileOptions; FileSetType HeadersFileSets; FileSetType CxxModulesFileSets; @@ -359,6 +359,7 @@ public: cmTargetInternals::cmTargetInternals() : IncludeDirectories("INCLUDE_DIRECTORIES"_s) + , CompileOptions("COMPILE_OPTIONS"_s) , 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, @@ -842,8 +843,8 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, sysInc.end()); } - cm::append(this->impl->CompileOptionsEntries, - this->impl->Makefile->GetCompileOptionsEntries()); + this->impl->CompileOptions.CopyFromDirectory( + this->impl->Makefile->GetCompileOptionsEntries()); cm::append(this->impl->LinkOptionsEntries, this->impl->Makefile->GetLinkOptionsEntries()); @@ -1463,7 +1464,7 @@ cmBTStringRange cmTarget::GetIncludeDirectoriesEntries() const cmBTStringRange cmTarget::GetCompileOptionsEntries() const { - return cmMakeRange(this->impl->CompileOptionsEntries); + return cmMakeRange(this->impl->CompileOptions.Entries); } cmBTStringRange cmTarget::GetCompileFeaturesEntries() const @@ -1644,6 +1645,7 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) UsageRequirementProperty* usageRequirements[] = { &this->impl->IncludeDirectories, + &this->impl->CompileOptions, }; for (auto* usageRequirement : usageRequirements) { @@ -1666,13 +1668,7 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) } } - if (prop == propCOMPILE_OPTIONS) { - this->impl->CompileOptionsEntries.clear(); - if (value) { - cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); - this->impl->CompileOptionsEntries.emplace_back(value, lfbt); - } - } else if (prop == propCOMPILE_FEATURES) { + if (prop == propCOMPILE_FEATURES) { this->impl->CompileFeaturesEntries.clear(); if (value) { cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); @@ -1841,6 +1837,7 @@ void cmTarget::AppendProperty(const std::string& prop, UsageRequirementProperty* usageRequirements[] = { &this->impl->IncludeDirectories, + &this->impl->CompileOptions, }; for (auto* usageRequirement : usageRequirements) { @@ -1863,12 +1860,7 @@ void cmTarget::AppendProperty(const std::string& prop, } } - if (prop == "COMPILE_OPTIONS") { - if (!value.empty()) { - cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); - this->impl->CompileOptionsEntries.emplace_back(value, lfbt); - } - } else if (prop == "COMPILE_FEATURES") { + if (prop == "COMPILE_FEATURES") { if (!value.empty()) { cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); this->impl->CompileFeaturesEntries.emplace_back(value, lfbt); @@ -2177,10 +2169,10 @@ void cmTarget::InsertInclude(BT const& entry, bool before) void cmTarget::InsertCompileOption(BT const& entry, bool before) { - auto position = before ? this->impl->CompileOptionsEntries.begin() - : this->impl->CompileOptionsEntries.end(); - - this->impl->CompileOptionsEntries.insert(position, entry); + this->impl->CompileOptions.WriteDirect( + entry, + before ? UsageRequirementProperty::Action::Prepend + : UsageRequirementProperty::Action::Append); } void cmTarget::InsertCompileDefinition(BT const& entry) @@ -2354,6 +2346,7 @@ cmValue cmTarget::GetProperty(const std::string& prop) const UsageRequirementProperty const* usageRequirements[] = { &this->impl->IncludeDirectories, + &this->impl->CompileOptions, }; for (auto const* usageRequirement : usageRequirements) { @@ -2413,15 +2406,6 @@ cmValue cmTarget::GetProperty(const std::string& prop) const output = cmJoin(this->impl->CompileFeaturesEntries, ";"); return cmValue(output); } - if (prop == propCOMPILE_OPTIONS) { - if (this->impl->CompileOptionsEntries.empty()) { - return nullptr; - } - - static std::string output; - output = cmJoin(this->impl->CompileOptionsEntries, ";"); - return cmValue(output); - } if (prop == propCOMPILE_DEFINITIONS) { if (this->impl->CompileDefinitionsEntries.empty()) { return nullptr; -- cgit v0.12 From 70555450fef7432c22735b6e61821e299c3e2ce9 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 28 Jan 2023 10:46:51 -0500 Subject: cmTarget: refactor COMPILE_FEATURES usage requirements --- Source/cmTarget.cxx | 34 +++++++++------------------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 63860f1..ce333d6 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -305,7 +305,6 @@ public: std::map> LanguageStandardProperties; std::map> InstallIncludeDirectoriesEntries; - std::vector> CompileFeaturesEntries; std::vector> CompileDefinitionsEntries; std::vector> PrecompileHeadersEntries; std::vector> SourceEntries; @@ -322,6 +321,7 @@ public: UsageRequirementProperty IncludeDirectories; UsageRequirementProperty CompileOptions; + UsageRequirementProperty CompileFeatures; FileSetType HeadersFileSets; FileSetType CxxModulesFileSets; @@ -360,6 +360,7 @@ public: cmTargetInternals::cmTargetInternals() : IncludeDirectories("INCLUDE_DIRECTORIES"_s) , CompileOptions("COMPILE_OPTIONS"_s) + , CompileFeatures("COMPILE_FEATURES"_s) , 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, @@ -977,7 +978,7 @@ void cmTarget::SetLanguageStandardProperty(std::string const& lang, const std::string& feature) { cmListFileBacktrace featureBacktrace; - for (auto const& entry : this->impl->CompileFeaturesEntries) { + for (auto const& entry : this->impl->CompileFeatures.Entries) { if (entry.Value == feature) { featureBacktrace = entry.Backtrace; break; @@ -1469,7 +1470,7 @@ cmBTStringRange cmTarget::GetCompileOptionsEntries() const cmBTStringRange cmTarget::GetCompileFeaturesEntries() const { - return cmMakeRange(this->impl->CompileFeaturesEntries); + return cmMakeRange(this->impl->CompileFeatures.Entries); } cmBTStringRange cmTarget::GetCompileDefinitionsEntries() const @@ -1646,6 +1647,7 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) UsageRequirementProperty* usageRequirements[] = { &this->impl->IncludeDirectories, &this->impl->CompileOptions, + &this->impl->CompileFeatures, }; for (auto* usageRequirement : usageRequirements) { @@ -1668,13 +1670,7 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) } } - if (prop == propCOMPILE_FEATURES) { - this->impl->CompileFeaturesEntries.clear(); - if (value) { - cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); - this->impl->CompileFeaturesEntries.emplace_back(value, lfbt); - } - } else if (prop == propCOMPILE_DEFINITIONS) { + if (prop == propCOMPILE_DEFINITIONS) { this->impl->CompileDefinitionsEntries.clear(); if (value) { cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); @@ -1838,6 +1834,7 @@ void cmTarget::AppendProperty(const std::string& prop, UsageRequirementProperty* usageRequirements[] = { &this->impl->IncludeDirectories, &this->impl->CompileOptions, + &this->impl->CompileFeatures, }; for (auto* usageRequirement : usageRequirements) { @@ -1860,12 +1857,7 @@ void cmTarget::AppendProperty(const std::string& prop, } } - if (prop == "COMPILE_FEATURES") { - if (!value.empty()) { - cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); - this->impl->CompileFeaturesEntries.emplace_back(value, lfbt); - } - } else if (prop == "COMPILE_DEFINITIONS") { + if (prop == "COMPILE_DEFINITIONS") { if (!value.empty()) { cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); this->impl->CompileDefinitionsEntries.emplace_back(value, lfbt); @@ -2347,6 +2339,7 @@ cmValue cmTarget::GetProperty(const std::string& prop) const UsageRequirementProperty const* usageRequirements[] = { &this->impl->IncludeDirectories, &this->impl->CompileOptions, + &this->impl->CompileFeatures, }; for (auto const* usageRequirement : usageRequirements) { @@ -2397,15 +2390,6 @@ cmValue cmTarget::GetProperty(const std::string& prop) const if (prop == propTYPE) { return cmValue(cmState::GetTargetTypeName(this->GetType())); } - if (prop == propCOMPILE_FEATURES) { - if (this->impl->CompileFeaturesEntries.empty()) { - return nullptr; - } - - static std::string output; - output = cmJoin(this->impl->CompileFeaturesEntries, ";"); - return cmValue(output); - } if (prop == propCOMPILE_DEFINITIONS) { if (this->impl->CompileDefinitionsEntries.empty()) { return nullptr; -- cgit v0.12 From 856633677692fd58f4f2483e64d8707b8438fbca Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 28 Jan 2023 10:49:06 -0500 Subject: cmTarget: refactor COMPILE_DEFINITIONS usage requirements --- Source/cmTarget.cxx | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index ce333d6..412df23 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -305,7 +305,6 @@ public: std::map> LanguageStandardProperties; std::map> InstallIncludeDirectoriesEntries; - std::vector> CompileDefinitionsEntries; std::vector> PrecompileHeadersEntries; std::vector> SourceEntries; std::vector> LinkOptionsEntries; @@ -322,6 +321,7 @@ public: UsageRequirementProperty IncludeDirectories; UsageRequirementProperty CompileOptions; UsageRequirementProperty CompileFeatures; + UsageRequirementProperty CompileDefinitions; FileSetType HeadersFileSets; FileSetType CxxModulesFileSets; @@ -361,6 +361,7 @@ cmTargetInternals::cmTargetInternals() : IncludeDirectories("INCLUDE_DIRECTORIES"_s) , CompileOptions("COMPILE_OPTIONS"_s) , CompileFeatures("COMPILE_FEATURES"_s) + , CompileDefinitions("COMPILE_DEFINITIONS"_s) , 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, @@ -1475,7 +1476,7 @@ cmBTStringRange cmTarget::GetCompileFeaturesEntries() const cmBTStringRange cmTarget::GetCompileDefinitionsEntries() const { - return cmMakeRange(this->impl->CompileDefinitionsEntries); + return cmMakeRange(this->impl->CompileDefinitions.Entries); } cmBTStringRange cmTarget::GetPrecompileHeadersEntries() const @@ -1648,6 +1649,7 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) &this->impl->IncludeDirectories, &this->impl->CompileOptions, &this->impl->CompileFeatures, + &this->impl->CompileDefinitions, }; for (auto* usageRequirement : usageRequirements) { @@ -1670,13 +1672,7 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) } } - if (prop == propCOMPILE_DEFINITIONS) { - this->impl->CompileDefinitionsEntries.clear(); - if (value) { - cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); - this->impl->CompileDefinitionsEntries.emplace_back(value, lfbt); - } - } else if (prop == propLINK_OPTIONS) { + if (prop == propLINK_OPTIONS) { this->impl->LinkOptionsEntries.clear(); if (value) { cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); @@ -1835,6 +1831,7 @@ void cmTarget::AppendProperty(const std::string& prop, &this->impl->IncludeDirectories, &this->impl->CompileOptions, &this->impl->CompileFeatures, + &this->impl->CompileDefinitions, }; for (auto* usageRequirement : usageRequirements) { @@ -1857,12 +1854,7 @@ void cmTarget::AppendProperty(const std::string& prop, } } - if (prop == "COMPILE_DEFINITIONS") { - if (!value.empty()) { - cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); - this->impl->CompileDefinitionsEntries.emplace_back(value, lfbt); - } - } else if (prop == "LINK_OPTIONS") { + if (prop == "LINK_OPTIONS") { if (!value.empty()) { cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); this->impl->LinkOptionsEntries.emplace_back(value, lfbt); @@ -2169,7 +2161,8 @@ void cmTarget::InsertCompileOption(BT const& entry, bool before) void cmTarget::InsertCompileDefinition(BT const& entry) { - this->impl->CompileDefinitionsEntries.push_back(entry); + this->impl->CompileDefinitions.WriteDirect( + entry, UsageRequirementProperty::Action::Append); } void cmTarget::InsertLinkOption(BT const& entry, bool before) @@ -2340,6 +2333,7 @@ cmValue cmTarget::GetProperty(const std::string& prop) const &this->impl->IncludeDirectories, &this->impl->CompileOptions, &this->impl->CompileFeatures, + &this->impl->CompileDefinitions, }; for (auto const* usageRequirement : usageRequirements) { @@ -2390,15 +2384,6 @@ cmValue cmTarget::GetProperty(const std::string& prop) const if (prop == propTYPE) { return cmValue(cmState::GetTargetTypeName(this->GetType())); } - if (prop == propCOMPILE_DEFINITIONS) { - if (this->impl->CompileDefinitionsEntries.empty()) { - return nullptr; - } - - static std::string output; - output = cmJoin(this->impl->CompileDefinitionsEntries, ";"); - return cmValue(output); - } if (prop == propLINK_OPTIONS) { if (this->impl->LinkOptionsEntries.empty()) { return nullptr; -- cgit v0.12 From b21ab2638fa2d3f4de8280df5165036659b768ab Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 28 Jan 2023 10:50:29 -0500 Subject: cmTarget: refactor PRECOMPILE_HEADERS usage requirements --- Source/cmTarget.cxx | 66 +++++++++++++++++++---------------------------------- 1 file changed, 23 insertions(+), 43 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 412df23..f6a3119 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -305,7 +305,6 @@ public: std::map> LanguageStandardProperties; std::map> InstallIncludeDirectoriesEntries; - std::vector> PrecompileHeadersEntries; std::vector> SourceEntries; std::vector> LinkOptionsEntries; std::vector> LinkDirectoriesEntries; @@ -322,6 +321,7 @@ public: UsageRequirementProperty CompileOptions; UsageRequirementProperty CompileFeatures; UsageRequirementProperty CompileDefinitions; + UsageRequirementProperty PrecompileHeaders; FileSetType HeadersFileSets; FileSetType CxxModulesFileSets; @@ -362,6 +362,7 @@ cmTargetInternals::cmTargetInternals() , CompileOptions("COMPILE_OPTIONS"_s) , CompileFeatures("COMPILE_FEATURES"_s) , CompileDefinitions("COMPILE_DEFINITIONS"_s) + , PrecompileHeaders("PRECOMPILE_HEADERS"_s) , 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, @@ -1481,7 +1482,7 @@ cmBTStringRange cmTarget::GetCompileDefinitionsEntries() const cmBTStringRange cmTarget::GetPrecompileHeadersEntries() const { - return cmMakeRange(this->impl->PrecompileHeadersEntries); + return cmMakeRange(this->impl->PrecompileHeaders.Entries); } cmBTStringRange cmTarget::GetSourceEntries() const @@ -1646,10 +1647,9 @@ 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->IncludeDirectories, &this->impl->CompileOptions, + &this->impl->CompileFeatures, &this->impl->CompileDefinitions, + &this->impl->PrecompileHeaders, }; for (auto* usageRequirement : usageRequirements) { @@ -1684,12 +1684,6 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); this->impl->LinkDirectoriesEntries.emplace_back(value, lfbt); } - } else if (prop == propPRECOMPILE_HEADERS) { - this->impl->PrecompileHeadersEntries.clear(); - if (value) { - cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); - this->impl->PrecompileHeadersEntries.emplace_back(value, lfbt); - } } else if (prop == propLINK_LIBRARIES) { this->impl->LinkImplementationPropertyEntries.clear(); if (value) { @@ -1826,12 +1820,20 @@ void cmTarget::AppendProperty(const std::string& prop, this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); return; } + if (prop == propPRECOMPILE_HEADERS && + this->GetProperty("PRECOMPILE_HEADERS_REUSE_FROM")) { + std::ostringstream e; + e << "PRECOMPILE_HEADERS_REUSE_FROM property is already set on target " + "(\"" + << this->impl->Name << "\")\n"; + this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); + return; + } UsageRequirementProperty* usageRequirements[] = { - &this->impl->IncludeDirectories, - &this->impl->CompileOptions, - &this->impl->CompileFeatures, - &this->impl->CompileDefinitions, + &this->impl->IncludeDirectories, &this->impl->CompileOptions, + &this->impl->CompileFeatures, &this->impl->CompileDefinitions, + &this->impl->PrecompileHeaders, }; for (auto* usageRequirement : usageRequirements) { @@ -1864,19 +1866,6 @@ void cmTarget::AppendProperty(const std::string& prop, cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); this->impl->LinkDirectoriesEntries.emplace_back(value, lfbt); } - } else if (prop == "PRECOMPILE_HEADERS") { - if (this->GetProperty("PRECOMPILE_HEADERS_REUSE_FROM")) { - std::ostringstream e; - e << "PRECOMPILE_HEADERS_REUSE_FROM property is already set on target " - "(\"" - << this->impl->Name << "\")\n"; - this->impl->Makefile->IssueMessage(MessageType::FATAL_ERROR, e.str()); - return; - } - if (!value.empty()) { - cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); - this->impl->PrecompileHeadersEntries.emplace_back(value, lfbt); - } } else if (prop == "LINK_LIBRARIES") { if (!value.empty()) { cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); @@ -2183,7 +2172,8 @@ void cmTarget::InsertLinkDirectory(BT const& entry, bool before) void cmTarget::InsertPrecompileHeader(BT const& entry) { - this->impl->PrecompileHeadersEntries.push_back(entry); + this->impl->PrecompileHeaders.WriteDirect( + entry, UsageRequirementProperty::Action::Append); } namespace { @@ -2330,10 +2320,9 @@ 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->IncludeDirectories, &this->impl->CompileOptions, + &this->impl->CompileFeatures, &this->impl->CompileDefinitions, + &this->impl->PrecompileHeaders, }; for (auto const* usageRequirement : usageRequirements) { @@ -2420,15 +2409,6 @@ cmValue cmTarget::GetProperty(const std::string& prop) const output = cmJoin(utilities, ";"); return cmValue(output); } - if (prop == propPRECOMPILE_HEADERS) { - if (this->impl->PrecompileHeadersEntries.empty()) { - return nullptr; - } - - static std::string output; - output = cmJoin(this->impl->PrecompileHeadersEntries, ";"); - return cmValue(output); - } if (prop == propIMPORTED) { return this->IsImported() ? cmValue(propTRUE) : cmValue(propFALSE); } -- cgit v0.12 From fd295dd26328c5771c9cf02f495049be844302e0 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 28 Jan 2023 10:52:22 -0500 Subject: cmTarget: refactor SOURCES usage requirements --- Source/cmTarget.cxx | 51 +++++++++++++++++++-------------------------------- 1 file 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> LanguageStandardProperties; std::map> InstallIncludeDirectoriesEntries; - std::vector> SourceEntries; std::vector> LinkOptionsEntries; std::vector> LinkDirectoriesEntries; std::vector> 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 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 const& srcs) { - std::string srcFiles; - const char* sep = ""; + std::vector srcFiles; for (auto filename : srcs) { if (!cmGeneratorExpression::StartsWithGeneratorExpression(filename)) { if (!filename.empty()) { @@ -1117,14 +1118,9 @@ void cmTarget::AddSources(std::vector 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(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) { -- cgit v0.12 From 99e783e735291057ff5c91fff10e13e94d45daeb Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 28 Jan 2023 10:54:25 -0500 Subject: cmTarget: refactor LINK_OPTIONS usage requirements --- Source/cmTarget.cxx | 45 ++++++++++++++------------------------------- 1 file changed, 14 insertions(+), 31 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 60e72a7..9f539f9 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -305,7 +305,6 @@ public: std::map> LanguageStandardProperties; std::map> InstallIncludeDirectoriesEntries; - std::vector> LinkOptionsEntries; std::vector> LinkDirectoriesEntries; std::vector> LinkImplementationPropertyEntries; std::vector> LinkInterfacePropertyEntries; @@ -322,6 +321,7 @@ public: UsageRequirementProperty CompileDefinitions; UsageRequirementProperty PrecompileHeaders; UsageRequirementProperty Sources; + UsageRequirementProperty LinkOptions; FileSetType HeadersFileSets; FileSetType CxxModulesFileSets; @@ -364,6 +364,7 @@ cmTargetInternals::cmTargetInternals() , CompileDefinitions("COMPILE_DEFINITIONS"_s) , PrecompileHeaders("PRECOMPILE_HEADERS"_s) , Sources("SOURCES"_s, UsageRequirementProperty::AppendEmpty::Yes) + , LinkOptions("LINK_OPTIONS"_s) , 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, @@ -849,9 +850,8 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, this->impl->CompileOptions.CopyFromDirectory( this->impl->Makefile->GetCompileOptionsEntries()); - - cm::append(this->impl->LinkOptionsEntries, - this->impl->Makefile->GetLinkOptionsEntries()); + this->impl->LinkOptions.CopyFromDirectory( + this->impl->Makefile->GetLinkOptionsEntries()); cm::append(this->impl->LinkDirectoriesEntries, this->impl->Makefile->GetLinkDirectoriesEntries()); @@ -1488,7 +1488,7 @@ cmBTStringRange cmTarget::GetSourceEntries() const cmBTStringRange cmTarget::GetLinkOptionsEntries() const { - return cmMakeRange(this->impl->LinkOptionsEntries); + return cmMakeRange(this->impl->LinkOptions.Entries); } cmBTStringRange cmTarget::GetLinkDirectoriesEntries() const @@ -1646,6 +1646,7 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) &this->impl->IncludeDirectories, &this->impl->CompileOptions, &this->impl->CompileFeatures, &this->impl->CompileDefinitions, &this->impl->PrecompileHeaders, &this->impl->Sources, + &this->impl->LinkOptions, }; for (auto* usageRequirement : usageRequirements) { @@ -1668,13 +1669,7 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) } } - if (prop == propLINK_OPTIONS) { - this->impl->LinkOptionsEntries.clear(); - if (value) { - cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); - this->impl->LinkOptionsEntries.emplace_back(value, lfbt); - } - } else if (prop == propLINK_DIRECTORIES) { + if (prop == propLINK_DIRECTORIES) { this->impl->LinkDirectoriesEntries.clear(); if (value) { cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); @@ -1824,6 +1819,7 @@ void cmTarget::AppendProperty(const std::string& prop, &this->impl->IncludeDirectories, &this->impl->CompileOptions, &this->impl->CompileFeatures, &this->impl->CompileDefinitions, &this->impl->PrecompileHeaders, &this->impl->Sources, + &this->impl->LinkOptions, }; for (auto* usageRequirement : usageRequirements) { @@ -1846,12 +1842,7 @@ void cmTarget::AppendProperty(const std::string& prop, } } - if (prop == "LINK_OPTIONS") { - if (!value.empty()) { - cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); - this->impl->LinkOptionsEntries.emplace_back(value, lfbt); - } - } else if (prop == "LINK_DIRECTORIES") { + if (prop == "LINK_DIRECTORIES") { if (!value.empty()) { cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); this->impl->LinkDirectoriesEntries.emplace_back(value, lfbt); @@ -2143,10 +2134,10 @@ void cmTarget::InsertCompileDefinition(BT const& entry) void cmTarget::InsertLinkOption(BT const& entry, bool before) { - auto position = before ? this->impl->LinkOptionsEntries.begin() - : this->impl->LinkOptionsEntries.end(); - - this->impl->LinkOptionsEntries.insert(position, entry); + this->impl->LinkOptions.WriteDirect( + entry, + before ? UsageRequirementProperty::Action::Prepend + : UsageRequirementProperty::Action::Append); } void cmTarget::InsertLinkDirectory(BT const& entry, bool before) @@ -2310,6 +2301,7 @@ cmValue cmTarget::GetProperty(const std::string& prop) const &this->impl->IncludeDirectories, &this->impl->CompileOptions, &this->impl->CompileFeatures, &this->impl->CompileDefinitions, &this->impl->PrecompileHeaders, &this->impl->Sources, + &this->impl->LinkOptions, }; for (auto const* usageRequirement : usageRequirements) { @@ -2360,15 +2352,6 @@ cmValue cmTarget::GetProperty(const std::string& prop) const if (prop == propTYPE) { return cmValue(cmState::GetTargetTypeName(this->GetType())); } - if (prop == propLINK_OPTIONS) { - if (this->impl->LinkOptionsEntries.empty()) { - return nullptr; - } - - static std::string output; - output = cmJoin(this->impl->LinkOptionsEntries, ";"); - return cmValue(output); - } if (prop == propLINK_DIRECTORIES) { if (this->impl->LinkDirectoriesEntries.empty()) { return nullptr; -- cgit v0.12 From 4f009d2121ac5f46e21786c7d60eb11e2e33c05d Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 28 Jan 2023 10:55:55 -0500 Subject: cmTarget: refactor LINK_DIRECTORIES usage requirements --- Source/cmTarget.cxx | 49 ++++++++++++++----------------------------------- 1 file changed, 14 insertions(+), 35 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 9f539f9..1055a9a 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -305,7 +305,6 @@ public: std::map> LanguageStandardProperties; std::map> InstallIncludeDirectoriesEntries; - std::vector> LinkDirectoriesEntries; std::vector> LinkImplementationPropertyEntries; std::vector> LinkInterfacePropertyEntries; std::vector> LinkInterfaceDirectPropertyEntries; @@ -322,6 +321,7 @@ public: UsageRequirementProperty PrecompileHeaders; UsageRequirementProperty Sources; UsageRequirementProperty LinkOptions; + UsageRequirementProperty LinkDirectories; FileSetType HeadersFileSets; FileSetType CxxModulesFileSets; @@ -365,6 +365,7 @@ cmTargetInternals::cmTargetInternals() , PrecompileHeaders("PRECOMPILE_HEADERS"_s) , Sources("SOURCES"_s, UsageRequirementProperty::AppendEmpty::Yes) , LinkOptions("LINK_OPTIONS"_s) + , LinkDirectories("LINK_DIRECTORIES"_s) , 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, @@ -852,9 +853,8 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type, this->impl->Makefile->GetCompileOptionsEntries()); this->impl->LinkOptions.CopyFromDirectory( this->impl->Makefile->GetLinkOptionsEntries()); - - cm::append(this->impl->LinkDirectoriesEntries, - this->impl->Makefile->GetLinkDirectoriesEntries()); + this->impl->LinkDirectories.CopyFromDirectory( + this->impl->Makefile->GetLinkDirectoriesEntries()); } if (this->impl->TargetType == cmStateEnums::EXECUTABLE) { @@ -1493,7 +1493,7 @@ cmBTStringRange cmTarget::GetLinkOptionsEntries() const cmBTStringRange cmTarget::GetLinkDirectoriesEntries() const { - return cmMakeRange(this->impl->LinkDirectoriesEntries); + return cmMakeRange(this->impl->LinkDirectories.Entries); } cmBTStringRange cmTarget::GetLinkImplementationEntries() const @@ -1646,7 +1646,7 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) &this->impl->IncludeDirectories, &this->impl->CompileOptions, &this->impl->CompileFeatures, &this->impl->CompileDefinitions, &this->impl->PrecompileHeaders, &this->impl->Sources, - &this->impl->LinkOptions, + &this->impl->LinkOptions, &this->impl->LinkDirectories, }; for (auto* usageRequirement : usageRequirements) { @@ -1669,13 +1669,7 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) } } - if (prop == propLINK_DIRECTORIES) { - this->impl->LinkDirectoriesEntries.clear(); - if (value) { - cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); - this->impl->LinkDirectoriesEntries.emplace_back(value, lfbt); - } - } else if (prop == propLINK_LIBRARIES) { + if (prop == propLINK_LIBRARIES) { this->impl->LinkImplementationPropertyEntries.clear(); if (value) { cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); @@ -1819,7 +1813,7 @@ void cmTarget::AppendProperty(const std::string& prop, &this->impl->IncludeDirectories, &this->impl->CompileOptions, &this->impl->CompileFeatures, &this->impl->CompileDefinitions, &this->impl->PrecompileHeaders, &this->impl->Sources, - &this->impl->LinkOptions, + &this->impl->LinkOptions, &this->impl->LinkDirectories, }; for (auto* usageRequirement : usageRequirements) { @@ -1842,12 +1836,7 @@ void cmTarget::AppendProperty(const std::string& prop, } } - if (prop == "LINK_DIRECTORIES") { - if (!value.empty()) { - cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); - this->impl->LinkDirectoriesEntries.emplace_back(value, lfbt); - } - } else if (prop == "LINK_LIBRARIES") { + if (prop == "LINK_LIBRARIES") { if (!value.empty()) { cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); this->impl->LinkImplementationPropertyEntries.emplace_back(value, lfbt); @@ -2142,10 +2131,10 @@ void cmTarget::InsertLinkOption(BT const& entry, bool before) void cmTarget::InsertLinkDirectory(BT const& entry, bool before) { - auto position = before ? this->impl->LinkDirectoriesEntries.begin() - : this->impl->LinkDirectoriesEntries.end(); - - this->impl->LinkDirectoriesEntries.insert(position, entry); + this->impl->LinkDirectories.WriteDirect( + entry, + before ? UsageRequirementProperty::Action::Prepend + : UsageRequirementProperty::Action::Append); } void cmTarget::InsertPrecompileHeader(BT const& entry) @@ -2301,7 +2290,7 @@ cmValue cmTarget::GetProperty(const std::string& prop) const &this->impl->IncludeDirectories, &this->impl->CompileOptions, &this->impl->CompileFeatures, &this->impl->CompileDefinitions, &this->impl->PrecompileHeaders, &this->impl->Sources, - &this->impl->LinkOptions, + &this->impl->LinkOptions, &this->impl->LinkDirectories, }; for (auto const* usageRequirement : usageRequirements) { @@ -2352,16 +2341,6 @@ cmValue cmTarget::GetProperty(const std::string& prop) const if (prop == propTYPE) { return cmValue(cmState::GetTargetTypeName(this->GetType())); } - if (prop == propLINK_DIRECTORIES) { - if (this->impl->LinkDirectoriesEntries.empty()) { - return nullptr; - } - - static std::string output; - output = cmJoin(this->impl->LinkDirectoriesEntries, ";"); - - return cmValue(output); - } if (prop == propMANUALLY_ADDED_DEPENDENCIES) { if (this->impl->Utilities.empty()) { return nullptr; -- cgit v0.12 From e80689d10199a3f4d09a564bd033004e698b150f Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 28 Jan 2023 10:57:32 -0500 Subject: cmTarget: refactor LINK_LIBRARIES usage requirements --- Source/cmTarget.cxx | 34 +++++++++------------------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 1055a9a..5befa05 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -305,7 +305,6 @@ public: std::map> LanguageStandardProperties; std::map> InstallIncludeDirectoriesEntries; - std::vector> LinkImplementationPropertyEntries; std::vector> LinkInterfacePropertyEntries; std::vector> LinkInterfaceDirectPropertyEntries; std::vector> LinkInterfaceDirectExcludePropertyEntries; @@ -322,6 +321,7 @@ public: UsageRequirementProperty Sources; UsageRequirementProperty LinkOptions; UsageRequirementProperty LinkDirectories; + UsageRequirementProperty LinkLibraries; FileSetType HeadersFileSets; FileSetType CxxModulesFileSets; @@ -366,6 +366,7 @@ cmTargetInternals::cmTargetInternals() , Sources("SOURCES"_s, UsageRequirementProperty::AppendEmpty::Yes) , LinkOptions("LINK_OPTIONS"_s) , LinkDirectories("LINK_DIRECTORIES"_s) + , LinkLibraries("LINK_LIBRARIES"_s) , 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, @@ -1498,7 +1499,7 @@ cmBTStringRange cmTarget::GetLinkDirectoriesEntries() const cmBTStringRange cmTarget::GetLinkImplementationEntries() const { - return cmMakeRange(this->impl->LinkImplementationPropertyEntries); + return cmMakeRange(this->impl->LinkLibraries.Entries); } cmBTStringRange cmTarget::GetLinkInterfaceEntries() const @@ -1647,6 +1648,7 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) &this->impl->CompileFeatures, &this->impl->CompileDefinitions, &this->impl->PrecompileHeaders, &this->impl->Sources, &this->impl->LinkOptions, &this->impl->LinkDirectories, + &this->impl->LinkLibraries, }; for (auto* usageRequirement : usageRequirements) { @@ -1669,13 +1671,7 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) } } - if (prop == propLINK_LIBRARIES) { - this->impl->LinkImplementationPropertyEntries.clear(); - if (value) { - cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); - this->impl->LinkImplementationPropertyEntries.emplace_back(value, lfbt); - } - } else if (prop == propINTERFACE_LINK_LIBRARIES) { + if (prop == propINTERFACE_LINK_LIBRARIES) { this->impl->LinkInterfacePropertyEntries.clear(); if (value) { cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); @@ -1814,6 +1810,7 @@ void cmTarget::AppendProperty(const std::string& prop, &this->impl->CompileFeatures, &this->impl->CompileDefinitions, &this->impl->PrecompileHeaders, &this->impl->Sources, &this->impl->LinkOptions, &this->impl->LinkDirectories, + &this->impl->LinkLibraries, }; for (auto* usageRequirement : usageRequirements) { @@ -1836,12 +1833,7 @@ void cmTarget::AppendProperty(const std::string& prop, } } - if (prop == "LINK_LIBRARIES") { - if (!value.empty()) { - cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); - this->impl->LinkImplementationPropertyEntries.emplace_back(value, lfbt); - } - } else if (prop == propINTERFACE_LINK_LIBRARIES) { + if (prop == propINTERFACE_LINK_LIBRARIES) { if (!value.empty()) { cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); this->impl->LinkInterfacePropertyEntries.emplace_back(value, lfbt); @@ -2051,7 +2043,7 @@ void cmTarget::FinalizeTargetConfiguration( } if (!CheckLinkLibraryPattern("LINK_LIBRARIES"_s, - this->impl->LinkImplementationPropertyEntries, + this->impl->LinkLibraries.Entries, this->GetMakefile()->GetCMakeInstance()) || !CheckLinkLibraryPattern("INTERFACE_LINK_LIBRARIES"_s, this->impl->LinkInterfacePropertyEntries, @@ -2291,6 +2283,7 @@ cmValue cmTarget::GetProperty(const std::string& prop) const &this->impl->CompileFeatures, &this->impl->CompileDefinitions, &this->impl->PrecompileHeaders, &this->impl->Sources, &this->impl->LinkOptions, &this->impl->LinkDirectories, + &this->impl->LinkLibraries, }; for (auto const* usageRequirement : usageRequirements) { @@ -2300,15 +2293,6 @@ cmValue cmTarget::GetProperty(const std::string& prop) const } } - if (prop == propLINK_LIBRARIES) { - if (this->impl->LinkImplementationPropertyEntries.empty()) { - return nullptr; - } - - static std::string output; - output = cmJoin(this->impl->LinkImplementationPropertyEntries, ";"); - return cmValue(output); - } if (prop == propINTERFACE_LINK_LIBRARIES) { if (this->impl->LinkInterfacePropertyEntries.empty()) { return nullptr; -- cgit v0.12 From 15eec07500dfeafaf81536ba08ef82f779831f1c Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 28 Jan 2023 10:59:22 -0500 Subject: cmTarget: refactor INTERFACE_LINK_LIBRARIES usage requirements --- Source/cmTarget.cxx | 37 +++++++++---------------------------- 1 file changed, 9 insertions(+), 28 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 5befa05..84f9871 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -305,7 +305,6 @@ public: std::map> LanguageStandardProperties; std::map> InstallIncludeDirectoriesEntries; - std::vector> LinkInterfacePropertyEntries; std::vector> LinkInterfaceDirectPropertyEntries; std::vector> LinkInterfaceDirectExcludePropertyEntries; std::vector> @@ -322,6 +321,7 @@ public: UsageRequirementProperty LinkOptions; UsageRequirementProperty LinkDirectories; UsageRequirementProperty LinkLibraries; + UsageRequirementProperty InterfaceLinkLibraries; FileSetType HeadersFileSets; FileSetType CxxModulesFileSets; @@ -367,6 +367,7 @@ cmTargetInternals::cmTargetInternals() , LinkOptions("LINK_OPTIONS"_s) , LinkDirectories("LINK_DIRECTORIES"_s) , LinkLibraries("LINK_LIBRARIES"_s) + , InterfaceLinkLibraries("INTERFACE_LINK_LIBRARIES"_s) , 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, @@ -1504,7 +1505,7 @@ cmBTStringRange cmTarget::GetLinkImplementationEntries() const cmBTStringRange cmTarget::GetLinkInterfaceEntries() const { - return cmMakeRange(this->impl->LinkInterfacePropertyEntries); + return cmMakeRange(this->impl->InterfaceLinkLibraries.Entries); } cmBTStringRange cmTarget::GetLinkInterfaceDirectEntries() const @@ -1648,7 +1649,7 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) &this->impl->CompileFeatures, &this->impl->CompileDefinitions, &this->impl->PrecompileHeaders, &this->impl->Sources, &this->impl->LinkOptions, &this->impl->LinkDirectories, - &this->impl->LinkLibraries, + &this->impl->LinkLibraries, &this->impl->InterfaceLinkLibraries, }; for (auto* usageRequirement : usageRequirements) { @@ -1671,13 +1672,7 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) } } - if (prop == propINTERFACE_LINK_LIBRARIES) { - this->impl->LinkInterfacePropertyEntries.clear(); - if (value) { - cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); - this->impl->LinkInterfacePropertyEntries.emplace_back(value, lfbt); - } - } else if (prop == propINTERFACE_LINK_LIBRARIES_DIRECT) { + if (prop == propINTERFACE_LINK_LIBRARIES_DIRECT) { this->impl->LinkInterfaceDirectPropertyEntries.clear(); if (value) { cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); @@ -1810,7 +1805,7 @@ void cmTarget::AppendProperty(const std::string& prop, &this->impl->CompileFeatures, &this->impl->CompileDefinitions, &this->impl->PrecompileHeaders, &this->impl->Sources, &this->impl->LinkOptions, &this->impl->LinkDirectories, - &this->impl->LinkLibraries, + &this->impl->LinkLibraries, &this->impl->InterfaceLinkLibraries, }; for (auto* usageRequirement : usageRequirements) { @@ -1833,12 +1828,7 @@ void cmTarget::AppendProperty(const std::string& prop, } } - if (prop == propINTERFACE_LINK_LIBRARIES) { - if (!value.empty()) { - cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); - this->impl->LinkInterfacePropertyEntries.emplace_back(value, lfbt); - } - } else if (prop == propINTERFACE_LINK_LIBRARIES_DIRECT) { + if (prop == propINTERFACE_LINK_LIBRARIES_DIRECT) { if (!value.empty()) { cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); this->impl->LinkInterfaceDirectPropertyEntries.emplace_back(value, lfbt); @@ -2046,7 +2036,7 @@ void cmTarget::FinalizeTargetConfiguration( this->impl->LinkLibraries.Entries, this->GetMakefile()->GetCMakeInstance()) || !CheckLinkLibraryPattern("INTERFACE_LINK_LIBRARIES"_s, - this->impl->LinkInterfacePropertyEntries, + this->impl->InterfaceLinkLibraries.Entries, this->GetMakefile()->GetCMakeInstance()) || !CheckLinkLibraryPattern("INTERFACE_LINK_LIBRARIES_DIRECT"_s, this->impl->LinkInterfaceDirectPropertyEntries, @@ -2283,7 +2273,7 @@ cmValue cmTarget::GetProperty(const std::string& prop) const &this->impl->CompileFeatures, &this->impl->CompileDefinitions, &this->impl->PrecompileHeaders, &this->impl->Sources, &this->impl->LinkOptions, &this->impl->LinkDirectories, - &this->impl->LinkLibraries, + &this->impl->LinkLibraries, &this->impl->InterfaceLinkLibraries, }; for (auto const* usageRequirement : usageRequirements) { @@ -2293,15 +2283,6 @@ cmValue cmTarget::GetProperty(const std::string& prop) const } } - if (prop == propINTERFACE_LINK_LIBRARIES) { - if (this->impl->LinkInterfacePropertyEntries.empty()) { - return nullptr; - } - - static std::string output; - output = cmJoin(this->impl->LinkInterfacePropertyEntries, ";"); - return cmValue(output); - } if (prop == propINTERFACE_LINK_LIBRARIES_DIRECT) { if (this->impl->LinkInterfaceDirectPropertyEntries.empty()) { return nullptr; -- cgit v0.12 From 332d2f8f528bcd454d36dd162454fdc4802c6b6c Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 28 Jan 2023 11:00:43 -0500 Subject: cmTarget: refactor INTERFACE_LINK_LIBRARIES_DIRECT usage requirements --- Source/cmTarget.cxx | 84 ++++++++++++++++++++++++++--------------------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 84f9871..629ecb8 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -305,7 +305,6 @@ public: std::map> LanguageStandardProperties; std::map> InstallIncludeDirectoriesEntries; - std::vector> LinkInterfaceDirectPropertyEntries; std::vector> LinkInterfaceDirectExcludePropertyEntries; std::vector> TLLCommands; @@ -322,6 +321,7 @@ public: UsageRequirementProperty LinkDirectories; UsageRequirementProperty LinkLibraries; UsageRequirementProperty InterfaceLinkLibraries; + UsageRequirementProperty InterfaceLinkLibrariesDirect; FileSetType HeadersFileSets; FileSetType CxxModulesFileSets; @@ -368,6 +368,7 @@ cmTargetInternals::cmTargetInternals() , LinkDirectories("LINK_DIRECTORIES"_s) , LinkLibraries("LINK_LIBRARIES"_s) , InterfaceLinkLibraries("INTERFACE_LINK_LIBRARIES"_s) + , InterfaceLinkLibrariesDirect("INTERFACE_LINK_LIBRARIES_DIRECT"_s) , 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, @@ -1510,7 +1511,7 @@ cmBTStringRange cmTarget::GetLinkInterfaceEntries() const cmBTStringRange cmTarget::GetLinkInterfaceDirectEntries() const { - return cmMakeRange(this->impl->LinkInterfaceDirectPropertyEntries); + return cmMakeRange(this->impl->InterfaceLinkLibrariesDirect.Entries); } cmBTStringRange cmTarget::GetLinkInterfaceDirectExcludeEntries() const @@ -1645,11 +1646,17 @@ 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->Sources, - &this->impl->LinkOptions, &this->impl->LinkDirectories, - &this->impl->LinkLibraries, &this->impl->InterfaceLinkLibraries, + &this->impl->IncludeDirectories, + &this->impl->CompileOptions, + &this->impl->CompileFeatures, + &this->impl->CompileDefinitions, + &this->impl->PrecompileHeaders, + &this->impl->Sources, + &this->impl->LinkOptions, + &this->impl->LinkDirectories, + &this->impl->LinkLibraries, + &this->impl->InterfaceLinkLibraries, + &this->impl->InterfaceLinkLibrariesDirect, }; for (auto* usageRequirement : usageRequirements) { @@ -1672,13 +1679,7 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) } } - if (prop == propINTERFACE_LINK_LIBRARIES_DIRECT) { - this->impl->LinkInterfaceDirectPropertyEntries.clear(); - if (value) { - cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); - this->impl->LinkInterfaceDirectPropertyEntries.emplace_back(value, lfbt); - } - } else if (prop == propINTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE) { + if (prop == propINTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE) { this->impl->LinkInterfaceDirectExcludePropertyEntries.clear(); if (value) { cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); @@ -1801,11 +1802,17 @@ 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->Sources, - &this->impl->LinkOptions, &this->impl->LinkDirectories, - &this->impl->LinkLibraries, &this->impl->InterfaceLinkLibraries, + &this->impl->IncludeDirectories, + &this->impl->CompileOptions, + &this->impl->CompileFeatures, + &this->impl->CompileDefinitions, + &this->impl->PrecompileHeaders, + &this->impl->Sources, + &this->impl->LinkOptions, + &this->impl->LinkDirectories, + &this->impl->LinkLibraries, + &this->impl->InterfaceLinkLibraries, + &this->impl->InterfaceLinkLibrariesDirect, }; for (auto* usageRequirement : usageRequirements) { @@ -1828,12 +1835,7 @@ void cmTarget::AppendProperty(const std::string& prop, } } - if (prop == propINTERFACE_LINK_LIBRARIES_DIRECT) { - if (!value.empty()) { - cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); - this->impl->LinkInterfaceDirectPropertyEntries.emplace_back(value, lfbt); - } - } else if (prop == propINTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE) { + if (prop == propINTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE) { if (!value.empty()) { cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); this->impl->LinkInterfaceDirectExcludePropertyEntries.emplace_back(value, @@ -2038,9 +2040,10 @@ void cmTarget::FinalizeTargetConfiguration( !CheckLinkLibraryPattern("INTERFACE_LINK_LIBRARIES"_s, this->impl->InterfaceLinkLibraries.Entries, this->GetMakefile()->GetCMakeInstance()) || - !CheckLinkLibraryPattern("INTERFACE_LINK_LIBRARIES_DIRECT"_s, - this->impl->LinkInterfaceDirectPropertyEntries, - this->GetMakefile()->GetCMakeInstance())) { + !CheckLinkLibraryPattern( + "INTERFACE_LINK_LIBRARIES_DIRECT"_s, + this->impl->InterfaceLinkLibrariesDirect.Entries, + this->GetMakefile()->GetCMakeInstance())) { return; } @@ -2269,11 +2272,17 @@ 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->Sources, - &this->impl->LinkOptions, &this->impl->LinkDirectories, - &this->impl->LinkLibraries, &this->impl->InterfaceLinkLibraries, + &this->impl->IncludeDirectories, + &this->impl->CompileOptions, + &this->impl->CompileFeatures, + &this->impl->CompileDefinitions, + &this->impl->PrecompileHeaders, + &this->impl->Sources, + &this->impl->LinkOptions, + &this->impl->LinkDirectories, + &this->impl->LinkLibraries, + &this->impl->InterfaceLinkLibraries, + &this->impl->InterfaceLinkLibrariesDirect, }; for (auto const* usageRequirement : usageRequirements) { @@ -2283,15 +2292,6 @@ cmValue cmTarget::GetProperty(const std::string& prop) const } } - if (prop == propINTERFACE_LINK_LIBRARIES_DIRECT) { - if (this->impl->LinkInterfaceDirectPropertyEntries.empty()) { - return nullptr; - } - - static std::string output; - output = cmJoin(this->impl->LinkInterfaceDirectPropertyEntries, ";"); - return cmValue(output); - } if (prop == propINTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE) { if (this->impl->LinkInterfaceDirectExcludePropertyEntries.empty()) { return nullptr; -- cgit v0.12 From 22b9ce73e76f75c594329e7ca44f2a75bc7ffcbf Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 28 Jan 2023 11:01:14 -0500 Subject: cmTarget: refactor INTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE usage requirements --- Source/cmTarget.cxx | 36 +++++++++--------------------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 629ecb8..e5bda26 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -305,7 +305,6 @@ public: std::map> LanguageStandardProperties; std::map> InstallIncludeDirectoriesEntries; - std::vector> LinkInterfaceDirectExcludePropertyEntries; std::vector> TLLCommands; std::map FileSets; @@ -322,6 +321,7 @@ public: UsageRequirementProperty LinkLibraries; UsageRequirementProperty InterfaceLinkLibraries; UsageRequirementProperty InterfaceLinkLibrariesDirect; + UsageRequirementProperty InterfaceLinkLibrariesDirectExclude; FileSetType HeadersFileSets; FileSetType CxxModulesFileSets; @@ -369,6 +369,8 @@ cmTargetInternals::cmTargetInternals() , LinkLibraries("LINK_LIBRARIES"_s) , InterfaceLinkLibraries("INTERFACE_LINK_LIBRARIES"_s) , InterfaceLinkLibrariesDirect("INTERFACE_LINK_LIBRARIES_DIRECT"_s) + , InterfaceLinkLibrariesDirectExclude( + "INTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE"_s) , 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, @@ -1516,7 +1518,7 @@ cmBTStringRange cmTarget::GetLinkInterfaceDirectEntries() const cmBTStringRange cmTarget::GetLinkInterfaceDirectExcludeEntries() const { - return cmMakeRange(this->impl->LinkInterfaceDirectExcludePropertyEntries); + return cmMakeRange(this->impl->InterfaceLinkLibrariesDirectExclude.Entries); } cmBTStringRange cmTarget::GetHeaderSetsEntries() const @@ -1657,6 +1659,7 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) &this->impl->LinkLibraries, &this->impl->InterfaceLinkLibraries, &this->impl->InterfaceLinkLibrariesDirect, + &this->impl->InterfaceLinkLibrariesDirectExclude, }; for (auto* usageRequirement : usageRequirements) { @@ -1679,14 +1682,7 @@ void cmTarget::StoreProperty(const std::string& prop, ValueType value) } } - if (prop == propINTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE) { - this->impl->LinkInterfaceDirectExcludePropertyEntries.clear(); - if (value) { - cmListFileBacktrace lfbt = this->impl->Makefile->GetBacktrace(); - this->impl->LinkInterfaceDirectExcludePropertyEntries.emplace_back(value, - lfbt); - } - } else if (prop == propIMPORTED_GLOBAL) { + if (prop == propIMPORTED_GLOBAL) { if (!cmIsOn(value)) { std::ostringstream e; e << "IMPORTED_GLOBAL property can't be set to FALSE on targets (\"" @@ -1813,6 +1809,7 @@ void cmTarget::AppendProperty(const std::string& prop, &this->impl->LinkLibraries, &this->impl->InterfaceLinkLibraries, &this->impl->InterfaceLinkLibrariesDirect, + &this->impl->InterfaceLinkLibrariesDirectExclude, }; for (auto* usageRequirement : usageRequirements) { @@ -1835,13 +1832,7 @@ void cmTarget::AppendProperty(const std::string& prop, } } - if (prop == propINTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE) { - if (!value.empty()) { - cmListFileBacktrace lfbt = this->impl->GetBacktrace(bt); - this->impl->LinkInterfaceDirectExcludePropertyEntries.emplace_back(value, - lfbt); - } - } else if (cmHasLiteralPrefix(prop, "IMPORTED_LIBNAME")) { + if (cmHasLiteralPrefix(prop, "IMPORTED_LIBNAME")) { this->impl->Makefile->IssueMessage( MessageType::FATAL_ERROR, prop + " property may not be APPENDed."); } else if (prop == "C_STANDARD" || prop == "CXX_STANDARD" || @@ -2283,6 +2274,7 @@ cmValue cmTarget::GetProperty(const std::string& prop) const &this->impl->LinkLibraries, &this->impl->InterfaceLinkLibraries, &this->impl->InterfaceLinkLibrariesDirect, + &this->impl->InterfaceLinkLibrariesDirectExclude, }; for (auto const* usageRequirement : usageRequirements) { @@ -2292,16 +2284,6 @@ cmValue cmTarget::GetProperty(const std::string& prop) const } } - if (prop == propINTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE) { - if (this->impl->LinkInterfaceDirectExcludePropertyEntries.empty()) { - return nullptr; - } - - static std::string output; - output = - cmJoin(this->impl->LinkInterfaceDirectExcludePropertyEntries, ";"); - return cmValue(output); - } // the type property returns what type the target is if (prop == propTYPE) { return cmValue(cmState::GetTargetTypeName(this->GetType())); -- cgit v0.12 From 33f629184fab88290274854595e44261f5a6dd2d Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 28 Jan 2023 11:01:29 -0500 Subject: cmTarget: simplify `CheckLinkLibraryPattern` Now that usage properties have more of a representation, the function can just take the requirement directly. --- Source/cmTarget.cxx | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index e5bda26..734c91b 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -1984,8 +1984,7 @@ void cmTarget::AppendBuildInterfaceIncludes() } namespace { -bool CheckLinkLibraryPattern(cm::string_view property, - const std::vector>& value, +bool CheckLinkLibraryPattern(UsageRequirementProperty const& usage, cmake* context) { // Look for and internal tags @@ -1994,7 +1993,7 @@ bool CheckLinkLibraryPattern(cm::string_view property, bool isValid = true; - for (const auto& item : value) { + for (const auto& item : usage.Entries) { if (!linkPattern.find(item.Value)) { continue; } @@ -2005,8 +2004,8 @@ bool CheckLinkLibraryPattern(cm::string_view property, context->IssueMessage( MessageType::FATAL_ERROR, cmStrCat( - "Property ", property, " contains the invalid item \"", - linkPattern.match(2), "\". The ", property, + "Property ", usage.Name, " contains the invalid item \"", + linkPattern.match(2), "\". The ", usage.Name, " property may contain the generator-expression \"$\" which may be used to specify how the libraries are linked."), @@ -2025,16 +2024,12 @@ void cmTarget::FinalizeTargetConfiguration( return; } - if (!CheckLinkLibraryPattern("LINK_LIBRARIES"_s, - this->impl->LinkLibraries.Entries, + if (!CheckLinkLibraryPattern(this->impl->LinkLibraries, this->GetMakefile()->GetCMakeInstance()) || - !CheckLinkLibraryPattern("INTERFACE_LINK_LIBRARIES"_s, - this->impl->InterfaceLinkLibraries.Entries, + !CheckLinkLibraryPattern(this->impl->InterfaceLinkLibraries, this->GetMakefile()->GetCMakeInstance()) || - !CheckLinkLibraryPattern( - "INTERFACE_LINK_LIBRARIES_DIRECT"_s, - this->impl->InterfaceLinkLibrariesDirect.Entries, - this->GetMakefile()->GetCMakeInstance())) { + !CheckLinkLibraryPattern(this->impl->InterfaceLinkLibrariesDirect, + this->GetMakefile()->GetCMakeInstance())) { return; } -- cgit v0.12