diff options
author | Stephen Kelly <steveire@gmail.com> | 2013-06-28 14:37:39 (GMT) |
---|---|---|
committer | Stephen Kelly <steveire@gmail.com> | 2013-10-11 19:17:27 (GMT) |
commit | e4e5b28c27dc2e6f0073e11fb64c4ea62022a051 (patch) | |
tree | ba7aa13e6521fcf786811b9679b23269a11e5d36 /Source | |
parent | 7e4910fe47d667e059e42ac6395b0f4726f17064 (diff) | |
download | CMake-e4e5b28c27dc2e6f0073e11fb64c4ea62022a051.zip CMake-e4e5b28c27dc2e6f0073e11fb64c4ea62022a051.tar.gz CMake-e4e5b28c27dc2e6f0073e11fb64c4ea62022a051.tar.bz2 |
cmTarget: Deprecate the LOCATION target property with a policy.
The final location and name of a build-target is not determined
until generate-time. However, reading the LOCATION property from
a target is currently allowed at configure time. Apart from creating
possibly-erroneous results, this has an impact on the implementation
of cmake itself, and prevents some major cleanups from being made.
Disallow reading LOCATION from build-targets with a policy. Port some
existing uses of it in CMake itself to use the TARGET_FILE generator
expression.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmPolicies.cxx | 22 | ||||
-rw-r--r-- | Source/cmPolicies.h | 1 | ||||
-rw-r--r-- | Source/cmTarget.cxx | 50 | ||||
-rw-r--r-- | Source/cmTarget.h | 2 |
4 files changed, 75 insertions, 0 deletions
diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx index 1d3469f..d07645c 100644 --- a/Source/cmPolicies.cxx +++ b/Source/cmPolicies.cxx @@ -637,6 +637,28 @@ cmPolicies::cmPolicies() "The OLD behavior for this policy is to use compiler id \"Clang\". " "The NEW behavior for this policy is to use compiler id \"AppleClang\".", 2,8,13,0, cmPolicies::WARN); + + this->DefinePolicy( + CMP0026, "CMP0026", + "Disallow use of the LOCATION target property.", + "CMake 2.8.12 and lower allowed reading the LOCATION target property to " + "determine the eventual location of build targets. This relies on the " + "assumption that all necessary information is available at " + "configure-time to determine the final location and filename of the " + "target. However, this property is not fully determined until later at " + "generate-time. At generate time, the $<TARGET_FILE> generator " + "expression can be used to determine the eventual LOCATION of a target " + "output." + "\n" + "Code which reads the LOCATION target property can be ported to use the " + "$<TARGET_FILE> generator expression together with the file(GENERATE) " + "subcommand to generate a file containing the target location." + "\n" + "The OLD behavior for this policy is to allow reading the LOCATION " + "property from build-targets. " + "The NEW behavior for this policy is to not to allow reading the " + "LOCATION property from build-targets.", + 2,8,13,0, cmPolicies::WARN); } cmPolicies::~cmPolicies() diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index ec8959d..e33171b 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -76,6 +76,7 @@ public: CMP0023, ///< Disallow mixing keyword and plain tll signatures CMP0024, ///< Disallow including export() result. CMP0025, ///< Compiler id for Apple Clang is now AppleClang + CMP0026, ///< Disallow use of the LOCATION target property. /** \brief Always the last entry. * diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 1c04e4e..43d9ed1 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -4130,6 +4130,43 @@ const char *cmTarget::GetProperty(const char* prop) } //---------------------------------------------------------------------------- +bool cmTarget::HandleLocationPropertyPolicy() +{ + if (this->IsImported()) + { + return true; + } + const char *modal = 0; + cmake::MessageType messageType = cmake::AUTHOR_WARNING; + switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0026)) + { + case cmPolicies::WARN: + modal = "should"; + case cmPolicies::OLD: + break; + case cmPolicies::REQUIRED_ALWAYS: + case cmPolicies::REQUIRED_IF_USED: + case cmPolicies::NEW: + modal = "may"; + messageType = cmake::FATAL_ERROR; + } + + if (modal) + { + cmOStringStream e; + e << (this->Makefile->GetPolicies() + ->GetPolicyWarning(cmPolicies::CMP0026)) << "\n"; + e << "The LOCATION property " << modal << " not be read from target \"" + << this->GetName() << "\". Use the target name directly with " + "add_custom_command, or use the generator expression $<TARGET_FILE>, " + "as appropriate.\n"; + this->Makefile->IssueMessage(messageType, e.str().c_str()); + } + + return messageType != cmake::FATAL_ERROR; +} + +//---------------------------------------------------------------------------- const char *cmTarget::GetProperty(const char* prop, cmProperty::ScopeType scope) { @@ -4154,6 +4191,11 @@ const char *cmTarget::GetProperty(const char* prop, { if(strcmp(prop,"LOCATION") == 0) { + if (!this->HandleLocationPropertyPolicy()) + { + return 0; + } + // Set the LOCATION property of the target. // // For an imported target this is the location of an arbitrary @@ -4169,6 +4211,10 @@ const char *cmTarget::GetProperty(const char* prop, // Support "LOCATION_<CONFIG>". if(strncmp(prop, "LOCATION_", 9) == 0) { + if (!this->HandleLocationPropertyPolicy()) + { + return 0; + } std::string configName = prop+9; this->SetProperty(prop, this->GetLocation(configName.c_str())); } @@ -4181,6 +4227,10 @@ const char *cmTarget::GetProperty(const char* prop, std::string configName(prop, len-9); if(configName != "IMPORTED") { + if (!this->HandleLocationPropertyPolicy()) + { + return 0; + } this->SetProperty(prop, this->GetLocation(configName.c_str())); } } diff --git a/Source/cmTarget.h b/Source/cmTarget.h index a88c5ec..3c36da7 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -554,6 +554,8 @@ public: { return this->TargetTypeValue == STATIC_LIBRARY; } private: + bool HandleLocationPropertyPolicy(); + // The set of include directories that are marked as system include // directories. std::set<cmStdString> SystemIncludeDirectories; |