1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmCMakeMinimumRequired.cxx,v $
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
&)
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")
34 else if(args
[i
] == "FATAL_ERROR")
38 this->SetError("called with no value for VERSION.");
41 doing_version
= false;
43 else if(doing_version
)
45 doing_version
= false;
46 version_string
= args
[i
];
50 this->UnknownArguments
.push_back(args
[i
]);
55 this->SetError("called with no value for VERSION.");
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
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)
84 e
<< "could not parse VERSION \"" << version_string
.c_str() << "\".";
85 this->SetError(e
.str().c_str());
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.
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();
107 // The version is not from the future, so enforce unknown arguments.
108 if(!this->EnforceUnknownArguments())
113 if (required_major
< 2 || (required_major
== 2 && required_minor
< 4))
115 this->Makefile
->SetPolicyVersion("2.4");
119 this->Makefile
->SetPolicyVersion(version_string
.c_str());
125 //----------------------------------------------------------------------------
126 bool cmCMakeMinimumRequired::EnforceUnknownArguments()
128 if(!this->UnknownArguments
.empty())
131 e
<< "called with unknown argument \""
132 << this->UnknownArguments
[0] << "\".";
133 this->SetError(e
.str().c_str());