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
|
|
|
|
bool cmCMakePolicyCommand
|
|
|
|
::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
|
|
|
|
{
|
2008-03-06 02:21:10 +03:00
|
|
|
if(args.size() < 1)
|
|
|
|
{
|
|
|
|
this->SetError("requires at least one argument.");
|
2008-02-29 23:42:14 +03:00
|
|
|
return false;
|
2008-03-06 02:21:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if(args[0] == "SET")
|
|
|
|
{
|
|
|
|
return this->HandleSetMode(args);
|
|
|
|
}
|
2008-08-18 17:53:06 +04:00
|
|
|
else if(args[0] == "GET")
|
|
|
|
{
|
|
|
|
return this->HandleGetMode(args);
|
|
|
|
}
|
2008-03-06 02:21:10 +03:00
|
|
|
else if(args[0] == "PUSH")
|
|
|
|
{
|
|
|
|
if(args.size() > 1)
|
|
|
|
{
|
|
|
|
this->SetError("PUSH may not be given additional arguments.");
|
|
|
|
return false;
|
|
|
|
}
|
2009-01-22 18:57:16 +03:00
|
|
|
this->Makefile->PushPolicy();
|
|
|
|
return true;
|
2008-03-06 02:21:10 +03:00
|
|
|
}
|
|
|
|
else if(args[0] == "POP")
|
|
|
|
{
|
|
|
|
if(args.size() > 1)
|
|
|
|
{
|
|
|
|
this->SetError("POP may not be given additional arguments.");
|
|
|
|
return false;
|
|
|
|
}
|
2009-01-22 18:57:16 +03:00
|
|
|
this->Makefile->PopPolicy();
|
|
|
|
return true;
|
2008-03-06 02:21:10 +03:00
|
|
|
}
|
|
|
|
else if(args[0] == "VERSION")
|
|
|
|
{
|
|
|
|
return this->HandleVersionMode(args);
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if(args.size() != 3)
|
|
|
|
{
|
|
|
|
this->SetError("SET must be given exactly 2 additional arguments.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmPolicies::PolicyStatus status;
|
|
|
|
if(args[2] == "OLD")
|
|
|
|
{
|
|
|
|
status = cmPolicies::OLD;
|
|
|
|
}
|
|
|
|
else if(args[2] == "NEW")
|
|
|
|
{
|
|
|
|
status = cmPolicies::NEW;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!this->Makefile->SetPolicy(args[1].c_str(), status))
|
|
|
|
{
|
|
|
|
this->SetError("SET failed to set policy.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-08-18 17:53:06 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmCMakePolicyCommand::HandleGetMode(std::vector<std::string> const& args)
|
|
|
|
{
|
|
|
|
if(args.size() != 3)
|
|
|
|
{
|
|
|
|
this->SetError("GET must be given exactly 2 additional arguments.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get arguments.
|
|
|
|
std::string const& id = args[1];
|
|
|
|
std::string const& var = args[2];
|
|
|
|
|
|
|
|
// Lookup the policy number.
|
|
|
|
cmPolicies::PolicyID pid;
|
|
|
|
if(!this->Makefile->GetPolicies()->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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lookup the policy setting.
|
|
|
|
cmPolicies::PolicyStatus status = this->Makefile->GetPolicyStatus(pid);
|
|
|
|
switch (status)
|
|
|
|
{
|
|
|
|
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.
|
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2008-08-18 17:53:06 +04:00
|
|
|
e << this->Makefile->GetPolicies()->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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-03-06 02:21:10 +03:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool
|
|
|
|
cmCMakePolicyCommand::HandleVersionMode(std::vector<std::string> const& args)
|
|
|
|
{
|
|
|
|
if(args.size() <= 1)
|
|
|
|
{
|
|
|
|
this->SetError("VERSION not given an argument");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if(args.size() >= 3)
|
|
|
|
{
|
|
|
|
this->SetError("VERSION given too many arguments");
|
|
|
|
return false;
|
|
|
|
}
|
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;
|
|
|
|
}
|