最低的CMake版本? [英] Which CMake version as the minimum?

查看:306
本文介绍了最低的CMake版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 cmake_minimum_required功能为CMake定义最低版本。
我已经看到某些项目将最低版本设置为2.8,而另一些项目将版本设置为3.0或3.2。
我想了解您关于该主题的意见和最佳做法。

I want to define a minimum version to CMake with "cmake_minimum_required" facility. I have seen that some project set minimum version 2.8 some others set 3.0 or 3.2. I would like to learn your opinions and best practices about the topic.

推荐答案

cmake_minimum_required()函数用于避免由于 CMakeLists.txt 假定存在比CMake安装的版本高的任何错误消息。当前主机。

The cmake_minimum_required() function is used to avoid any cryptic error messages due to the CMakeLists.txt assuming a later version of CMake than the one installed on the current host.

例如,失败较早,并且带有明确的信息...

As an example, failing early, and with a clear message...

CMake 3.2 or higher is required. You are running version 2.8.12.2

...比更神秘的东西(更多)更受欢迎以后...

...is to be preferred over something more cryptic (much) later on...

In file included from /home/foouser/src/testprj/string.cpp:1:0:
/home/foouser/src/testprj/string.hpp:94:29: error: ‘std::is_same’ has not been declared

...只是因为在此示例中,较早的CMake版本不支持 set(CMAKE_CXX_STANDARD 11)。我相信你会同意的。

...just because, in this example, the older CMake version does not support set( CMAKE_CXX_STANDARD 11 ). I am sure you'll agree.

理想的设置是:


  1. 具有脚本所需的所有功能的最旧版本。

与人的最大兼容性运行旧版本以及您的脚本。但是它需要测试确切是哪个版本首先支持您的构造。因此,通常可以归结为:

Maximal compatibility with people running older versions, as well as with your script. But it requires testing which version exactly it was that first supported your constructs. So it usually boils down to:


  1. 您测试过的最早的版本

  1. The oldest version you have tested that has all the features your script needs.

对于大多数项目而言,这可能已经足够了。而且,如果您是唯一真正从事该项目的人,并且对CMake兼容性的测试确实很低,那么您最终可能会得到:

That's probably good enough for most projects. And if you are the only one actually working on the project, and testing for CMake compatibility is really low on your list, you will probably end up with:


  1. 当前使用的版本。

后一种方法一旦有人尝试编译您的项目,这将是一个严重的缺陷。很少有人不是使用最新版本的东西。特别是在Linux上,默认设置是使用程序包管理器提供的任何功能。例如,Ubuntu wily当前版本为3.2.2-可能具有更高版本,但是除非您需要更高版本,否则您不应该要求(因为这意味着如果不先手动安装较新版本的CMake,人们就无法构建您的项目)。

This latter approach has a serious drawback once somebody else attempts to compile your project. Quite a few people are not using the latest version of everything. On Linux in particular, the default is to use whatever the package manager gives you. Ubuntu wily, for example, is currently at version 3.2.2 -- you may have a later version, but unless you need a later version, you shouldn't require it (as that means people won't be able to build your project without first installing a newer version of CMake, manually).

您要做什么应该做的是...

What you should not be doing is...


  • 需要一个非常旧的版本,但实际上不是测试与该旧版本(否!)。

  • Requiring a very old version, but not actually testing against that old version (NO!).

原因应该很明显-构建可能会失败,而用户不会得到任何提示以了解发生问题的原因。

The reasons should be obvious -- building could fail, without the user getting any hint as to why things went wrong.

这篇关于最低的CMake版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆