mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-16 14:08:35 +08:00
cmTargetPropertyComputer: Unify whitelist handling from cmTarget
This commit is contained in:
@@ -709,13 +709,9 @@ cmBacktraceRange cmTarget::GetLinkImplementationBacktraces() const
|
|||||||
|
|
||||||
void cmTarget::SetProperty(const std::string& prop, const char* value)
|
void cmTarget::SetProperty(const std::string& prop, const char* value)
|
||||||
{
|
{
|
||||||
if (this->GetType() == cmState::INTERFACE_LIBRARY &&
|
if (!cmTargetPropertyComputer::PassesWhitelist(
|
||||||
!cmTargetPropertyComputer::WhiteListedInterfaceProperty(prop)) {
|
this->GetType(), prop, this->Makefile->GetMessenger(),
|
||||||
std::ostringstream e;
|
this->Makefile->GetBacktrace())) {
|
||||||
e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
|
|
||||||
"The property \""
|
|
||||||
<< prop << "\" is not allowed.";
|
|
||||||
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (prop == "NAME") {
|
if (prop == "NAME") {
|
||||||
@@ -793,13 +789,9 @@ void cmTarget::SetProperty(const std::string& prop, const char* value)
|
|||||||
void cmTarget::AppendProperty(const std::string& prop, const char* value,
|
void cmTarget::AppendProperty(const std::string& prop, const char* value,
|
||||||
bool asString)
|
bool asString)
|
||||||
{
|
{
|
||||||
if (this->GetType() == cmState::INTERFACE_LIBRARY &&
|
if (!cmTargetPropertyComputer::PassesWhitelist(
|
||||||
!cmTargetPropertyComputer::WhiteListedInterfaceProperty(prop)) {
|
this->GetType(), prop, this->Makefile->GetMessenger(),
|
||||||
std::ostringstream e;
|
this->Makefile->GetBacktrace())) {
|
||||||
e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
|
|
||||||
"The property \""
|
|
||||||
<< prop << "\" is not allowed.";
|
|
||||||
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (prop == "NAME") {
|
if (prop == "NAME") {
|
||||||
@@ -1012,13 +1004,9 @@ const char* cmTarget::GetProperty(const std::string& prop) const
|
|||||||
const char* cmTarget::GetProperty(const std::string& prop,
|
const char* cmTarget::GetProperty(const std::string& prop,
|
||||||
cmMakefile* context) const
|
cmMakefile* context) const
|
||||||
{
|
{
|
||||||
if (this->GetType() == cmState::INTERFACE_LIBRARY &&
|
if (!cmTargetPropertyComputer::PassesWhitelist(this->GetType(), prop,
|
||||||
!cmTargetPropertyComputer::WhiteListedInterfaceProperty(prop)) {
|
context->GetMessenger(),
|
||||||
std::ostringstream e;
|
context->GetBacktrace())) {
|
||||||
e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
|
|
||||||
"The property \""
|
|
||||||
<< prop << "\" is not allowed.";
|
|
||||||
context->IssueMessage(cmake::FATAL_ERROR, e.str());
|
|
||||||
return CM_NULLPTR;
|
return CM_NULLPTR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -270,3 +270,19 @@ bool cmTargetPropertyComputer::WhiteListedInterfaceProperty(
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool cmTargetPropertyComputer::PassesWhitelist(
|
||||||
|
cmState::TargetType tgtType, std::string const& prop, cmMessenger* messenger,
|
||||||
|
cmListFileBacktrace const& context)
|
||||||
|
{
|
||||||
|
if (tgtType == cmState::INTERFACE_LIBRARY &&
|
||||||
|
!WhiteListedInterfaceProperty(prop)) {
|
||||||
|
std::ostringstream e;
|
||||||
|
e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
|
||||||
|
"The property \""
|
||||||
|
<< prop << "\" is not allowed.";
|
||||||
|
messenger->IssueMessage(cmake::FATAL_ERROR, e.str(), context);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
@@ -25,6 +25,10 @@ public:
|
|||||||
|
|
||||||
static bool WhiteListedInterfaceProperty(const std::string& prop);
|
static bool WhiteListedInterfaceProperty(const std::string& prop);
|
||||||
|
|
||||||
|
static bool PassesWhitelist(cmState::TargetType tgtType,
|
||||||
|
std::string const& prop, cmMessenger* messenger,
|
||||||
|
cmListFileBacktrace const& context);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool HandleLocationPropertyPolicy(std::string const& tgtName,
|
static bool HandleLocationPropertyPolicy(std::string const& tgtName,
|
||||||
cmMessenger* messenger,
|
cmMessenger* messenger,
|
||||||
|
Reference in New Issue
Block a user