[CMake] Determining appropriate setting for CMAKE_MINIMUM_REQUIRED

Daniele E. Domenichelli ddomenichelli at drdanz.it
Fri Oct 9 19:53:35 EDT 2015


Hello Zac,

On 09/10/2015 23:27, Zac Bergquist wrote:
> Is there a particular tool or method that one should use to determine
> the appropriate setting for CMAKE_MINIMUM_REQUIRED? By appropriate, I
> mean the earliest version that encompasses all of the features used by
> the project.


This is what I used to do:


1) Check the compatibility matrix[1] (unfortunately it's useful only
until CMake 2.8.12). According to this, CMakePackageConfigHelpers was
introduced in CMake 2.8.8.

2) Check cmake documentation [2][3][4] for the versions that I'm
interested in (just change the version number in the url). For cmake <
3.0 the main page is cmake.html, for 3.0 and later it is index.html

3) Check the release notes[4] for 3.0 or later, changelog (usually
available on kitware blog) for previous versions

4) Check bug tracker[5], mailing lists archives, and git history
(usually as last resort) by searching for commit that introduced the
change that I'm interest in, and then running "git describe --contains
<hash>"


Then, even though I spent a lot of time searching, as soon as I commit
the changes, there is someone that complains that on some ancient CMake
version, the build is broken, because of some other feature or module
that I used without realizing that it was not supported.


Recently I switched to a trial and error approach using the
ExternalProject module. I have this "superproject" that I called (with
not much fantasy) "supercmake" and that downloads and builds all the
versions of CMake that I need to test. Then it tries to build my project
with all these versions.

It takes some time but after the first run, all the CMake versions are
already compiled (you could download and extract the binary versions, if
you want to improve it), but it is time that you can dedicate to
something else while the machine is building, instead of wasting time on it.

After building it, you are almost sure that the project will build with
all the cmake versions that you have to support, or you can use the
results to set CMAKE_MINIMUM_REQUIRED accordingly.


Attached is the CMakeLists.txt that I use, you just have to edit the
last ExternalProject_Add call, and eventually add or remove tags from
"CMAKE_TAGS".

I hope this is useful! :)



Cheers,
 Daniele


[1]https://cmake.org/Wiki/CMake_Version_Compatibility_Matrix
[2]https://cmake.org/cmake/help/v2.8.9/cmake.html
[3]https://cmake.org/cmake/help/v3.0/index.html
[4]https://cmake.org/cmake/help/git-master/release/index.html
[5]http://public.kitware.com/Bug/changelog_page.php?project_id=2

-------------- next part --------------
#=============================================================================
# Copyright 2014-2015 Daniele E. Domenichelli <daniele.domenichelli at iit.it>
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================

cmake_minimum_required(VERSION 3.0)
project(supercmake NONE)

include(ExternalProject)

set(CMAKE_REPO "git://cmake.org/cmake.git")
set(CMAKE_URL_BASE "http://www.cmake.org/files")
if(WIN32)
    set(CMAKE_EXT "zip")
else()
    set(CMAKE_EXT "tar.gz")
endif()
set(CMAKE_TAGS v2.8.9
               v2.8.10.2
               v2.8.11.2
               v2.8.12.2
               v3.0.2
               v3.1.3
               v3.2.3
               v3.3.2
               v3.4.0-rc1
               master
               next)

foreach(tag ${CMAKE_TAGS})

    unset(url)
    unset(version)
    unset(prefix)

    if(${tag} MATCHES "^v([0-9].[0-9])")
        string(SUBSTRING ${tag} 1 -1 version)
        set(url ${CMAKE_URL_BASE}/v${CMAKE_MATCH_1}/cmake-${version}.${CMAKE_EXT})
    else()
        set(version ${tag})
    endif()

    string(REGEX REPLACE "[\\.-]" "_" VERSION ${version})

    if(url)
        set(args URL ${url})
    else()
        set(args GIT_REPOSITORY ${CMAKE_REPO}
                 GIT_TAG ${tag})
    endif()

    set(prefix ${CMAKE_BINARY_DIR}/install/cmake-${version})

    ExternalProject_Add(CMake_${VERSION}
                        CONFIGURE_COMMAND <SOURCE_DIR>/configure --system-libs --prefix=${prefix}
                        ${args})

    # This is where you build your project "FOO"
    ExternalProject_Add(FOO_CMake_${VERSION}
                        GIT_REPOSITORY file:///path/to/your/local/clone/foo
                        GIT_TAG master
                        CMAKE_COMMAND ${prefix}/bin/cmake
                        CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX:PATH=${prefix}"
                        DEPENDS CMake_${VERSION})

endforeach()


More information about the CMake mailing list