Clarify documentation for if.
[cmake.git] / Source / cmCMakeMinimumRequired.cxx
blob3b61b3c2926f79f84249fbb610405c48a79feeb0
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCMakeMinimumRequired.cxx,v $
5 Language: C++
6 Date: $Date: 2009-09-11 12:18:00 $
7 Version: $Revision: 1.20 $
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 this->UnknownArguments.push_back(args[i]);
53 if(doing_version)
55 this->SetError("called with no value for VERSION.");
56 return false;
59 // Make sure there was a version to check.
60 if(version_string.empty())
62 return this->EnforceUnknownArguments();
65 // Save the required version string.
66 this->Makefile->AddDefinition("CMAKE_MINIMUM_REQUIRED_VERSION",
67 version_string.c_str());
70 // Get the current version number.
71 int current_major = cmVersion::GetMajorVersion();
72 int current_minor = cmVersion::GetMinorVersion();
73 int current_patch = cmVersion::GetPatchVersion();
75 // Parse the required version number. If no patch-level is given
76 // use zero.
77 int required_major = 0;
78 int required_minor = 0;
79 int required_patch = 0;
80 if(sscanf(version_string.c_str(), "%d.%d.%d",
81 &required_major, &required_minor, &required_patch) < 2)
83 cmOStringStream e;
84 e << "could not parse VERSION \"" << version_string.c_str() << "\".";
85 this->SetError(e.str().c_str());
86 return false;
89 // Compare the version numbers.
90 if((current_major < required_major) ||
91 (current_major == required_major &&
92 current_minor < required_minor) ||
93 (current_major == required_major &&
94 current_minor == required_minor &&
95 current_patch < required_patch))
97 // The current version is too low.
98 cmOStringStream e;
99 e << "CMake " << version_string.c_str()
100 << " or higher is required. You are running version "
101 << current_major << "." << current_minor << "." << current_patch;
102 this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
103 cmSystemTools::SetFatalErrorOccured();
104 return true;
107 // The version is not from the future, so enforce unknown arguments.
108 if(!this->EnforceUnknownArguments())
110 return false;
113 if (required_major < 2 || (required_major == 2 && required_minor < 4))
115 this->Makefile->SetPolicyVersion("2.4");
117 else
119 this->Makefile->SetPolicyVersion(version_string.c_str());
122 return true;
125 //----------------------------------------------------------------------------
126 bool cmCMakeMinimumRequired::EnforceUnknownArguments()
128 if(!this->UnknownArguments.empty())
130 cmOStringStream e;
131 e << "called with unknown argument \""
132 << this->UnknownArguments[0] << "\".";
133 this->SetError(e.str().c_str());
134 return false;
136 return true;