我知道在 CMake 中我可以像这样检查编译器版本
if(MSVC_VERSION LESS 1700)
... // MSVC is lower than MSVC2012
但是我该如何用 CMake 语法来表达呢?
if(MSVC_VERSION GREATER_OR_EQUAL_TO 1700)
... // MSVC greater or equal to MSVC2012
我知道在 CMake 中我可以像这样检查编译器版本
if(MSVC_VERSION LESS 1700)
... // MSVC is lower than MSVC2012
但是我该如何用 CMake 语法来表达呢?
if(MSVC_VERSION GREATER_OR_EQUAL_TO 1700)
... // MSVC greater or equal to MSVC2012
CMake 3.7 及更高版本的更新:
CMake 3.7引入了一些新的比较,if
其中包括GREATER_EQUAL
:
if(MSVC_VERSION GREATER_EQUAL 1700)
[...]
旧 CMake 版本的原始答案:
if((MSVC_VERSION GREATER 1700) OR (MSVC_VERSION EQUAL 1700))
[...]
或者可能更好,因为它避免了重复条件:
if(NOT (MSVC_VERSION LESS 1700))
[...]
在 3.7 中引入了 GREATER_EQUAL 和 LESS_EQUAL。
Maybe use VERSION_GREATER_EQUAL
? (This was also introduced in CMake 3.7.)
I.e.:
if (MSVC_VERSION VERSION_GREATER_EQUAL 1700)
# [...]
VERSION_GREATER_EQUAL and VERSION_LESS_EQUAL also support multipart version identifiers, such as 14.1.0, comparing these correctly as well.