[Cmake] EXEC_PROGRAM and it's output variable

William A. Hoffman billlist at nycap.rr.com
Fri, 06 Feb 2004 14:39:40 -0500


OK, I see the problem.  
The EXEC_COMMAND is not an inherited command.
This means it will not be re-run by the sub directory
cmakelist files.  So, the value is not set in the sub directory.

I did get your example to work like this:

EXEC_PROGRAM(date
  ARGS +%Y%m%d
  OUTPUT_VARIABLE BUILD_DATE_EXEC
)

# check to see if BUILD_DATE_EXEC is unset
# unset variables match exactly the name of the variable
IF(BUILD_DATE_EXEC MATCHES "^BUILD_DATE_EXEC$")
ELSE(BUILD_DATE_EXEC MATCHES "^BUILD_DATE_EXEC$")
# if BUILD_DATE_EXEC has a value then cache the value
# so that BUILD_DATE can be seen in all sub directories of
# the project
  SET(BUILD_DATE ${BUILD_DATE_EXEC} CACHE INTERNAL "" FORCE)
ENDIF(BUILD_DATE_EXEC MATCHES "^BUILD_DATE_EXEC$")


However, all that said and done, I am not sure this is really what
you want.  This date will be the date that cmake was last run, and
will have little to do with when the software was actually built.
I can run cmake, and build the code a month latter without changing cmake.
You may want to look at a custom command.  Also, you might want to consider
using __DATE__ as defined by the c++ compiler.

-Bill

At 02:16 PM 2/6/2004, Terry Lorber wrote:
>FYI: If EXEC_PROGRAM and CONFIGURE_FILE are in the same location, it works.
>
>tgl
>----------------------------------
>PROJECT(Config)
>
>EXEC_PROGRAM(date
>  ARGS +%Y%m%d
>  OUTPUT_VARIABLE BUILD_DATE
>)
>
>CONFIGURE_FILE(${Config_SOURCE_DIR}/builddate.h.in
>  ${Config_BINARY_DIR}/builddate.h
>)
>
>
>
>
>_______________________________________________
>Cmake mailing list
>Cmake at www.cmake.org
>http://www.cmake.org/mailman/listinfo/cmake