[CMake] How to maintain compatibility with earlier versions?

Alan W. Irwin irwin at beluga.phys.uvic.ca
Mon Sep 11 17:37:18 EDT 2017


On 2017-09-11 18:06+0300 Konstantin Tokarev wrote:

>
>
> 11.09.2017, 16:52, "Robert Dailey" <rcdailey.lists at gmail.com>:
>> So typically my setup is that I have the newest CMake installed, but
>> am working with projects that set cmake_minimum_required to something
>> like version 2.8. Will version 3.9 of CMake prevent me from using
>> features that were introduced after 2.8? How can I make sure that
>> someone with *actual* version 2.8 installed will not run into
>> errors/issues?
>
> Only by testing with actual 2.8 (or whatever version you support).

I agree such testing is the only completely safe thing to do.  However,
that said, if a project specifies

cmake_minimum_required(VERSION <some_version> FATAL_ERROR)

than that, by default, implies

cmake_policy(VERSION <some_version>)

i.e., all policies after <some_version> will default
to OLD (i.e., the policy available for <some_version>) behaviour.

So because of this design, CMake has pretty good backwards
compatibility, i.e., a project _should_ build the same way (with
policies identical to those in effect for its minimum cmake version)
regardless of how far a user's cmake version is ahead of the minimum
version for a project.

In practice, of course, such backwards compatibility is not perfect
which is why I typically test the build systems for my various
software projects with both their minimum CMake version and the latest
CMake version. And to avoid straining that CMake backwards
compatibility design too far, I typically also bump my cmake minimum
version for projects (and therefore the associated cmake policies) to
be not too far behind the latest CMake version.  For example, fairly
recently I bumped the PLplot minimum version from 3.0.2 (the version
supplied by Debian Oldstable = Jessie) to 3.6.2, and within a few
months (once Cygwin provides 3.7.2) I plan to bump that minimum
version again to 3.7.2 (the version supplied by Debian Stable =
Stretch).  Note that Debian Stretch was just designated the Debian
Stable version and typically Debian has a release cycle of ~2 years.
So I will likely leave that minimum version at 3.7.2 for ~2 more years
which should allow most Linux users during that interval with access
to up-to-date distro versions of CMake to use their system CMake
version rather than forcing them to use a later version of CMake that
they have to build themselves.

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state
implementation for stellar interiors (freeeos.sf.net); the Time
Ephemerides project (timeephem.sf.net); PLplot scientific plotting
software package (plplot.sf.net); the libLASi project
(unifont.org/lasi); the Loads of Linux Links project (loll.sf.net);
and the Linux Brochure Project (lbproject.sf.net).
__________________________

Linux-powered Science
__________________________


More information about the CMake mailing list