2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2008-02-29 23:42:14 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2008-02-29 23:42:14 +03:00
|
|
|
|
2009-09-28 19:43:28 +04: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 23:42:14 +03:00
|
|
|
#include "cmCMakePolicyCommand.h"
|
|
|
|
|
|
|
|
#include "cmVersion.h"
|
|
|
|
|
|
|
|
// cmCMakePolicyCommand
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmCMakePolicyCommand::InitialPass(std::vector<std::string> const& args,
|
|
|
|
cmExecutionStatus&)
|
2008-02-29 23:42:14 +03:00
|
|
|
{
|
2016-09-16 00:59:29 +03:00
|
|
|
if (args.empty()) {
|
2008-03-06 02:21:10 +03:00
|
|
|
this->SetError("requires at least one argument.");
|
2008-02-29 23:42:14 +03:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-03-06 02:21:10 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (args[0] == "SET") {
|
2008-03-06 02:21:10 +03:00
|
|
|
return this->HandleSetMode(args);
|
2016-09-16 23:45:24 +03:00
|
|
|
}
|
|
|
|
if (args[0] == "GET") {
|
2008-08-18 17:53:06 +04:00
|
|
|
return this->HandleGetMode(args);
|
2016-09-16 23:45:24 +03:00
|
|
|
}
|
|
|
|
if (args[0] == "PUSH") {
|
2016-05-16 17:34:04 +03:00
|
|
|
if (args.size() > 1) {
|
2008-03-06 02:21:10 +03:00
|
|
|
this->SetError("PUSH may not be given additional arguments.");
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-01-22 18:57:16 +03:00
|
|
|
this->Makefile->PushPolicy();
|
|
|
|
return true;
|
2016-09-16 23:45:24 +03:00
|
|
|
}
|
|
|
|
if (args[0] == "POP") {
|
2016-05-16 17:34:04 +03:00
|
|
|
if (args.size() > 1) {
|
2008-03-06 02:21:10 +03:00
|
|
|
this->SetError("POP may not be given additional arguments.");
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-01-22 18:57:16 +03:00
|
|
|
this->Makefile->PopPolicy();
|
|
|
|
return true;
|
2016-09-16 23:45:24 +03:00
|
|
|
}
|
|
|
|
if (args[0] == "VERSION") {
|
2008-03-06 02:21:10 +03:00
|
|
|
return this->HandleVersionMode(args);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-03-06 02:21:10 +03:00
|
|
|
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2008-03-06 02:21:10 +03:00
|
|
|
e << "given unknown first argument \"" << args[0] << "\"";
|
2014-03-11 03:04:11 +04:00
|
|
|
this->SetError(e.str());
|
2008-02-29 23:42:14 +03:00
|
|
|
return false;
|
|
|
|
}
|
2008-03-06 02:21:10 +03:00
|
|
|
|
|
|
|
bool cmCMakePolicyCommand::HandleSetMode(std::vector<std::string> const& args)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (args.size() != 3) {
|
2008-03-06 02:21:10 +03:00
|
|
|
this->SetError("SET must be given exactly 2 additional arguments.");
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-03-06 02:21:10 +03:00
|
|
|
|
|
|
|
cmPolicies::PolicyStatus status;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (args[2] == "OLD") {
|
2008-03-06 02:21:10 +03:00
|
|
|
status = cmPolicies::OLD;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (args[2] == "NEW") {
|
2008-03-06 02:21:10 +03:00
|
|
|
status = cmPolicies::NEW;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2008-03-06 02:21:10 +03:00
|
|
|
e << "SET given unrecognized policy status \"" << args[2] << "\"";
|
2014-03-11 03:04:11 +04:00
|
|
|
this->SetError(e.str());
|
2008-03-06 02:21:10 +03:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-03-06 02:21:10 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->Makefile->SetPolicy(args[1].c_str(), status)) {
|
2008-03-06 02:21:10 +03:00
|
|
|
this->SetError("SET failed to set policy.");
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (args[1] == "CMP0001" &&
|
|
|
|
(status == cmPolicies::WARN || status == cmPolicies::OLD)) {
|
|
|
|
if (!(this->Makefile->GetState()->GetInitializedCacheValue(
|
|
|
|
"CMAKE_BACKWARDS_COMPATIBILITY"))) {
|
2015-07-06 03:10:25 +03:00
|
|
|
// Set it to 2.4 because that is the last version where the
|
|
|
|
// variable had meaning.
|
2016-05-16 17:34:04 +03: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-06 02:21:10 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-08-18 17:53:06 +04:00
|
|
|
bool cmCMakePolicyCommand::HandleGetMode(std::vector<std::string> const& args)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (args.size() != 3) {
|
2008-08-18 17:53:06 +04:00
|
|
|
this->SetError("GET must be given exactly 2 additional arguments.");
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-08-18 17:53:06 +04: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 17:34:04 +03:00
|
|
|
if (!cmPolicies::GetPolicyID(id.c_str(), pid)) {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2008-08-18 17:53:06 +04:00
|
|
|
e << "GET given policy \"" << id << "\" which is not known to this "
|
|
|
|
<< "version of CMake.";
|
2014-03-11 03:04:11 +04:00
|
|
|
this->SetError(e.str());
|
2008-08-18 17:53:06 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-08-18 17:53:06 +04:00
|
|
|
|
|
|
|
// Lookup the policy setting.
|
|
|
|
cmPolicies::PolicyStatus status = this->Makefile->GetPolicyStatus(pid);
|
2016-05-16 17:34:04 +03:00
|
|
|
switch (status) {
|
2008-08-18 17:53:06 +04:00
|
|
|
case cmPolicies::OLD:
|
|
|
|
// Report that the policy is set to OLD.
|
2014-03-11 03:04:11 +04:00
|
|
|
this->Makefile->AddDefinition(var, "OLD");
|
2008-08-18 17:53:06 +04:00
|
|
|
break;
|
|
|
|
case cmPolicies::WARN:
|
|
|
|
// Report that the policy is not set.
|
2014-03-11 03:04:11 +04:00
|
|
|
this->Makefile->AddDefinition(var, "");
|
2008-08-18 17:53:06 +04:00
|
|
|
break;
|
|
|
|
case cmPolicies::NEW:
|
|
|
|
// Report that the policy is set to NEW.
|
2014-03-11 03:04:11 +04:00
|
|
|
this->Makefile->AddDefinition(var, "NEW");
|
2008-08-18 17:53:06 +04: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 17:34:04 +03: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 17:53:06 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-08-18 17:53:06 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmCMakePolicyCommand::HandleVersionMode(
|
|
|
|
std::vector<std::string> const& args)
|
2008-03-06 02:21:10 +03:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (args.size() <= 1) {
|
2008-03-06 02:21:10 +03:00
|
|
|
this->SetError("VERSION not given an argument");
|
|
|
|
return false;
|
2016-09-16 23:45:24 +03:00
|
|
|
}
|
|
|
|
if (args.size() >= 3) {
|
2008-03-06 02:21:10 +03:00
|
|
|
this->SetError("VERSION given too many arguments");
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2008-03-24 17:56:26 +03:00
|
|
|
this->Makefile->SetPolicyVersion(args[1].c_str());
|
2008-03-06 02:21:10 +03:00
|
|
|
return true;
|
|
|
|
}
|