[Cmake] EXEC_PROGRAM and subdirs

Brad King brad.king at kitware.com
Mon Sep 13 14:02:35 EDT 2004


klaas.holwerda wrote:
> What can be the reason, that the following peace of cmake script ( which 
> is include in the some CMakeLists.txt),
> contains in the top makefile the first part of the if  as result, but in 
> a SUBDIR directory the second part?
> If i but a MESSAGE i only see it once, and the right part as expected by 
> me.
> Somehow Cmake seems to NOT execute the program under certain conditions 
> e.g. subdirs.?
> 
> It makes no sence to me at all, some help is much appreciated.
> 
>    EXEC_PROGRAM( ${CMAKE_WX_CONFIG} ARGS --cflags OUTPUT_VARIABLE GTK2 )
>        # assume wxWidget has "gtk2" in its include strings
>        IF ( GTK2 MATCHES "^.*gtk2*" )
>            SET( CMAKE_WX_CXX_FLAGS "${CMAKE_WX_CXX_FLAGS} 
> ${CMAKE_PKGCONFIG_C_FLAGS}" )
>        ELSE ( GTK2 MATCHES "^.*gtk2*" )                  SET( 
> CMAKE_WX_CXX_FLAGS "${CMAKE_WX_CXX_FLAGS} `gtk-config --cflags`" )
>        ENDIF ( GTK2 MATCHES "^.*gtk2*" )

Most cmake commands are "inherited" into subdirectories, but certain 
commands such as EXEC_PROGRAM are not.  The idea is that any command 
that actually performs an action outside CMake such as EXEC_PROGRAM or 
CONFIGURE_FILE is not inherited because we do not want it to execute 
from the subdirectories.  Other commands such as IF and SET are 
inherited so that their results are available for subdirectories to use.

All of this is due to historical reasons.  It was not originally 
expected that EXEC_PROGRAM would be used in a way that would affect the 
flow of CMake code evaluation.  The original version of the command did 
not have an OUTPUT_VARIABLE argument.  When the argument was added the 
command was not made inherited.

Eventually there will be a new methodology in place for listfile 
evaluation order which will resolve this problem.  For now you will have 
to find a work-around for the problem.  You can probably save some 
information in an internal cache entry so that it is available from the 
subdirectories also.

-Brad


More information about the Cmake mailing list