Remove filtering of allowed INTERFACE library properties

Previously we disallowed use of arbitrary properties on INTERFACE
libraries.  The goal was to future-proof projects using them by not
allowing properties to be set that may affect their future inclusion in
the generated buildsystem.  In order to prepare to actually include
INTERFACE libraries in the generated buildsystem, drop the filter and
allow arbitrary properties to be set.

Issue: #19145
This commit is contained in:
Brad King
2020-07-14 13:55:38 -04:00
parent e7edba2baf
commit afb998704e
11 changed files with 6 additions and 163 deletions
-5
View File
@@ -380,11 +380,6 @@ std::string cmGeneratorTarget::GetExportName() const
cmProp cmGeneratorTarget::GetProperty(const std::string& prop) const
{
if (!cmTargetPropertyComputer::PassesWhitelist(
this->GetType(), prop, this->Makefile->GetMessenger(),
this->GetBacktrace())) {
return nullptr;
}
if (cmProp result = cmTargetPropertyComputer::GetProperty(
this, prop, this->Makefile->GetMessenger(), this->GetBacktrace())) {
return result;
+3 -7
View File
@@ -17,7 +17,6 @@
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
#include "cmTarget.h"
#include "cmTargetPropertyComputer.h"
#include "cmTest.h"
#include "cmake.h"
@@ -364,12 +363,9 @@ bool HandleTargetMode(cmExecutionStatus& status, const std::string& name,
cmProp prop_cstr = nullptr;
cmListFileBacktrace bt = status.GetMakefile().GetBacktrace();
cmMessenger* messenger = status.GetMakefile().GetMessenger();
if (cmTargetPropertyComputer::PassesWhitelist(
target->GetType(), propertyName, messenger, bt)) {
prop_cstr = target->GetComputedProperty(propertyName, messenger, bt);
if (!prop_cstr) {
prop_cstr = target->GetProperty(propertyName);
}
prop_cstr = target->GetComputedProperty(propertyName, messenger, bt);
if (!prop_cstr) {
prop_cstr = target->GetProperty(propertyName);
}
return StoreResult(infoType, status.GetMakefile(), variable,
prop_cstr ? prop_cstr->c_str() : nullptr);
+3 -7
View File
@@ -12,7 +12,6 @@
#include "cmPolicies.h"
#include "cmProperty.h"
#include "cmTarget.h"
#include "cmTargetPropertyComputer.h"
class cmMessenger;
@@ -46,12 +45,9 @@ bool cmGetTargetPropertyCommand(std::vector<std::string> const& args,
cmProp prop_cstr = nullptr;
cmListFileBacktrace bt = mf.GetBacktrace();
cmMessenger* messenger = mf.GetMessenger();
if (cmTargetPropertyComputer::PassesWhitelist(tgt->GetType(), args[2],
messenger, bt)) {
prop_cstr = tgt->GetComputedProperty(args[2], messenger, bt);
if (!prop_cstr) {
prop_cstr = tgt->GetProperty(args[2]);
}
prop_cstr = tgt->GetComputedProperty(args[2], messenger, bt);
if (!prop_cstr) {
prop_cstr = tgt->GetProperty(args[2]);
}
if (prop_cstr) {
prop = *prop_cstr;
-10
View File
@@ -1144,11 +1144,6 @@ cmBacktraceRange cmTarget::GetLinkImplementationBacktraces() const
void cmTarget::SetProperty(const std::string& prop, const char* value)
{
if (!cmTargetPropertyComputer::PassesWhitelist(
this->GetType(), prop, impl->Makefile->GetMessenger(),
impl->Makefile->GetBacktrace())) {
return;
}
#define MAKE_STATIC_PROP(PROP) static const std::string prop##PROP = #PROP
MAKE_STATIC_PROP(C_STANDARD);
MAKE_STATIC_PROP(CXX_STANDARD);
@@ -1355,11 +1350,6 @@ void cmTarget::SetProperty(const std::string& prop, const char* value)
void cmTarget::AppendProperty(const std::string& prop,
const std::string& value, bool asString)
{
if (!cmTargetPropertyComputer::PassesWhitelist(
this->GetType(), prop, impl->Makefile->GetMessenger(),
impl->Makefile->GetBacktrace())) {
return;
}
if (prop == "NAME") {
impl->Makefile->IssueMessage(MessageType::FATAL_ERROR,
"NAME property is read-only\n");
-69
View File
@@ -3,15 +3,12 @@
#include "cmTargetPropertyComputer.h"
#include <cctype>
#include <sstream>
#include <unordered_set>
#include "cmMessageType.h"
#include "cmMessenger.h"
#include "cmPolicies.h"
#include "cmStateSnapshot.h"
#include "cmStringAlgorithms.h"
bool cmTargetPropertyComputer::HandleLocationPropertyPolicy(
std::string const& tgtName, cmMessenger* messenger,
@@ -44,69 +41,3 @@ bool cmTargetPropertyComputer::HandleLocationPropertyPolicy(
return messageType != MessageType::FATAL_ERROR;
}
bool cmTargetPropertyComputer::WhiteListedInterfaceProperty(
const std::string& prop)
{
if (cmHasLiteralPrefix(prop, "INTERFACE_")) {
return true;
}
if (cmHasLiteralPrefix(prop, "_")) {
return true;
}
if (std::islower(prop[0])) {
return true;
}
static std::unordered_set<std::string> const builtIns{
"COMPATIBLE_INTERFACE_BOOL",
"COMPATIBLE_INTERFACE_NUMBER_MAX",
"COMPATIBLE_INTERFACE_NUMBER_MIN",
"COMPATIBLE_INTERFACE_STRING",
"DEPRECATION",
"EXPORT_NAME",
"EXPORT_PROPERTIES",
"IMPORTED",
"IMPORTED_GLOBAL",
"MANUALLY_ADDED_DEPENDENCIES",
"NAME",
"PRIVATE_HEADER",
"PUBLIC_HEADER",
"TYPE"
};
if (builtIns.count(prop)) {
return true;
}
if (prop == "IMPORTED_CONFIGURATIONS" || prop == "IMPORTED_LIBNAME" ||
cmHasLiteralPrefix(prop, "IMPORTED_LIBNAME_") ||
cmHasLiteralPrefix(prop, "MAP_IMPORTED_CONFIG_")) {
return true;
}
// This property should not be allowed but was incorrectly added in
// CMake 3.8. We can't remove it from the whitelist without breaking
// projects that try to set it. One day we could warn about this, but
// for now silently accept it.
if (prop == "NO_SYSTEM_FROM_IMPORTED") {
return true;
}
return false;
}
bool cmTargetPropertyComputer::PassesWhitelist(
cmStateEnums::TargetType tgtType, std::string const& prop,
cmMessenger* messenger, cmListFileBacktrace const& context)
{
if (tgtType == cmStateEnums::INTERFACE_LIBRARY &&
!WhiteListedInterfaceProperty(prop)) {
std::ostringstream e;
e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
"The property \""
<< prop << "\" is not allowed.";
messenger->IssueMessage(MessageType::FATAL_ERROR, e.str(), context);
return false;
}
return true;
}
-6
View File
@@ -35,12 +35,6 @@ public:
return nullptr;
}
static bool WhiteListedInterfaceProperty(const std::string& prop);
static bool PassesWhitelist(cmStateEnums::TargetType tgtType,
std::string const& prop, cmMessenger* messenger,
cmListFileBacktrace const& context);
private:
static bool HandleLocationPropertyPolicy(std::string const& tgtName,
cmMessenger* messenger,