[CMake] relative CMAKE_MODULE_PATH

Johannes Stallkamp johannes.stallkamp at rub.de
Mon Feb 16 05:26:42 EST 2009


Hello list,

is it possible to set a relative path as CMAKE_MODULE_PATH ? I
actually had problems with that (CMake 2.6.3-RC 8)
Is it because the relative path would be resolved w.r.t current build
dir and not w.r.t. to the directory with CMakeLists.txt ?

Reason:
I want to point CMAKE_MODULE_PATH to a directory in the source tree
which contains a file with a couple of cmake macros and some
customized modules.

These should be available in all projects. These projects may be
located at varying depth within the tree.
e.g. (simplified view)

ROOT
|-common components
    |-libraryA
    |-libraryB
    |-CMakeMacros
|-applicationA
    |-subcomponentA  
    |-plugins
        |-pluginA
        |-pluginB
        |-pluginC
|-applicationB


Initially, I just used

INCLUDE( "../../CMakeMacros/localmacros.cmake")
( ../ varying according to project location, of course )

which is fine, as long as I only want to use that single file but
creates problems if I want to add custom/customized modules.

However,
    SET( CMAKE_MODULE_PATH "../../CMakeModules")
    INCLUDE( localmacros )
does not work. CMake complains that it cannot find that file.

My current workaround is
    SET( CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/../../CMakeModules")
    INCLUDE( localmacros )


Is that necessary or is there a more elegant way I'm not aware of?

Kind Regards
Johannes



More information about the CMake mailing list