cmTargetPropertyComputer: Simplify by restoring use of cmMakefile

Logically revert commit 390a7d8647 (cmTargetPropertyComputer: Implement
GetProperty without cmMakefile, 2016-10-13, v3.8.0-rc1~445^2~9).
It relied on using `cmListFileBacktrace` to get a scope in which to
look up policies.

This does remove a backtrace from `LOCATION` property errors at generate
time, but the backtrace we reported before was incorrect.  It pointed at
the addition of a target, not to the reference to the property.
This commit is contained in:
Brad King
2021-12-07 15:23:53 -05:00
parent 3d378541bb
commit c749982c13
9 changed files with 37 additions and 60 deletions

View File

@@ -52,8 +52,6 @@
#include "cmTargetPropertyComputer.h"
#include "cmake.h"
class cmMessenger;
namespace {
const cmsys::RegularExpression FrameworkRegularExpression(
"^(.*/)?([^/]*)\\.framework/(.*)$");
@@ -61,8 +59,7 @@ const cmsys::RegularExpression FrameworkRegularExpression(
template <>
cmValue cmTargetPropertyComputer::GetSources<cmGeneratorTarget>(
cmGeneratorTarget const* tgt, cmMessenger* /* messenger */,
cmListFileBacktrace const& /* context */)
cmGeneratorTarget const* tgt, cmMakefile const& /* mf */)
{
return tgt->GetSourcesProperty();
}
@@ -439,8 +436,8 @@ std::string cmGeneratorTarget::GetExportName() const
cmValue cmGeneratorTarget::GetProperty(const std::string& prop) const
{
if (cmValue result = cmTargetPropertyComputer::GetProperty(
this, prop, this->Makefile->GetMessenger(), this->GetBacktrace())) {
if (cmValue result =
cmTargetPropertyComputer::GetProperty(this, prop, *this->Makefile)) {
return result;
}
if (cmSystemTools::GetFatalErrorOccured()) {

View File

@@ -7,7 +7,6 @@
#include "cmExecutionStatus.h"
#include "cmGlobalGenerator.h"
#include "cmInstalledFile.h"
#include "cmListFileCache.h"
#include "cmMakefile.h"
#include "cmMessageType.h"
#include "cmPolicies.h"
@@ -23,8 +22,6 @@
#include "cmValue.h"
#include "cmake.h"
class cmMessenger;
namespace {
enum OutType
{
@@ -365,9 +362,8 @@ bool HandleTargetMode(cmExecutionStatus& status, const std::string& name,
}
return StoreResult(infoType, status.GetMakefile(), variable, nullptr);
}
cmListFileBacktrace bt = status.GetMakefile().GetBacktrace();
cmMessenger* messenger = status.GetMakefile().GetMessenger();
cmValue prop = target->GetComputedProperty(propertyName, messenger, bt);
cmValue prop =
target->GetComputedProperty(propertyName, status.GetMakefile());
if (!prop) {
prop = target->GetProperty(propertyName);
}

View File

@@ -6,15 +6,12 @@
#include "cmExecutionStatus.h"
#include "cmGlobalGenerator.h"
#include "cmListFileCache.h"
#include "cmMakefile.h"
#include "cmMessageType.h"
#include "cmPolicies.h"
#include "cmTarget.h"
#include "cmValue.h"
class cmMessenger;
bool cmGetTargetPropertyCommand(std::vector<std::string> const& args,
cmExecutionStatus& status)
{
@@ -43,9 +40,7 @@ bool cmGetTargetPropertyCommand(std::vector<std::string> const& args,
}
} else if (!args[2].empty()) {
cmValue prop_cstr = nullptr;
cmListFileBacktrace bt = mf.GetBacktrace();
cmMessenger* messenger = mf.GetMessenger();
prop_cstr = tgt->GetComputedProperty(args[2], messenger, bt);
prop_cstr = tgt->GetComputedProperty(args[2], mf);
if (!prop_cstr) {
prop_cstr = tgt->GetProperty(args[2]);
}

View File

@@ -27,7 +27,6 @@
#include "cmListFileCache.h"
#include "cmMakefile.h"
#include "cmMessageType.h"
#include "cmMessenger.h"
#include "cmProperty.h"
#include "cmPropertyMap.h"
#include "cmRange.h"
@@ -82,9 +81,8 @@ const std::string& cmTargetPropertyComputer::ComputeLocation<cmTarget>(
}
template <>
cmValue cmTargetPropertyComputer::GetSources<cmTarget>(
cmTarget const* tgt, cmMessenger* messenger,
cmListFileBacktrace const& context)
cmValue cmTargetPropertyComputer::GetSources<cmTarget>(cmTarget const* tgt,
cmMakefile const& mf)
{
cmBTStringRange entries = tgt->GetSourceEntries();
if (entries.empty()) {
@@ -111,7 +109,7 @@ cmValue cmTargetPropertyComputer::GetSources<cmTarget>(
bool noMessage = true;
std::ostringstream e;
MessageType messageType = MessageType::AUTHOR_WARNING;
switch (context.GetBottom().GetPolicy(cmPolicies::CMP0051)) {
switch (mf.GetPolicyStatus(cmPolicies::CMP0051)) {
case cmPolicies::WARN:
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0051) << "\n";
noMessage = false;
@@ -132,7 +130,7 @@ cmValue cmTargetPropertyComputer::GetSources<cmTarget>(
"time. Code reading that property needs to be adapted to "
"ignore the generator expression using the string(GENEX_STRIP) "
"command.";
messenger->IssueMessage(messageType, e.str(), context);
mf.IssueMessage(messageType, e.str());
}
if (addContent) {
ss << sep;
@@ -1813,10 +1811,9 @@ void cmTarget::CheckProperty(const std::string& prop,
}
cmValue cmTarget::GetComputedProperty(const std::string& prop,
cmMessenger* messenger,
cmListFileBacktrace const& context) const
cmMakefile& mf) const
{
return cmTargetPropertyComputer::GetProperty(this, prop, messenger, context);
return cmTargetPropertyComputer::GetProperty(this, prop, mf);
}
cmValue cmTarget::GetProperty(const std::string& prop) const

View File

@@ -12,7 +12,6 @@
#include <vector>
#include "cmAlgorithms.h"
#include "cmListFileCache.h"
#include "cmPolicies.h"
#include "cmStateTypes.h"
#include "cmStringAlgorithms.h"
@@ -23,12 +22,18 @@ class cmCustomCommand;
class cmFileSet;
class cmGlobalGenerator;
class cmInstallTargetGenerator;
class cmListFileBacktrace;
class cmListFileContext;
class cmMakefile;
class cmMessenger;
class cmPropertyMap;
class cmSourceFile;
class cmTargetInternals;
template <typename T>
class BT;
template <typename T>
class BTs;
/** \class cmTarget
* \brief Represent a library or executable target loaded from a makefile.
*
@@ -184,8 +189,7 @@ public:
std::string const& GetSafeProperty(std::string const& prop) const;
bool GetPropertyAsBool(const std::string& prop) const;
void CheckProperty(const std::string& prop, cmMakefile* context) const;
cmValue GetComputedProperty(const std::string& prop, cmMessenger* messenger,
cmListFileBacktrace const& context) const;
cmValue GetComputedProperty(const std::string& prop, cmMakefile& mf) const;
//! Get all properties
cmPropertyMap const& GetProperties() const;

View File

@@ -6,6 +6,8 @@
#include <set>
#include "cmListFileCache.h"
class cmGeneratorTarget;
/** One edge in the global target dependency graph.

View File

@@ -5,19 +5,17 @@
#include <sstream>
#include "cmMakefile.h"
#include "cmMessageType.h"
#include "cmMessenger.h"
#include "cmPolicies.h"
#include "cmStateSnapshot.h"
bool cmTargetPropertyComputer::HandleLocationPropertyPolicy(
std::string const& tgtName, cmMessenger* messenger,
cmListFileBacktrace const& context)
std::string const& tgtName, cmMakefile const& mf)
{
std::ostringstream e;
const char* modal = nullptr;
MessageType messageType = MessageType::AUTHOR_WARNING;
switch (context.GetBottom().GetPolicy(cmPolicies::CMP0026)) {
switch (mf.GetPolicyStatus(cmPolicies::CMP0026)) {
case cmPolicies::WARN:
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0026) << "\n";
modal = "should";
@@ -38,7 +36,7 @@ bool cmTargetPropertyComputer::HandleLocationPropertyPolicy(
<< "\". Use the target name directly with "
"add_custom_command, or use the generator expression $<TARGET_FILE>, "
"as appropriate.\n";
messenger->IssueMessage(messageType, e.str(), context);
mf.IssueMessage(messageType, e.str());
}
return messageType != MessageType::FATAL_ERROR;

View File

@@ -6,38 +6,35 @@
#include <string>
#include "cmListFileCache.h"
#include "cmStateTypes.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
#include "cmValue.h"
class cmMessenger;
class cmMakefile;
class cmTargetPropertyComputer
{
public:
template <typename Target>
static cmValue GetProperty(Target const* tgt, const std::string& prop,
cmMessenger* messenger,
cmListFileBacktrace const& context)
cmMakefile const& mf)
{
if (cmValue loc = GetLocation(tgt, prop, messenger, context)) {
if (cmValue loc = GetLocation(tgt, prop, mf)) {
return loc;
}
if (cmSystemTools::GetFatalErrorOccured()) {
return nullptr;
}
if (prop == "SOURCES") {
return GetSources(tgt, messenger, context);
return GetSources(tgt, mf);
}
return nullptr;
}
private:
static bool HandleLocationPropertyPolicy(std::string const& tgtName,
cmMessenger* messenger,
cmListFileBacktrace const& context);
cmMakefile const& mf);
template <typename Target>
static const std::string& ComputeLocationForBuild(Target const* tgt);
@@ -47,8 +44,7 @@ private:
template <typename Target>
static cmValue GetLocation(Target const* tgt, std::string const& prop,
cmMessenger* messenger,
cmListFileBacktrace const& context)
cmMakefile const& mf)
{
// Watch for special "computed" properties that are dependent on
@@ -61,8 +57,7 @@ private:
static const std::string propLOCATION = "LOCATION";
if (prop == propLOCATION) {
if (!tgt->IsImported() &&
!HandleLocationPropertyPolicy(tgt->GetName(), messenger,
context)) {
!HandleLocationPropertyPolicy(tgt->GetName(), mf)) {
return nullptr;
}
return cmValue(ComputeLocationForBuild(tgt));
@@ -71,8 +66,7 @@ private:
// Support "LOCATION_<CONFIG>".
if (cmHasLiteralPrefix(prop, "LOCATION_")) {
if (!tgt->IsImported() &&
!HandleLocationPropertyPolicy(tgt->GetName(), messenger,
context)) {
!HandleLocationPropertyPolicy(tgt->GetName(), mf)) {
return nullptr;
}
std::string configName = prop.substr(9);
@@ -85,8 +79,7 @@ private:
std::string configName(prop.c_str(), prop.size() - 9);
if (configName != "IMPORTED") {
if (!tgt->IsImported() &&
!HandleLocationPropertyPolicy(tgt->GetName(), messenger,
context)) {
!HandleLocationPropertyPolicy(tgt->GetName(), mf)) {
return nullptr;
}
return cmValue(ComputeLocation(tgt, configName));
@@ -97,6 +90,5 @@ private:
}
template <typename Target>
static cmValue GetSources(Target const* tgt, cmMessenger* messenger,
cmListFileBacktrace const& context);
static cmValue GetSources(Target const* tgt, cmMakefile const& mf);
};

View File

@@ -1,4 +1,4 @@
CMake Warning \(dev\) at TARGET_PROPERTY-LOCATION.cmake:2 \(add_library\):
CMake Warning \(dev\) in CMakeLists\.txt:
Policy CMP0026 is not set: Disallow use of the LOCATION target property.
Run "cmake --help-policy CMP0026" for policy details. Use the cmake_policy
command to set the policy and suppress this warning.
@@ -6,7 +6,3 @@ CMake Warning \(dev\) at TARGET_PROPERTY-LOCATION.cmake:2 \(add_library\):
The LOCATION property should not be read from target "foo". Use the target
name directly with add_custom_command, or use the generator expression
\$<TARGET_FILE>, as appropriate.
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
This warning is for project developers. Use -Wno-dev to suppress it.