[cmake-developers] Fwd: How to handle different cmake versions in extra-cmake-modules ?

Brad King brad.king at kitware.com
Mon Nov 7 08:54:12 EST 2011


On 11/6/2011 6:12 AM, Stephen Kelly wrote:
> ecm_copy_modules(${CMAKE_BINARY_DIR}/modules FindFoo.cmake
>                                               FindBlub.cmake
>                                               ECMDoSomething.cmake)
>
> set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}  ${CMAKE_BINARY_DIR}/modules} )
>
> This macro would copy just these needed files into the given directory, which
> can then be added to CMAKE_MODULE_PATH.

See below for an idea that may solve cases 2 and 3 together.

> Case 3. I don't really have an idea yet. Add some code at the top of each file
> which include()s the file from cmake if the version is bigger than some
> specified version ?
>
> Something like:
> FindBlub.cmake:
>
> if(CMAKE_VERSION>  2.8.12)
>    include(${CMAKE_ROOT}/Modules/FindBlub.cmake)
>    return()
> endif()

We've done the following before:

  if(EXISTS ${CMAKE_ROOT}/Modules/FindBlub.cmake)
    include(${CMAKE_ROOT}/Modules/FindBlub.cmake)
    return()
  endif()

That way you don't need to know when the module is added.  It is also
forward-compatible for any module not yet in CMake but may be later.
OTOH the version of the module added to CMake may provide a slightly
different interface than the original version.  That leads to the
unfortunate situation that a newer CMake breaks an existing build,
which looks like CMake's fault but isn't.

Another option is to provide a function that generates forwarding
modules.  Instead of ecm_copy_modules, create a similar API that
generates short modules that include either the ECM version or the
CMake version depending on some conditions.  Do the inclusion by
full path so that the actual ECM module dir does not need to be in
the CMAKE_MODULE_PATH.

-Brad



More information about the cmake-developers mailing list