Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmCMakeMinimumRequired.cxx
blobc5508caa14ba657eeb5ba20e6ffcd0c5a47d80e0
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCMakeMinimumRequired.cxx,v $
5 Language: C++
6 Date: $Date: 2008-03-24 14:56:26 $
7 Version: $Revision: 1.18 $
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 "cmCMakeMinimumRequired.h"
19 #include "cmVersion.h"
21 // cmCMakeMinimumRequired
22 bool cmCMakeMinimumRequired
23 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
25 // Process arguments.
26 std::string version_string;
27 bool doing_version = false;
28 for(unsigned int i=0; i < args.size(); ++i)
30 if(args[i] == "VERSION")
32 doing_version = true;
34 else if(args[i] == "FATAL_ERROR")
36 if(doing_version)
38 this->SetError("called with no value for VERSION.");
39 return false;
41 doing_version = false;
43 else if(doing_version)
45 doing_version = false;
46 version_string = args[i];
48 else
50 cmOStringStream e;
51 e << "called with unknown argument \"" << args[i].c_str() << "\".";
52 this->SetError(e.str().c_str());
53 return false;
56 if(doing_version)
58 this->SetError("called with no value for VERSION.");
59 return false;
62 // Make sure there was a version to check.
63 if(version_string.empty())
65 return true;
68 // Save the required version string.
69 this->Makefile->AddDefinition("CMAKE_MINIMUM_REQUIRED_VERSION",
70 version_string.c_str());
73 // Get the current version number.
74 int current_major = cmVersion::GetMajorVersion();
75 int current_minor = cmVersion::GetMinorVersion();
76 int current_patch = cmVersion::GetPatchVersion();
78 // Parse the required version number. If no patch-level is given
79 // use zero.
80 int required_major = 0;
81 int required_minor = 0;
82 int required_patch = 0;
83 if(sscanf(version_string.c_str(), "%d.%d.%d",
84 &required_major, &required_minor, &required_patch) < 2)
86 cmOStringStream e;
87 e << "could not parse VERSION \"" << version_string.c_str() << "\".";
88 this->SetError(e.str().c_str());
89 return false;
92 // Compare the version numbers.
93 if(current_major < required_major ||
94 current_major == required_major &&
95 current_minor < required_minor ||
96 current_major == required_major &&
97 current_minor == required_minor &&
98 current_patch < required_patch)
100 // The current version is too low.
101 cmOStringStream e;
102 e << "CMake " << version_string.c_str()
103 << " or higher is required. You are running version "
104 << current_major << "." << current_minor << "." << current_patch;
105 this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
106 cmSystemTools::SetFatalErrorOccured();
107 return true;
110 if (required_major < 2 || required_major == 2 && required_minor < 4)
112 this->Makefile->SetPolicyVersion("2.4");
114 else
116 this->Makefile->SetPolicyVersion(version_string.c_str());
119 return true;