diff options
author | Brad King <brad.king@kitware.com> | 2024-05-16 19:25:06 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2024-05-20 23:16:57 (GMT) |
commit | d0fc9325287d343c573c8a9dc1783952fd8555ee (patch) | |
tree | 60ed7631fbf8678acfc87f09ea42073c21ea0d85 /Source | |
parent | abf60adfa6526dc444f65c32427e392aaaa5f976 (diff) | |
download | CMake-d0fc9325287d343c573c8a9dc1783952fd8555ee.zip CMake-d0fc9325287d343c573c8a9dc1783952fd8555ee.tar.gz CMake-d0fc9325287d343c573c8a9dc1783952fd8555ee.tar.bz2 |
cmGeneratorTarget: Factor TargetPropertyEntry into own source
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Source/cmGeneratorTarget.cxx | 167 | ||||
-rw-r--r-- | Source/cmGeneratorTarget_TargetPropertyEntry.cxx | 189 |
3 files changed, 190 insertions, 167 deletions
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index dff685d..5683524 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -285,6 +285,7 @@ add_library( cmGeneratorExpression.h cmGeneratorTarget.cxx cmGeneratorTarget.h + cmGeneratorTarget_TargetPropertyEntry.cxx cmLinkItemGraphVisitor.cxx cmLinkItemGraphVisitor.h cmGetPipes.cxx diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index b82cc23..61b93be 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -118,173 +118,6 @@ cmTargetPropertyComputer::ComputeLocation<cmGeneratorTarget>( return tgt->GetLocation(config); } -cmLinkImplItem cmGeneratorTarget::TargetPropertyEntry::NoLinkImplItem; - -class TargetPropertyEntryString : public cmGeneratorTarget::TargetPropertyEntry -{ -public: - TargetPropertyEntryString(BT<std::string> propertyValue, - cmLinkImplItem const& item = NoLinkImplItem) - : cmGeneratorTarget::TargetPropertyEntry(item) - , PropertyValue(std::move(propertyValue)) - { - } - - const std::string& Evaluate(cmLocalGenerator*, const std::string&, - cmGeneratorTarget const*, - cmGeneratorExpressionDAGChecker*, - std::string const&) const override - { - return this->PropertyValue.Value; - } - - cmListFileBacktrace GetBacktrace() const override - { - return this->PropertyValue.Backtrace; - } - std::string const& GetInput() const override - { - return this->PropertyValue.Value; - } - -private: - BT<std::string> PropertyValue; -}; - -class TargetPropertyEntryGenex : public cmGeneratorTarget::TargetPropertyEntry -{ -public: - TargetPropertyEntryGenex(std::unique_ptr<cmCompiledGeneratorExpression> cge, - cmLinkImplItem const& item = NoLinkImplItem) - : cmGeneratorTarget::TargetPropertyEntry(item) - , ge(std::move(cge)) - { - } - - const std::string& Evaluate(cmLocalGenerator* lg, const std::string& config, - cmGeneratorTarget const* headTarget, - cmGeneratorExpressionDAGChecker* dagChecker, - std::string const& language) const override - { - return this->ge->Evaluate(lg, config, headTarget, dagChecker, nullptr, - language); - } - - cmListFileBacktrace GetBacktrace() const override - { - return this->ge->GetBacktrace(); - } - - std::string const& GetInput() const override { return this->ge->GetInput(); } - - bool GetHadContextSensitiveCondition() const override - { - return this->ge->GetHadContextSensitiveCondition(); - } - -private: - const std::unique_ptr<cmCompiledGeneratorExpression> ge; -}; - -class TargetPropertyEntryFileSet - : public cmGeneratorTarget::TargetPropertyEntry -{ -public: - TargetPropertyEntryFileSet( - std::vector<std::string> dirs, bool contextSensitiveDirs, - std::unique_ptr<cmCompiledGeneratorExpression> entryCge, - const cmFileSet* fileSet, cmLinkImplItem const& item = NoLinkImplItem) - : cmGeneratorTarget::TargetPropertyEntry(item) - , BaseDirs(std::move(dirs)) - , ContextSensitiveDirs(contextSensitiveDirs) - , EntryCge(std::move(entryCge)) - , FileSet(fileSet) - { - } - - const std::string& Evaluate(cmLocalGenerator* lg, const std::string& config, - cmGeneratorTarget const* headTarget, - cmGeneratorExpressionDAGChecker* dagChecker, - std::string const& /*lang*/) const override - { - std::map<std::string, std::vector<std::string>> filesPerDir; - this->FileSet->EvaluateFileEntry(this->BaseDirs, filesPerDir, - this->EntryCge, lg, config, headTarget, - dagChecker); - - std::vector<std::string> files; - for (auto const& it : filesPerDir) { - files.insert(files.end(), it.second.begin(), it.second.end()); - } - - static std::string filesStr; - filesStr = cmList::to_string(files); - return filesStr; - } - - cmListFileBacktrace GetBacktrace() const override - { - return this->EntryCge->GetBacktrace(); - } - - std::string const& GetInput() const override - { - return this->EntryCge->GetInput(); - } - - bool GetHadContextSensitiveCondition() const override - { - return this->ContextSensitiveDirs || - this->EntryCge->GetHadContextSensitiveCondition(); - } - -private: - const std::vector<std::string> BaseDirs; - const bool ContextSensitiveDirs; - const std::unique_ptr<cmCompiledGeneratorExpression> EntryCge; - const cmFileSet* FileSet; -}; - -std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry> -cmGeneratorTarget::TargetPropertyEntry::Create( - cmake& cmakeInstance, const BT<std::string>& propertyValue, - bool evaluateForBuildsystem) -{ - if (cmGeneratorExpression::Find(propertyValue.Value) != std::string::npos) { - cmGeneratorExpression ge(cmakeInstance, propertyValue.Backtrace); - std::unique_ptr<cmCompiledGeneratorExpression> cge = - ge.Parse(propertyValue.Value); - cge->SetEvaluateForBuildsystem(evaluateForBuildsystem); - return std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>( - cm::make_unique<TargetPropertyEntryGenex>(std::move(cge))); - } - - return std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>( - cm::make_unique<TargetPropertyEntryString>(propertyValue)); -} - -std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry> -cmGeneratorTarget::TargetPropertyEntry::CreateFileSet( - std::vector<std::string> dirs, bool contextSensitiveDirs, - std::unique_ptr<cmCompiledGeneratorExpression> entryCge, - const cmFileSet* fileSet, cmLinkImplItem const& item) -{ - return cm::make_unique<TargetPropertyEntryFileSet>( - std::move(dirs), contextSensitiveDirs, std::move(entryCge), fileSet, item); -} - -cmGeneratorTarget::TargetPropertyEntry::TargetPropertyEntry( - cmLinkImplItem const& item) - : LinkImplItem(item) -{ -} - -bool cmGeneratorTarget::TargetPropertyEntry::GetHadContextSensitiveCondition() - const -{ - return false; -} - static void CreatePropertyGeneratorExpressions( cmake& cmakeInstance, cmBTStringRange entries, std::vector<std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>>& items, diff --git a/Source/cmGeneratorTarget_TargetPropertyEntry.cxx b/Source/cmGeneratorTarget_TargetPropertyEntry.cxx new file mode 100644 index 0000000..9b70f63 --- /dev/null +++ b/Source/cmGeneratorTarget_TargetPropertyEntry.cxx @@ -0,0 +1,189 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +/* clang-format off */ +#include "cmGeneratorTarget.h" +/* clang-format on */ + +#include <map> +#include <string> +#include <utility> +#include <vector> + +#include <cm/memory> + +#include "cmFileSet.h" +#include "cmGeneratorExpression.h" +#include "cmLinkItem.h" +#include "cmList.h" +#include "cmListFileCache.h" + +class cmLocalGenerator; +class cmake; +struct cmGeneratorExpressionDAGChecker; + +cmLinkImplItem cmGeneratorTarget::TargetPropertyEntry::NoLinkImplItem; + +class TargetPropertyEntryString : public cmGeneratorTarget::TargetPropertyEntry +{ +public: + TargetPropertyEntryString(BT<std::string> propertyValue, + cmLinkImplItem const& item = NoLinkImplItem) + : cmGeneratorTarget::TargetPropertyEntry(item) + , PropertyValue(std::move(propertyValue)) + { + } + + const std::string& Evaluate(cmLocalGenerator*, const std::string&, + cmGeneratorTarget const*, + cmGeneratorExpressionDAGChecker*, + std::string const&) const override + { + return this->PropertyValue.Value; + } + + cmListFileBacktrace GetBacktrace() const override + { + return this->PropertyValue.Backtrace; + } + std::string const& GetInput() const override + { + return this->PropertyValue.Value; + } + +private: + BT<std::string> PropertyValue; +}; + +class TargetPropertyEntryGenex : public cmGeneratorTarget::TargetPropertyEntry +{ +public: + TargetPropertyEntryGenex(std::unique_ptr<cmCompiledGeneratorExpression> cge, + cmLinkImplItem const& item = NoLinkImplItem) + : cmGeneratorTarget::TargetPropertyEntry(item) + , ge(std::move(cge)) + { + } + + const std::string& Evaluate(cmLocalGenerator* lg, const std::string& config, + cmGeneratorTarget const* headTarget, + cmGeneratorExpressionDAGChecker* dagChecker, + std::string const& language) const override + { + return this->ge->Evaluate(lg, config, headTarget, dagChecker, nullptr, + language); + } + + cmListFileBacktrace GetBacktrace() const override + { + return this->ge->GetBacktrace(); + } + + std::string const& GetInput() const override { return this->ge->GetInput(); } + + bool GetHadContextSensitiveCondition() const override + { + return this->ge->GetHadContextSensitiveCondition(); + } + +private: + const std::unique_ptr<cmCompiledGeneratorExpression> ge; +}; + +class TargetPropertyEntryFileSet + : public cmGeneratorTarget::TargetPropertyEntry +{ +public: + TargetPropertyEntryFileSet( + std::vector<std::string> dirs, bool contextSensitiveDirs, + std::unique_ptr<cmCompiledGeneratorExpression> entryCge, + const cmFileSet* fileSet, cmLinkImplItem const& item = NoLinkImplItem) + : cmGeneratorTarget::TargetPropertyEntry(item) + , BaseDirs(std::move(dirs)) + , ContextSensitiveDirs(contextSensitiveDirs) + , EntryCge(std::move(entryCge)) + , FileSet(fileSet) + { + } + + const std::string& Evaluate(cmLocalGenerator* lg, const std::string& config, + cmGeneratorTarget const* headTarget, + cmGeneratorExpressionDAGChecker* dagChecker, + std::string const& /*lang*/) const override + { + std::map<std::string, std::vector<std::string>> filesPerDir; + this->FileSet->EvaluateFileEntry(this->BaseDirs, filesPerDir, + this->EntryCge, lg, config, headTarget, + dagChecker); + + std::vector<std::string> files; + for (auto const& it : filesPerDir) { + files.insert(files.end(), it.second.begin(), it.second.end()); + } + + static std::string filesStr; + filesStr = cmList::to_string(files); + return filesStr; + } + + cmListFileBacktrace GetBacktrace() const override + { + return this->EntryCge->GetBacktrace(); + } + + std::string const& GetInput() const override + { + return this->EntryCge->GetInput(); + } + + bool GetHadContextSensitiveCondition() const override + { + return this->ContextSensitiveDirs || + this->EntryCge->GetHadContextSensitiveCondition(); + } + +private: + const std::vector<std::string> BaseDirs; + const bool ContextSensitiveDirs; + const std::unique_ptr<cmCompiledGeneratorExpression> EntryCge; + const cmFileSet* FileSet; +}; + +std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry> +cmGeneratorTarget::TargetPropertyEntry::Create( + cmake& cmakeInstance, const BT<std::string>& propertyValue, + bool evaluateForBuildsystem) +{ + if (cmGeneratorExpression::Find(propertyValue.Value) != std::string::npos) { + cmGeneratorExpression ge(cmakeInstance, propertyValue.Backtrace); + std::unique_ptr<cmCompiledGeneratorExpression> cge = + ge.Parse(propertyValue.Value); + cge->SetEvaluateForBuildsystem(evaluateForBuildsystem); + return std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>( + cm::make_unique<TargetPropertyEntryGenex>(std::move(cge))); + } + + return std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>( + cm::make_unique<TargetPropertyEntryString>(propertyValue)); +} + +std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry> +cmGeneratorTarget::TargetPropertyEntry::CreateFileSet( + std::vector<std::string> dirs, bool contextSensitiveDirs, + std::unique_ptr<cmCompiledGeneratorExpression> entryCge, + const cmFileSet* fileSet, cmLinkImplItem const& item) +{ + return cm::make_unique<TargetPropertyEntryFileSet>( + std::move(dirs), contextSensitiveDirs, std::move(entryCge), fileSet, item); +} + +cmGeneratorTarget::TargetPropertyEntry::TargetPropertyEntry( + cmLinkImplItem const& item) + : LinkImplItem(item) +{ +} + +bool cmGeneratorTarget::TargetPropertyEntry::GetHadContextSensitiveCondition() + const +{ + return false; +} |