Introduce "generator expressions" to add_test()
[cmake.git] / Source / cmCMakePolicyCommand.cxx
bloba3fb5c1dccdc0b0c692965196b880e42cb28ed2f
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCMakePolicyCommand.cxx,v $
5 Language: C++
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 &)
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 this->Makefile->PushPolicy();
47 return true;
49 else if(args[0] == "POP")
51 if(args.size() > 1)
53 this->SetError("POP may not be given additional arguments.");
54 return false;
56 this->Makefile->PopPolicy();
57 return true;
59 else if(args[0] == "VERSION")
61 return this->HandleVersionMode(args);
64 cmOStringStream e;
65 e << "given unknown first argument \"" << args[0] << "\"";
66 this->SetError(e.str().c_str());
67 return false;
70 //----------------------------------------------------------------------------
71 bool cmCMakePolicyCommand::HandleSetMode(std::vector<std::string> const& args)
73 if(args.size() != 3)
75 this->SetError("SET must be given exactly 2 additional arguments.");
76 return false;
79 cmPolicies::PolicyStatus status;
80 if(args[2] == "OLD")
82 status = cmPolicies::OLD;
84 else if(args[2] == "NEW")
86 status = cmPolicies::NEW;
88 else
90 cmOStringStream e;
91 e << "SET given unrecognized policy status \"" << args[2] << "\"";
92 this->SetError(e.str().c_str());
93 return false;
96 if(!this->Makefile->SetPolicy(args[1].c_str(), status))
98 this->SetError("SET failed to set policy.");
99 return false;
101 return true;
104 //----------------------------------------------------------------------------
105 bool cmCMakePolicyCommand::HandleGetMode(std::vector<std::string> const& args)
107 if(args.size() != 3)
109 this->SetError("GET must be given exactly 2 additional arguments.");
110 return false;
113 // Get 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))
121 cmOStringStream e;
122 e << "GET given policy \"" << id << "\" which is not known to this "
123 << "version of CMake.";
124 this->SetError(e.str().c_str());
125 return false;
128 // Lookup the policy setting.
129 cmPolicies::PolicyStatus status = this->Makefile->GetPolicyStatus(pid);
130 switch (status)
132 case cmPolicies::OLD:
133 // Report that the policy is set to OLD.
134 this->Makefile->AddDefinition(var.c_str(), "OLD");
135 break;
136 case cmPolicies::WARN:
137 // Report that the policy is not set.
138 this->Makefile->AddDefinition(var.c_str(), "");
139 break;
140 case cmPolicies::NEW:
141 // Report that the policy is set to NEW.
142 this->Makefile->AddDefinition(var.c_str(), "NEW");
143 break;
144 case cmPolicies::REQUIRED_IF_USED:
145 case cmPolicies::REQUIRED_ALWAYS:
146 // The policy is required to be set before anything needs it.
148 cmOStringStream e;
149 e << this->Makefile->GetPolicies()->GetRequiredPolicyError(pid)
150 << "\n"
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());
158 return true;
161 //----------------------------------------------------------------------------
162 bool
163 cmCMakePolicyCommand::HandleVersionMode(std::vector<std::string> const& args)
165 if(args.size() <= 1)
167 this->SetError("VERSION not given an argument");
168 return false;
170 else if(args.size() >= 3)
172 this->SetError("VERSION given too many arguments");
173 return false;
175 this->Makefile->SetPolicyVersion(args[1].c_str());
176 return true;