Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which CMake version as the minimum?

Tags:

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.

like image 264
mustafagonul Avatar asked Feb 22 '16 09:02

mustafagonul


People also ask

What is Cmake_minimum_required?

The cmake_minimum_required(VERSION) command implicitly invokes the cmake_policy(VERSION) command to specify that the current project code is written for the given range of CMake versions.

How common is CMake?

Our brief research showed that CMake and 'make' were the most popular cross-platform tools, having ~30% of users each, while both Autotools and qmake had less than 7% of users.

What is CMakeLists txt?

CMakeLists. txt file contains a set of directives and instructions describing the project's source files and targets (executable, library, or both). When you create a new project, CLion generates CMakeLists. txt file automatically and places it in the project root directory.

How do I know what version of CMake I have?

You can check your CMake version by using the command cmake --version. cmake version 3.11.


1 Answers

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 

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


The ideal setting would be:

  1. The oldest version with all the features your script needs.

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. The oldest version you have tested that has all the features your script needs.

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. The version you are currently using.

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.

like image 136
DevSolar Avatar answered Oct 22 '22 01:10

DevSolar