[CMake] Re: CMake script return a value

Brad King brad.king at kitware.com
Wed Jul 19 15:08:08 EDT 2006


Brandon J. Van Every wrote:
> 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.

If you just need to know whether there was an error, have the script
exit with MESSAGE(FATAL_ERROR ...) in the error case.  Otherwise you can
add a feature request for an EXIT command or something like it.  There
is actually no reason that the same set of commands needs to be
available in project mode and script mode, so we could just add
scripting-specific commands like EXIT when needed.

-Brad



More information about the CMake mailing list