[CMake] Puzzle about CMAKE_MODULE_PATH

Brad King brad.king at kitware.com
Wed Sep 14 16:24:31 EDT 2005


Mark Foskey wrote:
>>> I also set a variable so that the SNAP CMakeLists.txt file calls 
>>> FIND_PACKAGE(ITK) and FIND_PACKAGE(VTK).
>> Environment variables are not CMake cache variables.  Setting them is 
>> useless. 
> Not in this case, because FindITK.cmake has the lines:
> 
>   FIND_PATH(ITK_DIR ITKConfig.cmake
>     # Look for an environment variable ITK_DIR.
>     $ENV{ITK_DIR}

Okay, when the FindFOO.cmake is not found by FIND_PACKAGE it instead 
creates a FOO_DIR cache variable that it wants set to the location of a 
FOOConfig.cmake file.  When CMake cannot find the modules then 
FindITK.cmake is not found so the latter behavior is used.  In the case 
of the latter behavior the environment variables are not used.

>>> This is mysterious to me.  I think ccmake is finding the Modules 
>>> directory even without the CMAKE_MODULE_PATH, since it otherwise runs 
>>> OK, and since the modules directory is findable (via a softlink) as 
>>> ${CMAKE_ROOT}/Modules.  So why does it behave differently, apparently 
>>> not using Modules/FindITK.cmake, when CMAKE_MODULE_PATH is not set?
>>
>> What do you mean by "via a softlink"?  The whole CMake install tree 
>> should be extracted together in one tree with no symlinks.  Did you 
>> customize your installation?
> 
> Yes.  A 'bin' directory in AFS space has a softlink to the correct 
> ccmake executable for the given hardware platform, and softlinks to 
> 'Modules' and two other associated directories.  Apparently it doesn't 
> follow the softlink to find the FindFOO.cmake files in Modules.  I will 
> try fixing our setup.

CMake complains on startup if it cannot find CMAKE_ROOT.  CMAKE_ROOT 
must be a directory under which the file Modules/CMake.cmake is found. 
Therefore CMAKE_ROOT must have been found or CMake would not get to the 
point of executing the FIND_PACKAGE command.  If CMAKE_ROOT is set then 
it should be able to find ${CMAKE_ROOT}/Modules/FindITK.cmake.  I have 
no idea how this can be happening.  Try putting a

MESSAGE("CMAKE_ROOT=[${CMAKE_ROOT}]")

in the project to see what path is being used.

-Brad


More information about the CMake mailing list