21

我知道在 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
4

3 回答 3

52

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))
  [...]
于 2013-05-21T10:57:24.657 回答
0

在 3.7 中引入了 GREATER_EQUAL 和 LESS_EQUAL。

于 2021-03-12T00:42:06.347 回答
0

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.

于 2021-12-17T03:43:23.417 回答