1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License for more information.
11 ============================================================================*/
12 #include "cmCMakePolicyCommand.h"
14 #include "cmVersion.h"
16 // cmCMakePolicyCommand
17 bool cmCMakePolicyCommand
18 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
22 this->SetError("requires at least one argument.");
28 return this->HandleSetMode(args);
30 else if(args[0] == "GET")
32 return this->HandleGetMode(args);
34 else if(args[0] == "PUSH")
38 this->SetError("PUSH may not be given additional arguments.");
41 this->Makefile->PushPolicy();
44 else if(args[0] == "POP")
48 this->SetError("POP may not be given additional arguments.");
51 this->Makefile->PopPolicy();
54 else if(args[0] == "VERSION")
56 return this->HandleVersionMode(args);
60 e << "given unknown first argument \"" << args[0] << "\"";
61 this->SetError(e.str().c_str());
65 //----------------------------------------------------------------------------
66 bool cmCMakePolicyCommand::HandleSetMode(std::vector<std::string> const& args)
70 this->SetError("SET must be given exactly 2 additional arguments.");
74 cmPolicies::PolicyStatus status;
77 status = cmPolicies::OLD;
79 else if(args[2] == "NEW")
81 status = cmPolicies::NEW;
86 e << "SET given unrecognized policy status \"" << args[2] << "\"";
87 this->SetError(e.str().c_str());
91 if(!this->Makefile->SetPolicy(args[1].c_str(), status))
93 this->SetError("SET failed to set policy.");
99 //----------------------------------------------------------------------------
100 bool cmCMakePolicyCommand::HandleGetMode(std::vector<std::string> const& args)
104 this->SetError("GET must be given exactly 2 additional arguments.");
109 std::string const& id = args[1];
110 std::string const& var = args[2];
112 // Lookup the policy number.
113 cmPolicies::PolicyID pid;
114 if(!this->Makefile->GetPolicies()->GetPolicyID(id.c_str(), pid))
117 e << "GET given policy \"" << id << "\" which is not known to this "
118 << "version of CMake.";
119 this->SetError(e.str().c_str());
123 // Lookup the policy setting.
124 cmPolicies::PolicyStatus status = this->Makefile->GetPolicyStatus(pid);
127 case cmPolicies::OLD:
128 // Report that the policy is set to OLD.
129 this->Makefile->AddDefinition(var.c_str(), "OLD");
131 case cmPolicies::WARN:
132 // Report that the policy is not set.
133 this->Makefile->AddDefinition(var.c_str(), "");
135 case cmPolicies::NEW:
136 // Report that the policy is set to NEW.
137 this->Makefile->AddDefinition(var.c_str(), "NEW");
139 case cmPolicies::REQUIRED_IF_USED:
140 case cmPolicies::REQUIRED_ALWAYS:
141 // The policy is required to be set before anything needs it.
144 e << this->Makefile->GetPolicies()->GetRequiredPolicyError(pid)
146 << "The call to cmake_policy(GET " << id << " ...) at which this "
147 << "error appears requests the policy, and this version of CMake "
148 << "requires that the policy be set to NEW before it is checked.";
149 this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
156 //----------------------------------------------------------------------------
158 cmCMakePolicyCommand::HandleVersionMode(std::vector<std::string> const& args)
162 this->SetError("VERSION not given an argument");
165 else if(args.size() >= 3)
167 this->SetError("VERSION given too many arguments");
170 this->Makefile->SetPolicyVersion(args[1].c_str());