Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
CMake
CMake
Commits
aea456a9
Commit
aea456a9
authored
Feb 14, 2006
by
Brad King
Browse files
ENH: Added FATAL_ERROR option and fixed check to not have floating point roundoff problems.
parent
6c89a96b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Source/cmCMakeMinimumRequired.cxx
View file @
aea456a9
...
...
@@ -16,39 +16,106 @@
=========================================================================*/
#include "cmCMakeMinimumRequired.h"
#include "cmVersion.h"
// cmCMakeMinimumRequired
bool
cmCMakeMinimumRequired
::
InitialPass
(
std
::
vector
<
std
::
string
>
const
&
args
)
{
if
(
args
.
size
()
!=
2
)
// Process arguments.
std
::
string
version_string
;
bool
doing_version
=
false
;
bool
fatal_error
=
false
;
for
(
unsigned
int
i
=
0
;
i
<
args
.
size
();
++
i
)
{
if
(
args
[
i
]
==
"VERSION"
)
{
doing_version
=
true
;
}
else
if
(
args
[
i
]
==
"FATAL_ERROR"
)
{
if
(
doing_version
)
{
this
->
SetError
(
"called with no value for VERSION."
);
return
false
;
}
doing_version
=
false
;
fatal_error
=
true
;
}
else
if
(
doing_version
)
{
doing_version
=
false
;
version_string
=
args
[
i
];
}
else
{
cmOStringStream
e
;
e
<<
"called with unknown argument
\"
"
<<
args
[
i
].
c_str
()
<<
"
\"
."
;
this
->
SetError
(
e
.
str
().
c_str
());
return
false
;
}
}
if
(
doing_version
)
{
this
->
SetError
(
"called with
incorrect number of arguments
"
);
this
->
SetError
(
"called with
no value for VERSION.
"
);
return
false
;
}
if
(
args
[
0
]
==
"VERSION"
)
// Make sure there was a version to check.
if
(
version_string
.
empty
())
{
return
true
;
}
// Save the required version string.
m_Makefile
->
AddDefinition
(
"CMAKE_MINIMUM_REQUIRED_VERSION"
,
version_string
.
c_str
());
// Get the current version number.
int
current_major
=
m_Makefile
->
GetMajorVersion
();
int
current_minor
=
m_Makefile
->
GetMinorVersion
();
int
current_patch
=
m_Makefile
->
GetPatchVersion
();
// Parse the required version number. If no patch-level is given
// use zero.
int
required_major
=
0
;
int
required_minor
=
0
;
int
required_patch
=
0
;
if
(
sscanf
(
version_string
.
c_str
(),
"%d.%d.%d"
,
&
required_major
,
&
required_minor
,
&
required_patch
)
<
2
)
{
m_Makefile
->
AddDefinition
(
"CMAKE_MINIMUM_REQUIRED_VERSION"
,
args
[
1
].
c_str
());
cmOStringStream
e
;
e
<<
"could not parse VERSION
\"
"
<<
version_string
.
c_str
()
<<
"
\"
."
;
this
->
SetError
(
e
.
str
().
c_str
());
return
false
;
}
float
version
=
float
(
m_Makefile
->
GetMajorVersion
());
version
+=
(
float
(
m_Makefile
->
GetMinorVersion
())
*
(
float
)
.1
);
version
+=
(
float
(
m_Makefile
->
GetPatchVersion
())
*
(
float
)
.01
);
float
reqVersion
=
0
;
int
major
=
0
;
int
minor
=
0
;
int
patch
=
0
;
int
res
=
sscanf
(
args
[
1
].
c_str
(),
"%d.%d.%d"
,
&
major
,
&
minor
,
&
patch
);
if
(
res
==
3
)
reqVersion
=
float
(
major
)
+
0.1
*
float
(
minor
)
+
0.01
*
float
(
patch
);
else
if
(
res
==
2
)
reqVersion
=
float
(
major
)
+
0.1
*
float
(
minor
);
if
(
reqVersion
>
version
)
// Compare the version numbers.
if
(
current_major
<
required_major
||
current_major
==
required_major
&&
current_minor
<
required_minor
||
current_major
==
required_major
&&
current_minor
==
required_minor
&&
current_patch
<
required_patch
)
{
cmOStringStream
str
;
str
<<
"WARNING: This project requires version: "
<<
args
[
1
].
c_str
()
<<
" of cmake.
\n
"
<<
"You are running version: "
<<
version
;
cmSystemTools
::
Message
(
str
.
str
().
c_str
());
// The current version is too low.
cmOStringStream
e
;
if
(
!
fatal_error
)
{
e
<<
"WARNING: "
;
}
e
<<
"This project requires version "
<<
version_string
.
c_str
()
<<
" of CMake. "
<<
"You are running version "
<<
current_major
<<
"."
<<
current_minor
<<
"."
<<
current_patch
<<
".
\n
"
;
if
(
fatal_error
)
{
cmSystemTools
::
Error
(
e
.
str
().
c_str
());
cmSystemTools
::
SetFatalErrorOccured
();
}
else
{
cmSystemTools
::
Message
(
e
.
str
().
c_str
());
}
}
return
true
;
}
Source/cmCMakeMinimumRequired.h
View file @
aea456a9
...
...
@@ -65,11 +65,12 @@ public:
virtual
const
char
*
GetFullDocumentation
()
{
return
" CMAKE_MINIMUM_REQUIRED(VERSION versionNumber)
\n
"
" CMAKE_MINIMUM_REQUIRED(VERSION versionNumber
[FATAL_ERROR]
)
\n
"
"Let cmake know that the project requires a certain version of a "
"cmake, or newer. CMake will also try to be backwards compatible to "
"the version of cmake specified, if a newer version of cmake is "
"running."
;
"running. If FATAL_ERROR is given then failure to meet the "
"requirements will be considered an error instead of a warning."
;
}
cmTypeMacro
(
cmCMakeMinimumRequired
,
cmCommand
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment