STYLE: Fix line-too-long
[cmake.git] / Source / cmCMakePolicyCommand.cxx
blobe96f4632315194b29b4c64f1a5c93118fc602e6e
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCMakePolicyCommand.cxx,v $
5 Language: C++
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 &)
25 if(args.size() < 1)
27 this->SetError("requires at least one argument.");
28 return false;
31 if(args[0] == "SET")
33 return this->HandleSetMode(args);
35 else if(args[0] == "GET")
37 return this->HandleGetMode(args);
39 else if(args[0] == "PUSH")
41 if(args.size() > 1)
43 this->SetError("PUSH may not be given additional arguments.");
44 return false;
46 return this->Makefile->PushPolicy();
48 else if(args[0] == "POP")
50 if(args.size() > 1)
52 this->SetError("POP may not be given additional arguments.");
53 return false;
55 if(this->Makefile->PopPolicy(false))
57 return true;
59 else
61 this->SetError("POP without matching PUSH");
62 return false;
65 else if(args[0] == "VERSION")
67 return this->HandleVersionMode(args);
70 cmOStringStream e;
71 e << "given unknown first argument \"" << args[0] << "\"";
72 this->SetError(e.str().c_str());
73 return false;
76 //----------------------------------------------------------------------------
77 bool cmCMakePolicyCommand::HandleSetMode(std::vector<std::string> const& args)
79 if(args.size() != 3)
81 this->SetError("SET must be given exactly 2 additional arguments.");
82 return false;
85 cmPolicies::PolicyStatus status;
86 if(args[2] == "OLD")
88 status = cmPolicies::OLD;
90 else if(args[2] == "NEW")
92 status = cmPolicies::NEW;
94 else
96 cmOStringStream e;
97 e << "SET given unrecognized policy status \"" << args[2] << "\"";
98 this->SetError(e.str().c_str());
99 return false;
102 if(!this->Makefile->SetPolicy(args[1].c_str(), status))
104 this->SetError("SET failed to set policy.");
105 return false;
107 return true;
110 //----------------------------------------------------------------------------
111 bool cmCMakePolicyCommand::HandleGetMode(std::vector<std::string> const& args)
113 if(args.size() != 3)
115 this->SetError("GET must be given exactly 2 additional arguments.");
116 return false;
119 // Get 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))
127 cmOStringStream e;
128 e << "GET given policy \"" << id << "\" which is not known to this "
129 << "version of CMake.";
130 this->SetError(e.str().c_str());
131 return false;
134 // Lookup the policy setting.
135 cmPolicies::PolicyStatus status = this->Makefile->GetPolicyStatus(pid);
136 switch (status)
138 case cmPolicies::OLD:
139 // Report that the policy is set to OLD.
140 this->Makefile->AddDefinition(var.c_str(), "OLD");
141 break;
142 case cmPolicies::WARN:
143 // Report that the policy is not set.
144 this->Makefile->AddDefinition(var.c_str(), "");
145 break;
146 case cmPolicies::NEW:
147 // Report that the policy is set to NEW.
148 this->Makefile->AddDefinition(var.c_str(), "NEW");
149 break;
150 case cmPolicies::REQUIRED_IF_USED:
151 case cmPolicies::REQUIRED_ALWAYS:
152 // The policy is required to be set before anything needs it.
154 cmOStringStream e;
155 e << this->Makefile->GetPolicies()->GetRequiredPolicyError(pid)
156 << "\n"
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());
164 return true;
167 //----------------------------------------------------------------------------
168 bool
169 cmCMakePolicyCommand::HandleVersionMode(std::vector<std::string> const& args)
171 if(args.size() <= 1)
173 this->SetError("VERSION not given an argument");
174 return false;
176 else if(args.size() >= 3)
178 this->SetError("VERSION given too many arguments");
179 return false;
181 this->Makefile->SetPolicyVersion(args[1].c_str());
182 return true;