diff options
author | Stephen Kelly <steveire@gmail.com> | 2016-10-12 22:18:26 (GMT) |
---|---|---|
committer | Stephen Kelly <steveire@gmail.com> | 2016-10-16 11:56:12 (GMT) |
commit | c3fb0d95ad114c9f9680e885c4c2263b43c437dc (patch) | |
tree | b17a83176a79757161a8998b397c81445db17b26 | |
parent | fa9dbc56a15aec71ac2eda7890efd0116797f373 (diff) | |
download | CMake-c3fb0d95ad114c9f9680e885c4c2263b43c437dc.zip CMake-c3fb0d95ad114c9f9680e885c4c2263b43c437dc.tar.gz CMake-c3fb0d95ad114c9f9680e885c4c2263b43c437dc.tar.bz2 |
cmTarget: Move sanity checks and computed property access to callers
The GetProperty method is now just accessing contained data, meaning it
can be implemented in cmState.
Remove the cmMakefile context from the signature as a result and remove
the overload with the same signature.
Add a GetComputedProperty to cmTarget so that templates can be properly
instantiated. Otherwise the Commands would need to be able to reach the
specializations which are currently in cmTarget.cxx.
As a side-effect, the CMP0026 warning now gives a backtrace to the
target when issued from a generator expression.
-rw-r--r-- | Source/cmGeneratorTarget.cxx | 12 | ||||
-rw-r--r-- | Source/cmGetPropertyCommand.cxx | 15 | ||||
-rw-r--r-- | Source/cmGetTargetPropertyCommand.cxx | 13 | ||||
-rw-r--r-- | Source/cmTarget.cxx | 23 | ||||
-rw-r--r-- | Source/cmTarget.h | 4 | ||||
-rw-r--r-- | Tests/RunCMake/GeneratorExpression/TARGET_PROPERTY-LOCATION-stderr.txt | 4 |
6 files changed, 48 insertions, 23 deletions
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 050fcb8..b0ff13e 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -397,6 +397,18 @@ std::string cmGeneratorTarget::GetExportName() const const char* cmGeneratorTarget::GetProperty(const std::string& prop) const { + if (!cmTargetPropertyComputer::PassesWhitelist( + this->GetType(), prop, this->Makefile->GetMessenger(), + this->GetBacktrace())) { + return 0; + } + if (const char* result = cmTargetPropertyComputer::GetProperty( + this, prop, this->Makefile->GetMessenger(), this->GetBacktrace())) { + return result; + } + if (cmSystemTools::GetFatalErrorOccured()) { + return CM_NULLPTR; + } return this->Target->GetProperty(prop); } diff --git a/Source/cmGetPropertyCommand.cxx b/Source/cmGetPropertyCommand.cxx index ba03568..39445dd 100644 --- a/Source/cmGetPropertyCommand.cxx +++ b/Source/cmGetPropertyCommand.cxx @@ -6,6 +6,7 @@ #include "cmPropertyDefinition.h" #include "cmSourceFile.h" #include "cmState.h" +#include "cmTargetPropertyComputer.h" #include "cmTest.h" #include "cmake.h" @@ -246,8 +247,18 @@ bool cmGetPropertyCommand::HandleTargetMode() } return this->StoreResult(CM_NULLPTR); } - return this->StoreResult( - target->GetProperty(this->PropertyName, this->Makefile)); + const char* prop_cstr = 0; + cmListFileBacktrace bt = this->Makefile->GetBacktrace(); + cmMessenger* messenger = this->Makefile->GetMessenger(); + if (cmTargetPropertyComputer::PassesWhitelist( + target->GetType(), this->PropertyName, messenger, bt)) { + prop_cstr = + target->GetComputedProperty(this->PropertyName, messenger, bt); + if (!prop_cstr) { + prop_cstr = target->GetProperty(this->PropertyName); + } + } + return this->StoreResult(prop_cstr); } std::ostringstream e; e << "could not find TARGET " << this->Name diff --git a/Source/cmGetTargetPropertyCommand.cxx b/Source/cmGetTargetPropertyCommand.cxx index fe09442..6a816d8 100644 --- a/Source/cmGetTargetPropertyCommand.cxx +++ b/Source/cmGetTargetPropertyCommand.cxx @@ -2,6 +2,8 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmGetTargetPropertyCommand.h" +#include "cmTargetPropertyComputer.h" + // cmSetTargetPropertyCommand bool cmGetTargetPropertyCommand::InitialPass( std::vector<std::string> const& args, cmExecutionStatus&) @@ -22,7 +24,16 @@ bool cmGetTargetPropertyCommand::InitialPass( prop_exists = true; } } else if (!args[2].empty()) { - const char* prop_cstr = tgt->GetProperty(args[2], this->Makefile); + const char* prop_cstr = 0; + cmListFileBacktrace bt = this->Makefile->GetBacktrace(); + cmMessenger* messenger = this->Makefile->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]); + } + } if (prop_cstr) { prop = prop_cstr; prop_exists = true; diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 9b2043c..e80768d 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -1129,28 +1129,15 @@ void cmTarget::CheckProperty(const std::string& prop, } } -const char* cmTarget::GetProperty(const std::string& prop) const +const char* cmTarget::GetComputedProperty( + const std::string& prop, cmMessenger* messenger, + cmListFileBacktrace const& context) const { - return this->GetProperty(prop, this->Makefile); + return cmTargetPropertyComputer::GetProperty(this, prop, messenger, context); } -const char* cmTarget::GetProperty(const std::string& prop, - cmMakefile* context) const +const char* cmTarget::GetProperty(const std::string& prop) const { - if (!cmTargetPropertyComputer::PassesWhitelist(this->GetType(), prop, - context->GetMessenger(), - context->GetBacktrace())) { - return CM_NULLPTR; - } - - if (const char* result = cmTargetPropertyComputer::GetProperty( - this, prop, context->GetMessenger(), context->GetBacktrace())) { - return result; - } - if (cmSystemTools::GetFatalErrorOccured()) { - return CM_NULLPTR; - } - static UNORDERED_SET<std::string> specialProps; #define MAKE_STATIC_PROP(PROP) static const std::string prop##PROP = #PROP MAKE_STATIC_PROP(LINK_LIBRARIES); diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 2d259ed..bd00b3d 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -200,9 +200,11 @@ public: void AppendProperty(const std::string& prop, const char* value, bool asString = false); const char* GetProperty(const std::string& prop) const; - const char* GetProperty(const std::string& prop, cmMakefile* context) const; bool GetPropertyAsBool(const std::string& prop) const; void CheckProperty(const std::string& prop, cmMakefile* context) const; + const char* GetComputedProperty(const std::string& prop, + cmMessenger* messenger, + cmListFileBacktrace const& context) const; bool IsImported() const { return this->IsImportedTarget; } bool IsImportedGloballyVisible() const diff --git a/Tests/RunCMake/GeneratorExpression/TARGET_PROPERTY-LOCATION-stderr.txt b/Tests/RunCMake/GeneratorExpression/TARGET_PROPERTY-LOCATION-stderr.txt index e4dbb71..d4e5b29 100644 --- a/Tests/RunCMake/GeneratorExpression/TARGET_PROPERTY-LOCATION-stderr.txt +++ b/Tests/RunCMake/GeneratorExpression/TARGET_PROPERTY-LOCATION-stderr.txt @@ -1,4 +1,4 @@ -CMake Warning \(dev\) in CMakeLists.txt: +CMake Warning \(dev\) at TARGET_PROPERTY-LOCATION.cmake:2 \(add_library\): 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. @@ -7,4 +7,6 @@ CMake Warning \(dev\) in CMakeLists.txt: 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. |