From b45dcfd30623f34238c678d898db1634ae971d34 Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Thu, 19 Feb 2026 11:36:16 +0100 Subject: [PATCH] Extract cmTargetPropertyEntry class from cmGeneratorTarget class. To enable to reuse this class in different classes. --- Source/CMakeLists.txt | 3 +- Source/cmEvaluatedTargetProperty.cxx | 7 ++- Source/cmGeneratorTarget.cxx | 4 +- Source/cmGeneratorTarget.h | 33 ++---------- Source/cmGeneratorTarget_Sources.cxx | 5 +- ...rtyEntry.cxx => cmTargetPropertyEntry.cxx} | 38 +++++++------- Source/cmTargetPropertyEntry.h | 50 +++++++++++++++++++ bootstrap | 2 +- 8 files changed, 80 insertions(+), 62 deletions(-) rename Source/{cmGeneratorTarget_TargetPropertyEntry.cxx => cmTargetPropertyEntry.cxx} (80%) create mode 100644 Source/cmTargetPropertyEntry.h diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index ff49eeff91..29fc40d283 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -308,7 +308,6 @@ add_library( cmGeneratorTarget_LinkDirectories.cxx cmGeneratorTarget_Options.cxx cmGeneratorTarget_Sources.cxx - cmGeneratorTarget_TargetPropertyEntry.cxx cmGeneratorTarget_TransitiveProperty.cxx cmLinkItemGraphVisitor.cxx cmLinkItemGraphVisitor.h @@ -503,6 +502,8 @@ add_library( cmTarget.h cmTargetPropertyComputer.cxx cmTargetPropertyComputer.h + cmTargetPropertyEntry.cxx + cmTargetPropertyEntry.h cmTargetExport.h cmTargetTraceDependencies.cxx cmTargetTraceDependencies.h diff --git a/Source/cmEvaluatedTargetProperty.cxx b/Source/cmEvaluatedTargetProperty.cxx index f786985bb8..43c550fabe 100644 --- a/Source/cmEvaluatedTargetProperty.cxx +++ b/Source/cmEvaluatedTargetProperty.cxx @@ -10,6 +10,7 @@ #include "cmGeneratorTarget.h" #include "cmLinkItem.h" #include "cmList.h" +#include "cmTargetPropertyEntry.h" struct cmGeneratorExpressionDAGChecker; @@ -22,8 +23,7 @@ EvaluatedTargetPropertyEntry::EvaluatedTargetPropertyEntry( EvaluatedTargetPropertyEntry EvaluateTargetPropertyEntry( cmGeneratorTarget const* thisTarget, cm::GenEx::Context const& context, - cmGeneratorExpressionDAGChecker* dagChecker, - cmGeneratorTarget::TargetPropertyEntry& entry) + cmGeneratorExpressionDAGChecker* dagChecker, cm::TargetPropertyEntry& entry) { EvaluatedTargetPropertyEntry ee(entry.LinkItem, entry.GetBacktrace()); cmExpandList(entry.Evaluate(context, thisTarget, dagChecker), ee.Values); @@ -36,8 +36,7 @@ EvaluatedTargetPropertyEntry EvaluateTargetPropertyEntry( EvaluatedTargetPropertyEntries EvaluateTargetPropertyEntries( cmGeneratorTarget const* thisTarget, cm::GenEx::Context const& context, cmGeneratorExpressionDAGChecker* dagChecker, - std::vector> const& - in) + std::vector> const& in) { EvaluatedTargetPropertyEntries out; out.Entries.reserve(in.size()); diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index a8e3211e3d..61c35b2741 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -79,11 +79,11 @@ cmTargetPropertyComputer::ImportedLocation( static void CreatePropertyGeneratorExpressions( cmake& cmakeInstance, cmBTStringRange entries, - std::vector>& items, + std::vector>& items, bool evaluateForBuildsystem = false) { for (auto const& entry : entries) { - items.emplace_back(cmGeneratorTarget::TargetPropertyEntry::Create( + items.emplace_back(cm::TargetPropertyEntry::Create( cmakeInstance, entry, evaluateForBuildsystem)); } } diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 8c56a9b66f..cf87543a38 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -27,6 +27,7 @@ #include "cmSourceFile.h" #include "cmStandardLevel.h" #include "cmStateTypes.h" +#include "cmTargetPropertyEntry.h" #include "cmValue.h" namespace cm { @@ -53,6 +54,8 @@ struct cmGeneratorExpressionDAGChecker; class cmGeneratorTarget { public: + using TargetPropertyEntry = cm::TargetPropertyEntry; + cmGeneratorTarget(cmTarget*, cmLocalGenerator* lg); ~cmGeneratorTarget(); @@ -1014,8 +1017,6 @@ public: std::string const& report, std::string const& compatibilityType) const; - class TargetPropertyEntry; - std::string EvaluateInterfaceProperty( std::string const& prop, cm::GenEx::Evaluation* eval, cmGeneratorExpressionDAGChecker* dagCheckerParent, UseTo usage) const; @@ -1576,31 +1577,3 @@ private: mutable bool ComputingPchReuse = false; mutable bool PchReuseCycleDetected = false; }; - -class cmGeneratorTarget::TargetPropertyEntry -{ -protected: - static cmLinkItem NoLinkItem; - -public: - TargetPropertyEntry(cmLinkItem const& item); - virtual ~TargetPropertyEntry() = default; - - static std::unique_ptr Create( - cmake& cmakeInstance, const BT& propertyValue, - bool evaluateForBuildsystem = false); - static std::unique_ptr CreateFileSet( - std::vector dirs, bool contextSensitiveDirs, - std::unique_ptr entryCge, - cmFileSet const* fileSet, cmLinkItem const& item = NoLinkItem); - - virtual std::string const& Evaluate( - cm::GenEx::Context const& context, cmGeneratorTarget const* headTarget, - cmGeneratorExpressionDAGChecker* dagChecker) const = 0; - - virtual cmListFileBacktrace GetBacktrace() const = 0; - virtual std::string const& GetInput() const = 0; - virtual bool GetHadContextSensitiveCondition() const; - - cmLinkItem const& LinkItem; -}; diff --git a/Source/cmGeneratorTarget_Sources.cxx b/Source/cmGeneratorTarget_Sources.cxx index a5b958d7a8..b167a731d3 100644 --- a/Source/cmGeneratorTarget_Sources.cxx +++ b/Source/cmGeneratorTarget_Sources.cxx @@ -98,9 +98,8 @@ void addFileSetEntry(cmGeneratorTarget const* headTarget, } cmake* cm = headTarget->GetLocalGenerator()->GetCMakeInstance(); for (auto& entryCge : fileSet->CompileFileEntries()) { - auto targetPropEntry = - cmGeneratorTarget::TargetPropertyEntry::CreateFileSet( - dirs, contextSensitiveDirs, std::move(entryCge), fileSet); + auto targetPropEntry = cm::TargetPropertyEntry::CreateFileSet( + dirs, contextSensitiveDirs, std::move(entryCge), fileSet); entries.Entries.emplace_back(EvaluateTargetPropertyEntry( headTarget, context, dagChecker, *targetPropEntry)); EvaluatedTargetPropertyEntry const& entry = entries.Entries.back(); diff --git a/Source/cmGeneratorTarget_TargetPropertyEntry.cxx b/Source/cmTargetPropertyEntry.cxx similarity index 80% rename from Source/cmGeneratorTarget_TargetPropertyEntry.cxx rename to Source/cmTargetPropertyEntry.cxx index 2280e9387d..ef88f51e3b 100644 --- a/Source/cmGeneratorTarget_TargetPropertyEntry.cxx +++ b/Source/cmTargetPropertyEntry.cxx @@ -1,8 +1,7 @@ /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying file LICENSE.rst or https://cmake.org/licensing for details. */ -/* clang-format off */ -#include "cmGeneratorTarget.h" -/* clang-format on */ + +#include "cmTargetPropertyEntry.h" #include #include @@ -19,14 +18,15 @@ class cmake; -cmLinkItem cmGeneratorTarget::TargetPropertyEntry::NoLinkItem; +namespace cm { +cmLinkItem TargetPropertyEntry::NoLinkItem; -class TargetPropertyEntryString : public cmGeneratorTarget::TargetPropertyEntry +class TargetPropertyEntryString : public TargetPropertyEntry { public: TargetPropertyEntryString(BT propertyValue, cmLinkItem const& item = NoLinkItem) - : cmGeneratorTarget::TargetPropertyEntry(item) + : TargetPropertyEntry(item) , PropertyValue(std::move(propertyValue)) { } @@ -51,12 +51,12 @@ private: BT PropertyValue; }; -class TargetPropertyEntryGenex : public cmGeneratorTarget::TargetPropertyEntry +class TargetPropertyEntryGenex : public TargetPropertyEntry { public: TargetPropertyEntryGenex(std::unique_ptr cge, cmLinkItem const& item = NoLinkItem) - : cmGeneratorTarget::TargetPropertyEntry(item) + : TargetPropertyEntry(item) , ge(std::move(cge)) { } @@ -84,15 +84,14 @@ private: std::unique_ptr const ge; }; -class TargetPropertyEntryFileSet - : public cmGeneratorTarget::TargetPropertyEntry +class TargetPropertyEntryFileSet : public TargetPropertyEntry { public: TargetPropertyEntryFileSet( std::vector dirs, bool contextSensitiveDirs, std::unique_ptr entryCge, cmFileSet const* fileSet, cmLinkItem const& item = NoLinkItem) - : cmGeneratorTarget::TargetPropertyEntry(item) + : TargetPropertyEntry(item) , BaseDirs(std::move(dirs)) , ContextSensitiveDirs(contextSensitiveDirs) , EntryCge(std::move(entryCge)) @@ -142,8 +141,7 @@ private: cmFileSet const* FileSet; }; -std::unique_ptr -cmGeneratorTarget::TargetPropertyEntry::Create( +std::unique_ptr TargetPropertyEntry::Create( cmake& cmakeInstance, const BT& propertyValue, bool evaluateForBuildsystem) { @@ -152,16 +150,15 @@ cmGeneratorTarget::TargetPropertyEntry::Create( std::unique_ptr cge = ge.Parse(propertyValue.Value); cge->SetEvaluateForBuildsystem(evaluateForBuildsystem); - return std::unique_ptr( + return std::unique_ptr( cm::make_unique(std::move(cge))); } - return std::unique_ptr( + return std::unique_ptr( cm::make_unique(propertyValue)); } -std::unique_ptr -cmGeneratorTarget::TargetPropertyEntry::CreateFileSet( +std::unique_ptr TargetPropertyEntry::CreateFileSet( std::vector dirs, bool contextSensitiveDirs, std::unique_ptr entryCge, cmFileSet const* fileSet, cmLinkItem const& item) @@ -170,14 +167,13 @@ cmGeneratorTarget::TargetPropertyEntry::CreateFileSet( std::move(dirs), contextSensitiveDirs, std::move(entryCge), fileSet, item); } -cmGeneratorTarget::TargetPropertyEntry::TargetPropertyEntry( - cmLinkItem const& item) +TargetPropertyEntry::TargetPropertyEntry(cmLinkItem const& item) : LinkItem(item) { } -bool cmGeneratorTarget::TargetPropertyEntry::GetHadContextSensitiveCondition() - const +bool TargetPropertyEntry::GetHadContextSensitiveCondition() const { return false; } +} diff --git a/Source/cmTargetPropertyEntry.h b/Source/cmTargetPropertyEntry.h new file mode 100644 index 0000000000..fdb4f26c9d --- /dev/null +++ b/Source/cmTargetPropertyEntry.h @@ -0,0 +1,50 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file LICENSE.rst or https://cmake.org/licensing for details. */ +#pragma once + +#include +#include + +#include "cmListFileCache.h" + +class cmLinkItem; +class cmake; +class cmGeneratorTarget; +class cmFileSet; +struct cmGeneratorExpressionDAGChecker; +class cmCompiledGeneratorExpression; + +namespace cm { +namespace GenEx { +struct Context; +} + +class TargetPropertyEntry +{ +protected: + static cmLinkItem NoLinkItem; + +public: + TargetPropertyEntry(cmLinkItem const& item); + virtual ~TargetPropertyEntry() = default; + + static std::unique_ptr Create( + cmake& cmakeInstance, const BT& propertyValue, + bool evaluateForBuildsystem = false); + + static std::unique_ptr CreateFileSet( + std::vector dirs, bool contextSensitiveDirs, + std::unique_ptr entryCge, + cmFileSet const* fileSet, cmLinkItem const& item = NoLinkItem); + + virtual std::string const& Evaluate( + cm::GenEx::Context const& context, cmGeneratorTarget const* headTarget, + cmGeneratorExpressionDAGChecker* dagChecker) const = 0; + + virtual cmListFileBacktrace GetBacktrace() const = 0; + virtual std::string const& GetInput() const = 0; + virtual bool GetHadContextSensitiveCondition() const; + + cmLinkItem const& LinkItem; +}; +} diff --git a/bootstrap b/bootstrap index b7d608d021..dc9db3e43b 100755 --- a/bootstrap +++ b/bootstrap @@ -392,7 +392,6 @@ CMAKE_CXX_SOURCES="\ cmGeneratorTarget_LinkDirectories \ cmGeneratorTarget_Options \ cmGeneratorTarget_Sources \ - cmGeneratorTarget_TargetPropertyEntry \ cmGeneratorTarget_TransitiveProperty \ cmGetCMakePropertyCommand \ cmGetDirectoryPropertyCommand \ @@ -512,6 +511,7 @@ CMAKE_CXX_SOURCES="\ cmTargetPrecompileHeadersCommand \ cmTargetPropCommandBase \ cmTargetPropertyComputer \ + cmTargetPropertyEntry \ cmTargetSourcesCommand \ cmTargetTraceDependencies \ cmTest \