Resync (forgot to add new files?)
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmCMakePolicyCommand.cxx
blob96c9ac25d8949997da94978eae74ed0916033124
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCMakePolicyCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2008-03-05 23:21:09 $
7 Version: $Revision: 1.2 $
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] == "PUSH")
37 if(args.size() > 1)
39 this->SetError("PUSH may not be given additional arguments.");
40 return false;
42 return this->Makefile->PushPolicy();
44 else if(args[0] == "POP")
46 if(args.size() > 1)
48 this->SetError("POP may not be given additional arguments.");
49 return false;
51 if(this->Makefile->PopPolicy(false))
53 return true;
55 else
57 this->SetError("POP without matching PUSH");
58 return false;
61 else if(args[0] == "VERSION")
63 return this->HandleVersionMode(args);
66 cmOStringStream e;
67 e << "given unknown first argument \"" << args[0] << "\"";
68 this->SetError(e.str().c_str());
69 return false;
72 //----------------------------------------------------------------------------
73 bool cmCMakePolicyCommand::HandleSetMode(std::vector<std::string> const& args)
75 if(args.size() != 3)
77 this->SetError("SET must be given exactly 2 additional arguments.");
78 return false;
81 cmPolicies::PolicyStatus status;
82 if(args[2] == "OLD")
84 status = cmPolicies::OLD;
86 else if(args[2] == "NEW")
88 status = cmPolicies::NEW;
90 else
92 cmOStringStream e;
93 e << "SET given unrecognized policy status \"" << args[2] << "\"";
94 this->SetError(e.str().c_str());
95 return false;
98 if(!this->Makefile->SetPolicy(args[1].c_str(), status))
100 this->SetError("SET failed to set policy.");
101 return false;
103 return true;
106 //----------------------------------------------------------------------------
107 bool
108 cmCMakePolicyCommand::HandleVersionMode(std::vector<std::string> const& args)
110 if(args.size() <= 1)
112 this->SetError("VERSION not given an argument");
113 return false;
115 else if(args.size() >= 3)
117 this->SetError("VERSION given too many arguments");
118 return false;
120 if(!this->Makefile->SetPolicyVersion(args[1].c_str()))
122 cmOStringStream e;
123 e << "VERSION given invalid value \"" << args[1] << "\". "
124 << "A numeric major.minor[.patch] must be given.";
125 this->SetError(e.str().c_str());
126 return false;
128 return true;