Extract cmTargetPropertyEntry class from cmGeneratorTarget class.

To enable to reuse this class in different classes.
This commit is contained in:
Marc Chevrier
2026-02-19 17:03:45 +01:00
parent c362c4a7b5
commit b45dcfd306
8 changed files with 80 additions and 62 deletions
+2 -1
View File
@@ -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
+3 -4
View File
@@ -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<std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>> const&
in)
std::vector<std::unique_ptr<cm::TargetPropertyEntry>> const& in)
{
EvaluatedTargetPropertyEntries out;
out.Entries.reserve(in.size());
+2 -2
View File
@@ -79,11 +79,11 @@ cmTargetPropertyComputer::ImportedLocation<cmGeneratorTarget>(
static void CreatePropertyGeneratorExpressions(
cmake& cmakeInstance, cmBTStringRange entries,
std::vector<std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>>& items,
std::vector<std::unique_ptr<cm::TargetPropertyEntry>>& items,
bool evaluateForBuildsystem = false)
{
for (auto const& entry : entries) {
items.emplace_back(cmGeneratorTarget::TargetPropertyEntry::Create(
items.emplace_back(cm::TargetPropertyEntry::Create(
cmakeInstance, entry, evaluateForBuildsystem));
}
}
+3 -30
View File
@@ -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<TargetPropertyEntry> Create(
cmake& cmakeInstance, const BT<std::string>& propertyValue,
bool evaluateForBuildsystem = false);
static std::unique_ptr<TargetPropertyEntry> CreateFileSet(
std::vector<std::string> dirs, bool contextSensitiveDirs,
std::unique_ptr<cmCompiledGeneratorExpression> 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;
};
+2 -3
View File
@@ -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();
@@ -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 <map>
#include <string>
@@ -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<std::string> propertyValue,
cmLinkItem const& item = NoLinkItem)
: cmGeneratorTarget::TargetPropertyEntry(item)
: TargetPropertyEntry(item)
, PropertyValue(std::move(propertyValue))
{
}
@@ -51,12 +51,12 @@ private:
BT<std::string> PropertyValue;
};
class TargetPropertyEntryGenex : public cmGeneratorTarget::TargetPropertyEntry
class TargetPropertyEntryGenex : public TargetPropertyEntry
{
public:
TargetPropertyEntryGenex(std::unique_ptr<cmCompiledGeneratorExpression> cge,
cmLinkItem const& item = NoLinkItem)
: cmGeneratorTarget::TargetPropertyEntry(item)
: TargetPropertyEntry(item)
, ge(std::move(cge))
{
}
@@ -84,15 +84,14 @@ private:
std::unique_ptr<cmCompiledGeneratorExpression> const ge;
};
class TargetPropertyEntryFileSet
: public cmGeneratorTarget::TargetPropertyEntry
class TargetPropertyEntryFileSet : public TargetPropertyEntry
{
public:
TargetPropertyEntryFileSet(
std::vector<std::string> dirs, bool contextSensitiveDirs,
std::unique_ptr<cmCompiledGeneratorExpression> 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>
cmGeneratorTarget::TargetPropertyEntry::Create(
std::unique_ptr<TargetPropertyEntry> TargetPropertyEntry::Create(
cmake& cmakeInstance, const BT<std::string>& propertyValue,
bool evaluateForBuildsystem)
{
@@ -152,16 +150,15 @@ cmGeneratorTarget::TargetPropertyEntry::Create(
std::unique_ptr<cmCompiledGeneratorExpression> cge =
ge.Parse(propertyValue.Value);
cge->SetEvaluateForBuildsystem(evaluateForBuildsystem);
return std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>(
return std::unique_ptr<TargetPropertyEntry>(
cm::make_unique<TargetPropertyEntryGenex>(std::move(cge)));
}
return std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>(
return std::unique_ptr<TargetPropertyEntry>(
cm::make_unique<TargetPropertyEntryString>(propertyValue));
}
std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>
cmGeneratorTarget::TargetPropertyEntry::CreateFileSet(
std::unique_ptr<TargetPropertyEntry> TargetPropertyEntry::CreateFileSet(
std::vector<std::string> dirs, bool contextSensitiveDirs,
std::unique_ptr<cmCompiledGeneratorExpression> 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;
}
}
+50
View File
@@ -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 <memory>
#include <string>
#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<TargetPropertyEntry> Create(
cmake& cmakeInstance, const BT<std::string>& propertyValue,
bool evaluateForBuildsystem = false);
static std::unique_ptr<TargetPropertyEntry> CreateFileSet(
std::vector<std::string> dirs, bool contextSensitiveDirs,
std::unique_ptr<cmCompiledGeneratorExpression> 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;
};
}
+1 -1
View File
@@ -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 \