<div dir="ltr">Hi David, <br><br><div><div><div>You need to escape the "$" sign otherwise the "_err", "_out" and "_res" variables are resolved to an empty string.<br><br></div>Here is an example of what you could do:<br>
<br>-------------8<-----------8<----------<br>cmake_minimum_required(VERSION 2.8.9)<br><br>install(CODE "execute_process (<br> COMMAND ${CMAKE_COMMAND} -E echo \"Hello\"<br> OUTPUT_VARIABLE _out<br>
ERROR_VARIABLE _err<br> RESULT_VARIABLE _res<br> )" <br> )<br>install(CODE "message( STATUS \"out: \${_out}, err: \${_err}, res: \${_res}...\")")<br>-------------8<-----------8<----------<br>
<br></div>Hth<br></div>Jc<br><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Nov 13, 2013 at 2:29 PM, David Hauck <span dir="ltr"><<a href="mailto:davidh@netacquire.com" target="_blank">davidh@netacquire.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Kornel,<br>
<div><div><br>
On Wednesday, November 13, 2013 11:08 AM, <a href="mailto:cmake-bounces@cmake.org" target="_blank">cmake-bounces@cmake.org</a> wrote:<br>
> Am Mittwoch, 13. November 2013 um 18:41:03, schrieb David Hauck<br>
> <<a href="mailto:davidh@netacquire.com" target="_blank">davidh@netacquire.com</a>><br>
>> Hi Kornel,<br>
>><br>
>> On Wednesday, November 13, 2013 10:26 AM, cmake-<br>
> <a href="mailto:bounces@cmake.org" target="_blank">bounces@cmake.org</a> wrote:<br>
>>> Am Mittwoch, 13. November 2013 um 18:12:26, schrieb David Hauck<br>
>>> <<a href="mailto:davidh@netacquire.com" target="_blank">davidh@netacquire.com</a>><br>
>>>> Hello,<br>
>>>><br>
>>>> I've been using several "install (CODE "EXECUTE_PROCESS ...")"<br>
>>>> constructs<br>
>>> in my top-level CMakeLists.txt file. However, I've been unable to<br>
>>> capture/operate on any exit status of the embedded command.<br>
>>> Unfortunately, documentation/searches haven't turned up any useful<br>
>>> pointers. The closest I've come is a pointer in the following thread:<br>
>>>> <a href="http://www.cmake.org/pipermail/cmake/2011-July/045475.html" target="_blank">http://www.cmake.org/pipermail/cmake/2011-July/045475.html</a> However,<br>
>>>> I've not been able to sufficiently read between the lines to get<br>
>>>> this working.<br>
>>>><br>
>>>> Does anyone have any thoughts on how to get something like the<br>
>>>> following working:<br>
>>>><br>
>>>> install (CODE "EXECUTE_PROCESS (<br>
>>>> COMMAND ant ...<br>
>>>> WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/java<br>
>>>> ERROR_VARIABLE _err<br>
>>><br>
>>> Didn't you mean 'RESULT_VARIABLE' here?<br>
>><br>
>> No, I really do mean ERROR_VARIABLE (unless, of course, this variable<br>
>> does<br>
> not include the non-zero exit status of the EXECUTE_PROCESS command?).<br>
><br>
> If you run 'cmake --help-command execute_process', you see: ... If<br>
> RESULT_VARIABLE is given the variable will be set to contain the<br>
> result of running the processes. This will be an integer return code<br>
> from the last child or a string describing an error condition. ... So,<br>
> if this is not "0", then you have an error condition.<br>
<br>
</div></div>Yes, I see this. I also assumed that the ERROR_VARIABLE would be returning non-zero text as well in this case. I will change to using RESULT_VARIABLE, but, in both cases, it seems that I'm referencing the variable incorrectly (either syntactically or in the incorrect context) since this/these is/are always <empty>.<br>
<div><br>
>> BTW, I'm still curious about the (dual 'code') construct generally.<br>
>> Specifically, if I do the following I never see the fatal error<br>
>> message (so I'm wondering if there's still something wrong regarding<br>
>> the scoping of the message command)?<br>
>><br>
>> install (CODE "EXECUTE_PROCESS (<br>
>> COMMAND ant ...<br>
>> WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/java<br>
>> ERROR_VARIABLE _err<br>
>> )<br>
>> MESSAGE( FATAL_ERROR \"err: ${_err}\")<br>
><br>
> Never did this. When do you want to see the message?<br>
<br>
</div>Ideally, I want to be able to test for the result of this variable (either ERROR_VARIABLE or RESULT_VARIABLE) after the execute_process command completes (during 'make install') to determine its result and to terminate (with error message) when the command fails.<br>
<br>
Thanks,<br>
-David<br>
<div><br>
> As I understand your code, only in call of cmake, e.g. at configuration time.<br>
><br>
> Kornel<br>
</div><div><div>--<br>
<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" target="_blank">http://cmake.org/cmake/help/training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><a href="tel:%2B1%20919%20869%208849" value="+19198698849" target="_blank">+1 919 869 8849</a><br>
</div></div>