[CMake] Re: CMake script return a value
Brandon J. Van Every
bvanevery at gmail.com
Sat Jul 15 20:04:04 EDT 2006
Brandon J. Van Every wrote:
> Can a CMake script invoked with
>
> EXECUTE_PROCESS(
> COMMAND ${CMAKE_COMMAND} -P myscript.cmake
> RESULT_VARIABLE myresult
> )
>
> return a value? I don't really want to use stdout. I need that for
> status messages. I could regex the stdout to extract a decorated
> string, but that's bletcherous. What I want is to do something like
> RETURN(${value}) and have RESULT_VARIABLE pick it up.
I realized a further problem, that ADD_CUSTOM_COMMAND and
ADD_CUSTOM_TARGET can't have EXECUTE_PROCESS in them. They can only
call scripts, and the scripts do not return values. So, there's no way
to directly return a value from a script to a build rule.
To get around this, I have my script write out a file, and I denote that
file as the output of a custom build rule, i.e.
ADD_CUSTOM_COMMAND(
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ResultFile
COMMAND ${CMAKE_COMMAND} -P myscript.cmake
)
Other custom commands can invoke scripts that read the ResultFile. Data
floats around in a universe of scripts and files, driven by build rules
that don't know what's going on. It's awkward having this separation,
between build rules and scripts, but it's workable. Doesn't feel very
nice compared to using a proper scripting language though.
Cheers,
Brandon Van Every
More information about the CMake
mailing list