1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCMakePolicyCommand.cxx,v $
6 Date: $Date: 2008-08-18 13:53:06 $
7 Version: $Revision: 1.4 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmCMakePolicyCommand.h"
19 #include "cmVersion.h"
21 // cmCMakePolicyCommand
22 bool cmCMakePolicyCommand
23 ::InitialPass(std::vector
<std::string
> const& args
, cmExecutionStatus
&)
27 this->SetError("requires at least one argument.");
33 return this->HandleSetMode(args
);
35 else if(args
[0] == "GET")
37 return this->HandleGetMode(args
);
39 else if(args
[0] == "PUSH")
43 this->SetError("PUSH may not be given additional arguments.");
46 return this->Makefile
->PushPolicy();
48 else if(args
[0] == "POP")
52 this->SetError("POP may not be given additional arguments.");
55 if(this->Makefile
->PopPolicy(false))
61 this->SetError("POP without matching PUSH");
65 else if(args
[0] == "VERSION")
67 return this->HandleVersionMode(args
);
71 e
<< "given unknown first argument \"" << args
[0] << "\"";
72 this->SetError(e
.str().c_str());
76 //----------------------------------------------------------------------------
77 bool cmCMakePolicyCommand::HandleSetMode(std::vector
<std::string
> const& args
)
81 this->SetError("SET must be given exactly 2 additional arguments.");
85 cmPolicies::PolicyStatus status
;
88 status
= cmPolicies::OLD
;
90 else if(args
[2] == "NEW")
92 status
= cmPolicies::NEW
;
97 e
<< "SET given unrecognized policy status \"" << args
[2] << "\"";
98 this->SetError(e
.str().c_str());
102 if(!this->Makefile
->SetPolicy(args
[1].c_str(), status
))
104 this->SetError("SET failed to set policy.");
110 //----------------------------------------------------------------------------
111 bool cmCMakePolicyCommand::HandleGetMode(std::vector
<std::string
> const& args
)
115 this->SetError("GET must be given exactly 2 additional arguments.");
120 std::string
const& id
= args
[1];
121 std::string
const& var
= args
[2];
123 // Lookup the policy number.
124 cmPolicies::PolicyID pid
;
125 if(!this->Makefile
->GetPolicies()->GetPolicyID(id
.c_str(), pid
))
128 e
<< "GET given policy \"" << id
<< "\" which is not known to this "
129 << "version of CMake.";
130 this->SetError(e
.str().c_str());
134 // Lookup the policy setting.
135 cmPolicies::PolicyStatus status
= this->Makefile
->GetPolicyStatus(pid
);
138 case cmPolicies::OLD
:
139 // Report that the policy is set to OLD.
140 this->Makefile
->AddDefinition(var
.c_str(), "OLD");
142 case cmPolicies::WARN
:
143 // Report that the policy is not set.
144 this->Makefile
->AddDefinition(var
.c_str(), "");
146 case cmPolicies::NEW
:
147 // Report that the policy is set to NEW.
148 this->Makefile
->AddDefinition(var
.c_str(), "NEW");
150 case cmPolicies::REQUIRED_IF_USED
:
151 case cmPolicies::REQUIRED_ALWAYS
:
152 // The policy is required to be set before anything needs it.
155 e
<< this->Makefile
->GetPolicies()->GetRequiredPolicyError(pid
)
157 << "The call to cmake_policy(GET " << id
<< " ...) at which this "
158 << "error appears requests the policy, and this version of CMake "
159 << "requires that the policy be set to NEW before it is checked.";
160 this->Makefile
->IssueMessage(cmake::FATAL_ERROR
, e
.str());
167 //----------------------------------------------------------------------------
169 cmCMakePolicyCommand::HandleVersionMode(std::vector
<std::string
> const& args
)
173 this->SetError("VERSION not given an argument");
176 else if(args
.size() >= 3)
178 this->SetError("VERSION given too many arguments");
181 this->Makefile
->SetPolicyVersion(args
[1].c_str());