[Cmake] EXEC_PROGRAM and subdirs
Brad King
brad.king at kitware.com
Tue Sep 14 12:43:25 EDT 2004
klaas.holwerda wrote:
> Indeed i want to use the result, which looks like a normal variable.
You need to save the result in a cache variable. Then it will be
available in subdirectories. It will also prevent the program from
being executed every time cmake runs.
IF(DEFINED FOO_RESULT)
# Foo was already run and the result saved. Just use FOO_RESULT.
ELSE(DEFINED FOO_RESULT)
# Foo has not been run. Run it and save the result in the cache.
EXEC_PROGRAM(foo ARGS bar OUTPUT_VARIABLE OUT)
SET(FOO_RESULT "${OUT}" CACHE INTERNAL "result of running foo")
ENDIF(DEFINED FOO_RESULT)
You may, of course, add another condition to cause the program to be
re-executed.
>> 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
> What is meant by that?
We may introduce a new order in which the listfiles are processed.
Currently there is no way for a higher level listfile to access a
variable from one of its subdirectories' listfiles. Listfiles are
processed in a pre-order visit of the tree. We may in the future
provide a way to have an in-order visit of the tree.
-Brad
More information about the Cmake
mailing list