1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License for more information.
11 ============================================================================*/
12 #include "cmCMakeMinimumRequired.h"
14 #include "cmVersion.h"
16 // cmCMakeMinimumRequired
17 bool cmCMakeMinimumRequired
18 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
21 std::string version_string;
22 bool doing_version = false;
23 for(unsigned int i=0; i < args.size(); ++i)
25 if(args[i] == "VERSION")
29 else if(args[i] == "FATAL_ERROR")
33 this->SetError("called with no value for VERSION.");
36 doing_version = false;
38 else if(doing_version)
40 doing_version = false;
41 version_string = args[i];
45 this->UnknownArguments.push_back(args[i]);
50 this->SetError("called with no value for VERSION.");
54 // Make sure there was a version to check.
55 if(version_string.empty())
57 return this->EnforceUnknownArguments();
60 // Save the required version string.
61 this->Makefile->AddDefinition("CMAKE_MINIMUM_REQUIRED_VERSION",
62 version_string.c_str());
65 // Get the current version number.
66 int current_major = cmVersion::GetMajorVersion();
67 int current_minor = cmVersion::GetMinorVersion();
68 int current_patch = cmVersion::GetPatchVersion();
69 int current_tweak = cmVersion::GetTweakVersion();
71 // Parse at least two components of the version number.
72 // Use zero for those not specified.
73 int required_major = 0;
74 int required_minor = 0;
75 int required_patch = 0;
76 int required_tweak = 0;
77 if(sscanf(version_string.c_str(), "%u.%u.%u.%u",
78 &required_major, &required_minor,
79 &required_patch, &required_tweak) < 2)
82 e << "could not parse VERSION \"" << version_string.c_str() << "\".";
83 this->SetError(e.str().c_str());
87 // Compare the version numbers.
88 if((current_major < required_major) ||
89 (current_major == required_major &&
90 current_minor < required_minor) ||
91 (current_major == required_major &&
92 current_minor == required_minor &&
93 current_patch < required_patch) ||
94 (current_major == required_major &&
95 current_minor == required_minor &&
96 current_patch == required_patch &&
97 current_tweak < required_tweak))
99 // The current version is too low.
101 e << "CMake " << version_string.c_str()
102 << " or higher is required. You are running version "
103 << cmVersion::GetCMakeVersion();
104 this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
105 cmSystemTools::SetFatalErrorOccured();
109 // The version is not from the future, so enforce unknown arguments.
110 if(!this->EnforceUnknownArguments())
115 if (required_major < 2 || (required_major == 2 && required_minor < 4))
117 this->Makefile->SetPolicyVersion("2.4");
121 this->Makefile->SetPolicyVersion(version_string.c_str());
127 //----------------------------------------------------------------------------
128 bool cmCMakeMinimumRequired::EnforceUnknownArguments()
130 if(!this->UnknownArguments.empty())
133 e << "called with unknown argument \""
134 << this->UnknownArguments[0] << "\".";
135 this->SetError(e.str().c_str());