diff options
author | Brad King <brad.king@kitware.com> | 2013-11-21 14:39:39 (GMT) |
---|---|---|
committer | CMake Topic Stage <kwrobot@kitware.com> | 2013-11-21 14:39:39 (GMT) |
commit | d46dfd32c6c2f21a1ed272a38fc140157a17e94e (patch) | |
tree | 2eea34ebb3b577fe76fd48c5ad9c011511aba115 /Source | |
parent | 392932fb30d5b611887ad4e8a16901fa43fe1434 (diff) | |
parent | a02f3d2de00a16a68e8948db3c0de507e569f8a3 (diff) | |
download | CMake-d46dfd32c6c2f21a1ed272a38fc140157a17e94e.zip CMake-d46dfd32c6c2f21a1ed272a38fc140157a17e94e.tar.gz CMake-d46dfd32c6c2f21a1ed272a38fc140157a17e94e.tar.bz2 |
Merge topic 'missing-target-error'
a02f3d2 Add policy CMP0040 to disallow custom commands on missing targets
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmMakefile.cxx | 73 | ||||
-rw-r--r-- | Source/cmPolicies.cxx | 5 | ||||
-rw-r--r-- | Source/cmPolicies.h | 2 |
3 files changed, 57 insertions, 23 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 6be1fdd..e073f76 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -884,34 +884,61 @@ cmMakefile::AddCustomCommandToTarget(const char* target, { // Find the target to which to add the custom command. cmTargets::iterator ti = this->Targets.find(target); - if(ti != this->Targets.end()) + + if(ti == this->Targets.end()) { - if(ti->second.GetType() == cmTarget::OBJECT_LIBRARY) + cmake::MessageType messageType = cmake::AUTHOR_WARNING; + bool issueMessage = false; + switch(this->GetPolicyStatus(cmPolicies::CMP0040)) { - cmOStringStream e; - e << "Target \"" << target << "\" is an OBJECT library " - "that may not have PRE_BUILD, PRE_LINK, or POST_BUILD commands."; - this->IssueMessage(cmake::FATAL_ERROR, e.str()); - return; + case cmPolicies::WARN: + issueMessage = true; + case cmPolicies::OLD: + break; + case cmPolicies::NEW: + case cmPolicies::REQUIRED_IF_USED: + case cmPolicies::REQUIRED_ALWAYS: + issueMessage = true; + messageType = cmake::FATAL_ERROR; } - // Add the command to the appropriate build step for the target. - std::vector<std::string> no_output; - cmCustomCommand cc(this, no_output, depends, - commandLines, comment, workingDir); - cc.SetEscapeOldStyle(escapeOldStyle); - cc.SetEscapeAllowMakeVars(true); - switch(type) + + if(issueMessage) { - case cmTarget::PRE_BUILD: - ti->second.AddPreBuildCommand(cc); - break; - case cmTarget::PRE_LINK: - ti->second.AddPreLinkCommand(cc); - break; - case cmTarget::POST_BUILD: - ti->second.AddPostBuildCommand(cc); - break; + cmOStringStream e; + e << (this->GetPolicies() + ->GetPolicyWarning(cmPolicies::CMP0040)) << "\n"; + e << "The target name \"" << target << "\" is unknown in this context."; + IssueMessage(messageType, e.str().c_str()); } + + return; + } + + if(ti->second.GetType() == cmTarget::OBJECT_LIBRARY) + { + cmOStringStream e; + e << "Target \"" << target << "\" is an OBJECT library " + "that may not have PRE_BUILD, PRE_LINK, or POST_BUILD commands."; + this->IssueMessage(cmake::FATAL_ERROR, e.str()); + return; + } + // Add the command to the appropriate build step for the target. + std::vector<std::string> no_output; + cmCustomCommand cc(this, no_output, depends, + commandLines, comment, workingDir); + cc.SetEscapeOldStyle(escapeOldStyle); + cc.SetEscapeAllowMakeVars(true); + switch(type) + { + case cmTarget::PRE_BUILD: + ti->second.AddPreBuildCommand(cc); + break; + case cmTarget::PRE_LINK: + ti->second.AddPreLinkCommand(cc); + break; + case cmTarget::POST_BUILD: + ti->second.AddPostBuildCommand(cc); + break; } } diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx index a18fc16..b9b469c 100644 --- a/Source/cmPolicies.cxx +++ b/Source/cmPolicies.cxx @@ -301,6 +301,11 @@ cmPolicies::cmPolicies() CMP0039, "CMP0039", "Utility targets may not have link dependencies.", 3,0,0,0, cmPolicies::WARN); + + this->DefinePolicy( + CMP0040, "CMP0040", + "The target in the TARGET signature of add_custom_command() must exist.", + 3,0,0,0, cmPolicies::WARN); } cmPolicies::~cmPolicies() diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index 361d820..6834121 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -92,6 +92,8 @@ public: /// should match a validity pattern. CMP0038, ///< Targets may not link directly to themselves CMP0039, ///< Utility targets may not have link dependencies + CMP0040, ///< The target in the TARGET signature of + /// add_custom_command() must exist. /** \brief Always the last entry. * |