1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCMakePolicyCommand.cxx,v $
6 Date: $Date: 2009-01-22 15:57:15 $
7 Version: $Revision: 1.5 $
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 this->Makefile
->PushPolicy();
49 else if(args
[0] == "POP")
53 this->SetError("POP may not be given additional arguments.");
56 this->Makefile
->PopPolicy();
59 else if(args
[0] == "VERSION")
61 return this->HandleVersionMode(args
);
65 e
<< "given unknown first argument \"" << args
[0] << "\"";
66 this->SetError(e
.str().c_str());
70 //----------------------------------------------------------------------------
71 bool cmCMakePolicyCommand::HandleSetMode(std::vector
<std::string
> const& args
)
75 this->SetError("SET must be given exactly 2 additional arguments.");
79 cmPolicies::PolicyStatus status
;
82 status
= cmPolicies::OLD
;
84 else if(args
[2] == "NEW")
86 status
= cmPolicies::NEW
;
91 e
<< "SET given unrecognized policy status \"" << args
[2] << "\"";
92 this->SetError(e
.str().c_str());
96 if(!this->Makefile
->SetPolicy(args
[1].c_str(), status
))
98 this->SetError("SET failed to set policy.");
104 //----------------------------------------------------------------------------
105 bool cmCMakePolicyCommand::HandleGetMode(std::vector
<std::string
> const& args
)
109 this->SetError("GET must be given exactly 2 additional arguments.");
114 std::string
const& id
= args
[1];
115 std::string
const& var
= args
[2];
117 // Lookup the policy number.
118 cmPolicies::PolicyID pid
;
119 if(!this->Makefile
->GetPolicies()->GetPolicyID(id
.c_str(), pid
))
122 e
<< "GET given policy \"" << id
<< "\" which is not known to this "
123 << "version of CMake.";
124 this->SetError(e
.str().c_str());
128 // Lookup the policy setting.
129 cmPolicies::PolicyStatus status
= this->Makefile
->GetPolicyStatus(pid
);
132 case cmPolicies::OLD
:
133 // Report that the policy is set to OLD.
134 this->Makefile
->AddDefinition(var
.c_str(), "OLD");
136 case cmPolicies::WARN
:
137 // Report that the policy is not set.
138 this->Makefile
->AddDefinition(var
.c_str(), "");
140 case cmPolicies::NEW
:
141 // Report that the policy is set to NEW.
142 this->Makefile
->AddDefinition(var
.c_str(), "NEW");
144 case cmPolicies::REQUIRED_IF_USED
:
145 case cmPolicies::REQUIRED_ALWAYS
:
146 // The policy is required to be set before anything needs it.
149 e
<< this->Makefile
->GetPolicies()->GetRequiredPolicyError(pid
)
151 << "The call to cmake_policy(GET " << id
<< " ...) at which this "
152 << "error appears requests the policy, and this version of CMake "
153 << "requires that the policy be set to NEW before it is checked.";
154 this->Makefile
->IssueMessage(cmake::FATAL_ERROR
, e
.str());
161 //----------------------------------------------------------------------------
163 cmCMakePolicyCommand::HandleVersionMode(std::vector
<std::string
> const& args
)
167 this->SetError("VERSION not given an argument");
170 else if(args
.size() >= 3)
172 this->SetError("VERSION given too many arguments");
175 this->Makefile
->SetPolicyVersion(args
[1].c_str());