2009-09-28 15:43:28 +00:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2008-02-29 20:42:14 +00:00
|
|
|
|
2009-09-28 15:43:28 +00:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2008-02-29 20:42:14 +00:00
|
|
|
|
2009-09-28 15:43:28 +00:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2008-02-29 20:42:14 +00:00
|
|
|
#include "cmCMakePolicyCommand.h"
|
|
|
|
|
|
|
|
#include "cmVersion.h"
|
|
|
|
|
|
|
|
// cmCMakePolicyCommand
|
2016-05-16 14:34:04 +00:00
|
|
|
bool cmCMakePolicyCommand::InitialPass(std::vector<std::string> const& args,
|
|
|
|
cmExecutionStatus&)
|
2008-02-29 20:42:14 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
if (args.size() < 1) {
|
2008-03-05 23:21:10 +00:00
|
|
|
this->SetError("requires at least one argument.");
|
2008-02-29 20:42:14 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-03-05 23:21:10 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (args[0] == "SET") {
|
2008-03-05 23:21:10 +00:00
|
|
|
return this->HandleSetMode(args);
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (args[0] == "GET") {
|
2008-08-18 13:53:06 +00:00
|
|
|
return this->HandleGetMode(args);
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (args[0] == "PUSH") {
|
|
|
|
if (args.size() > 1) {
|
2008-03-05 23:21:10 +00:00
|
|
|
this->SetError("PUSH may not be given additional arguments.");
|
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-01-22 15:57:16 +00:00
|
|
|
this->Makefile->PushPolicy();
|
|
|
|
return true;
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (args[0] == "POP") {
|
|
|
|
if (args.size() > 1) {
|
2008-03-05 23:21:10 +00:00
|
|
|
this->SetError("POP may not be given additional arguments.");
|
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-01-22 15:57:16 +00:00
|
|
|
this->Makefile->PopPolicy();
|
|
|
|
return true;
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (args[0] == "VERSION") {
|
2008-03-05 23:21:10 +00:00
|
|
|
return this->HandleVersionMode(args);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-03-05 23:21:10 +00:00
|
|
|
|
2015-01-05 19:31:31 +00:00
|
|
|
std::ostringstream e;
|
2008-03-05 23:21:10 +00:00
|
|
|
e << "given unknown first argument \"" << args[0] << "\"";
|
2014-03-10 23:04:11 +00:00
|
|
|
this->SetError(e.str());
|
2008-02-29 20:42:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
2008-03-05 23:21:10 +00:00
|
|
|
|
|
|
|
bool cmCMakePolicyCommand::HandleSetMode(std::vector<std::string> const& args)
|
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
if (args.size() != 3) {
|
2008-03-05 23:21:10 +00:00
|
|
|
this->SetError("SET must be given exactly 2 additional arguments.");
|
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-03-05 23:21:10 +00:00
|
|
|
|
|
|
|
cmPolicies::PolicyStatus status;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (args[2] == "OLD") {
|
2008-03-05 23:21:10 +00:00
|
|
|
status = cmPolicies::OLD;
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (args[2] == "NEW") {
|
2008-03-05 23:21:10 +00:00
|
|
|
status = cmPolicies::NEW;
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2015-01-05 19:31:31 +00:00
|
|
|
std::ostringstream e;
|
2008-03-05 23:21:10 +00:00
|
|
|
e << "SET given unrecognized policy status \"" << args[2] << "\"";
|
2014-03-10 23:04:11 +00:00
|
|
|
this->SetError(e.str());
|
2008-03-05 23:21:10 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-03-05 23:21:10 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!this->Makefile->SetPolicy(args[1].c_str(), status)) {
|
2008-03-05 23:21:10 +00:00
|
|
|
this->SetError("SET failed to set policy.");
|
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (args[1] == "CMP0001" &&
|
|
|
|
(status == cmPolicies::WARN || status == cmPolicies::OLD)) {
|
|
|
|
if (!(this->Makefile->GetState()->GetInitializedCacheValue(
|
|
|
|
"CMAKE_BACKWARDS_COMPATIBILITY"))) {
|
2015-07-06 00:10:25 +00:00
|
|
|
// Set it to 2.4 because that is the last version where the
|
|
|
|
// variable had meaning.
|
2016-05-16 14:34:04 +00:00
|
|
|
this->Makefile->AddCacheDefinition(
|
|
|
|
"CMAKE_BACKWARDS_COMPATIBILITY", "2.4",
|
|
|
|
"For backwards compatibility, what version of CMake "
|
|
|
|
"commands and "
|
|
|
|
"syntax should this version of CMake try to support.",
|
|
|
|
cmState::STRING);
|
|
|
|
}
|
|
|
|
}
|
2008-03-05 23:21:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-08-18 13:53:06 +00:00
|
|
|
bool cmCMakePolicyCommand::HandleGetMode(std::vector<std::string> const& args)
|
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
if (args.size() != 3) {
|
2008-08-18 13:53:06 +00:00
|
|
|
this->SetError("GET must be given exactly 2 additional arguments.");
|
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-08-18 13:53:06 +00:00
|
|
|
|
|
|
|
// Get arguments.
|
|
|
|
std::string const& id = args[1];
|
|
|
|
std::string const& var = args[2];
|
|
|
|
|
|
|
|
// Lookup the policy number.
|
|
|
|
cmPolicies::PolicyID pid;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!cmPolicies::GetPolicyID(id.c_str(), pid)) {
|
2015-01-05 19:31:31 +00:00
|
|
|
std::ostringstream e;
|
2008-08-18 13:53:06 +00:00
|
|
|
e << "GET given policy \"" << id << "\" which is not known to this "
|
|
|
|
<< "version of CMake.";
|
2014-03-10 23:04:11 +00:00
|
|
|
this->SetError(e.str());
|
2008-08-18 13:53:06 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-08-18 13:53:06 +00:00
|
|
|
|
|
|
|
// Lookup the policy setting.
|
|
|
|
cmPolicies::PolicyStatus status = this->Makefile->GetPolicyStatus(pid);
|
2016-05-16 14:34:04 +00:00
|
|
|
switch (status) {
|
2008-08-18 13:53:06 +00:00
|
|
|
case cmPolicies::OLD:
|
|
|
|
// Report that the policy is set to OLD.
|
2014-03-10 23:04:11 +00:00
|
|
|
this->Makefile->AddDefinition(var, "OLD");
|
2008-08-18 13:53:06 +00:00
|
|
|
break;
|
|
|
|
case cmPolicies::WARN:
|
|
|
|
// Report that the policy is not set.
|
2014-03-10 23:04:11 +00:00
|
|
|
this->Makefile->AddDefinition(var, "");
|
2008-08-18 13:53:06 +00:00
|
|
|
break;
|
|
|
|
case cmPolicies::NEW:
|
|
|
|
// Report that the policy is set to NEW.
|
2014-03-10 23:04:11 +00:00
|
|
|
this->Makefile->AddDefinition(var, "NEW");
|
2008-08-18 13:53:06 +00:00
|
|
|
break;
|
|
|
|
case cmPolicies::REQUIRED_IF_USED:
|
|
|
|
case cmPolicies::REQUIRED_ALWAYS:
|
|
|
|
// The policy is required to be set before anything needs it.
|
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
std::ostringstream e;
|
|
|
|
e << cmPolicies::GetRequiredPolicyError(pid) << "\n"
|
|
|
|
<< "The call to cmake_policy(GET " << id << " ...) at which this "
|
|
|
|
<< "error appears requests the policy, and this version of CMake "
|
|
|
|
<< "requires that the policy be set to NEW before it is checked.";
|
|
|
|
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
|
2008-08-18 13:53:06 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-08-18 13:53:06 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
bool cmCMakePolicyCommand::HandleVersionMode(
|
|
|
|
std::vector<std::string> const& args)
|
2008-03-05 23:21:10 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
if (args.size() <= 1) {
|
2008-03-05 23:21:10 +00:00
|
|
|
this->SetError("VERSION not given an argument");
|
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (args.size() >= 3) {
|
2008-03-05 23:21:10 +00:00
|
|
|
this->SetError("VERSION given too many arguments");
|
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2008-03-24 14:56:26 +00:00
|
|
|
this->Makefile->SetPolicyVersion(args[1].c_str());
|
2008-03-05 23:21:10 +00:00
|
|
|
return true;
|
|
|
|
}
|