[CMake] Determining appropriate CMAKE_MINIMUM_REQUIRED

Alan W. Irwin irwin at beluga.phys.uvic.ca
Thu Feb 6 15:24:20 EST 2014


On 2014-02-06 11:09-0800 Rob McDonald wrote:

> Is there a way to get cmake to report back an _actual_ minimum required
> version?
>
> Our project has lots of parts, and the CMakeLists.txt have not been very
> well maintained.  Right now, CMAKE_MINIMUM_REQUIRED is set to different
> values throughout, none of which are likely correct.
>
> It seems like it 'ought to be possible' to run a new version of cmake and
> have it report out actual values for CMAKE_MINIMUM_REQUIRED.
>
> Is there any way to do this other than a manual audit?

I don't think so.  Of course, finding all the instances
of cmake_minimum_required throughout your project should be
trivial.  For example, on linux you could use

find <top-level-directory-of project> -type f \
|xargs grep -il cmake_minimum_required

(with a slighly more complex syntax required if your paths include
spaces).

Changing all the uses of cmake_minimum_required to a common minimum
version is extremely worthwhile in my opinion.  I assume you could do
that by including a common file in each of your subprojects, but I
have never had to do that (my project only has two calls to
cmake_minimum_required which are easy to keep in synch manually) so I
will let others comment on details of the implementation.

You will probably want to convert each subproject to that common
minimum version approach just one subproject at a time since each such
change to that minimum version is equivalent (since you say the CMake
code is not well maintained so the current minimum versions are likely
to be quite old) to a large number of CMake policy changes for the
associated subproject which very likely will require some fixups to
the CMake code for that subproject.

Once all your subprojects are converted to the common minimum version
approach and the common policies that implies, then updating that
common minimum version should be fairly trivial.  If you are keeping
your common minimum version fairly up to date, then any change to that
value implies relatively few or no policy changes for each of your
subprojects so the needed adjustment of the CMake code in those
subprojects should be small or nonexistent.

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