[CMake] PROJECT_SOURCE_DIR needs two cMake pass to be set

Bill Hoffman bill.hoffman at kitware.com
Mon Jan 8 17:35:48 EST 2007


Julien BIBOLLET wrote:
> Hi,
> I've simplified a problem I'm encountering:
> I have following hierarchie:
> |--proj1
> |--|--CMakeLists.txt
> |--CMakeLists.txt
>
> the proj1/CMakeLists.txt contains:
> PROJECT( PROJ1 )
> SET( PROJ1_SRCS main.cc )
> ADD_LIBRARY( PROJ1 STATIC ${PROJ1_SRCS} )
>
> and the ./CMakeLists.txt contains:
> SUBDIRS(proj1)
> MESSAGE ( STATUS "PROJ1_SOURCE_DIR: ${PROJ1_SOURCE_DIR}")
>
> now, when I run a cmake ., the PROJ1_SOURCE_DIR value is "", and if I 
> then rerun cmake . then the value is correct. Why does it need two 
> cMake pass to be correct, and is it possible to have it done in one ?
There can be more than one PROJECT command in a cmake project. 
The fact that it works the second time is a side effect of it being stored
in the cache.  If you use ADD_SUBDIRECTORY instead of SUBDIRS
it will work as you have it.  SUBDIRS due to backwards compatibility issue
is done at the end of the cmake list file no matter where it really 
shows up.

-Bill



More information about the CMake mailing list