<div dir="ltr"><div><div>Hi, <br><br></div>You also need to add the "if" statement into the "CODE" parameter, for example something like this ... <br><br>install(CODE "If (NOT \${_res} EQUAL "0")<br>
message( FATAL_ERROR \"out: \${_out}, err: \${_err}, res: \${_res}\")<br></div> endif()<br><div>")<br><br></div><div>To keep things simpler, you could also look at "INSTALL(SCRIPT ...)" it would allow you to avoid escaping. You would just need to configure the script using "configure_file".<br>
<br>Hth<br>Jc<br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Nov 13, 2013 at 2:57 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"><div class="im">On Wednesday, November 13, 2013 11:42 AM, David Hauck wrote:<br>
> Hi Jean-christophe,<br>
><br>
> On <a href="mailto:chris.fillionr@kitware.com">chris.fillionr@kitware.com</a>], Jean-Christophe Fillion-Robin wrote:<br>
</div><div class="im">>> Hi David,<br>
>><br>
>> You need to escape the "$" sign otherwise the "_err", "_out" and "_res"<br>
>> variables are resolved to an empty string.<br>
>><br>
>> Here is an example of what you could do:<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:<br>
>> \${_res}...\")") -------------8<-----------8<----------<br>
><br>
</div><div class="im">> Aha! This was probably obvious to you and Kornel, but it "escaped" me ;).<br>
> Brilliant, this is working fine now.<br>
<br>
</div>One last item here: I'm now able to see the resulting variable values in the message command output, but I'd now like to enclose this in an 'if' command. Something like:<br>
<div class="im"><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>
</div>If (NOT \${_res} EQUAL "0") # escaping here has not effect one way or the other...<br>
install(CODE "message( FATAL_ERROR \"out: \${_out}, err: \${_err}, res: \${_res}\")")<br>
endif ()<br>
<br>
However, the resulting cmake_install.cmake has the following (meaning the fatal error message will always be executed regardless of the value of '_res"):<br>
<div class="im"><br>
IF(NOT CMAKE_INSTALL_COMPONENT OR "${CMAKE_INSTALL_COMPONENT}" STREQUAL "Unspecified")<br>
</div> MESSAGE( FATAL_ERROR "out: ${_out}, err: ${_err}, res: ${_res}...")<br>
<div class="im">ENDIF(NOT CMAKE_INSTALL_COMPONENT OR "${CMAKE_INSTALL_COMPONENT}" STREQUAL "Unspecified")<br>
<br>
</div>Is there a way to do this?<br>
<br>
-David<br>
<div class="im"><br>
> Thanks to both of you for your help,<br>
> -David<br>
><br>
</div><div class="im">>> Hth<br>
>> Jc<br>
>><br>
>> On Wed, Nov 13, 2013 at 2:29 PM, David Hauck <<a href="mailto:davidh@netacquire.com">davidh@netacquire.com</a>><br>
>> wrote:<br>
>> Hi Kornel,<br>
>><br>
</div>>> On Wednesday, November 13, 2013 11:08 AM, cmake- <a href="mailto:bounces@cmake.org">bounces@cmake.org</a><br>
>> wrote: > Am Mittwoch, 13. November 2013 um 18:41:03, schrieb David<br>
<div class="HOEnZb"><div class="h5">>> Hauck > <<a href="mailto:davidh@netacquire.com">davidh@netacquire.com</a>> >> Hi Kornel, >> >> On Wednesday,<br>
>> November 13, 2013 10:26 AM, cmake- > <a href="mailto:bounces@cmake.org">bounces@cmake.org</a> wrote: >>> Am<br>
>> Mittwoch, 13. November 2013 um 18:12:26, schrieb David Hauck >>><br>
>> <<a href="mailto:davidh@netacquire.com">davidh@netacquire.com</a>> >>>> Hello, >>>> >>>> I've been using<br>
>> several "install (CODE "EXECUTE_PROCESS ...")" >>>> constructs >>> in<br>
>> 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-" target="_blank">http://www.cmake.org/pipermail/cmake/2011-</a> July/045475.html<br>
>> However, >>>> I've not been able to sufficiently read between the<br>
>> lines to get >>>> this working. >>>> >>>> Does anyone have any<br>
>> thoughts on how to get something like the >>>> following working:<br>
>> >>>> >>>> install (CODE "EXECUTE_PROCESS ( >>>> COMMAND ant<br>
>> ... >>>> WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/java >>>><br>
>> ERROR_VARIABLE _err >>> >>> Didn't you mean 'RESULT_VARIABLE' here?<br>
>> >> >> No, I really do mean ERROR_VARIABLE (unless, of course, this<br>
>> variable >> does > not include the non-zero exit status of the<br>
>> EXECUTE_PROCESS command?). > > If you run 'cmake --help-command<br>
>> execute_process', you see: ... If > RESULT_VARIABLE is given the<br>
>> variable will be set to contain the > result of running the processes.<br>
>> This will be an integer return code > from the last child or a string<br>
>> describing an error condition. ... So, > if this is not "0", then you<br>
>> have an error condition.<br>
>><br>
>> Yes, I see this. I also assumed that the ERROR_VARIABLE would be<br>
>> returning non-zero text as well in this case. I will change to using<br>
>> RESULT_VARIABLE, but, in both cases, it seems that I'm referencing<br>
>> the variable incorrectly (either syntactically or in the incorrect<br>
>> context) since this/these is/are always <empty>.<br>
>><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)? >> >> install (CODE<br>
>> "EXECUTE_PROCESS ( >> COMMAND ant ... >> WORKING_DIRECTORY<br>
>> ${PROJECT_SOURCE_DIR}/java >> ERROR_VARIABLE _err >> ) >><br>
>> MESSAGE( FATAL_ERROR \"err: ${_err}\") > > Never did this. When do<br>
>> you want to see the message?<br>
>><br>
>> Ideally, I want to be able to test for the result of this variable<br>
>> (either ERROR_VARIABLE or RESULT_VARIABLE) after the execute_process<br>
>> command completes (during 'make install') to determine its result<br>
>> and to terminate (with error message) when the command fails.<br>
>><br>
>> Thanks,<br>
>> -David<br>
>><br>
>> > As I understand your code, only in call of cmake, e.g. at<br>
>> configuration time.<br>
>> ><br>
>> > Kornel<br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>+1 919 869 8849<br>
</div>