<br><br><div class="gmail_quote">On Thu, Sep 8, 2011 at 3:39 PM, David Cole <span dir="ltr">&lt;<a href="mailto:david.cole@kitware.com">david.cole@kitware.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="h5">On Thu, Sep 8, 2011 at 9:30 AM, Delphinus Delphinus wrote:<br>
&gt; Hi all,<br>
&gt;<br>
&gt; I am using the Qt module QTestLib to do some tests on my application<br>
&gt; (windows, MSVC 2008) that has been all set up with CMake.<br>
&gt;<br>
&gt; A test I have created with QTestLib is executed, all output is sent to the<br>
&gt; command window. Since I want it to a file, I used what Qt suggest to<br>
&gt; redirect all output: -xml -o my_file.xml<br>
&gt; so I do this in my CMake file:<br>
&gt;<br>
&gt; add_test ( NAME   ${PROJECT_NAME}   COMMAND   ${PROJECT_NAME} -xml -o<br>
&gt; log/foo.xml )<br>
&gt;<br>
&gt; So now, when I do the &quot;run_test&quot; through visual, my test is run and my file<br>
&gt; is created (so far so good!).<br>
&gt;<br>
&gt;<br>
&gt; My problem is that I want the name of the file to be time and date dependant<br>
&gt; (log20110908140230.xml - a year, month, day, hour, minute and second<br>
&gt; format).<br>
&gt;<br>
&gt; So I have considered the following solution (I did not succeed in<br>
&gt; implementing it so far):<br>
&gt; I want to execute a script, just after the execution of my test that will<br>
&gt; rename the result file generated.<br>
&gt; --&gt; Here I don&#39;t know how I can tell CMake to execute my script just when<br>
&gt; the test has been executed ?<br>
&gt;<br>
&gt; NB: I do NOT have any problem creating a script that rename a foo.xml file<br>
&gt; to a log20110908140230.xml file (my script.bat file is already ready). The<br>
&gt; problem is how to make this script to be executed just after the test<br>
&gt; execution.<br>
&gt;<br>
&gt;<br>
&gt; Any insight is welcomed on how to implement my suggestion (or if you have<br>
&gt; another choice, I&#39;m all ears :)! ).<br>
&gt;<br>
&gt;<br>
</div></div><br>
You can either:<br>
<br>
(1) execute your script as an additional test that depends on the<br>
first one (so that guarantees it to run *after* the test, even in<br>
parallel testing scenarios, although not necessarily *immediately*<br>
after)<br>
<br>
or<br>
<br>
(2) execute a single script as the test itself, and then inside that<br>
script, execute the real test first, followed immediately by the<br>
script your already have...<br>
<br>
I would do option #2 if I were you. :-)<br>
<br>
You can probably find other examples of this by googling around for<br>
&quot;add_test script cmake&quot; ( one of the hits is another reply I made<br>
previously on this list:<br>
<a href="http://www.cmake.org/pipermail/cmake/2011-May/044180.html" target="_blank">http://www.cmake.org/pipermail/cmake/2011-May/044180.html</a> )<br>
<br>
<br>
HTH,<br>
<font color="#888888">David<br>
</font></blockquote></div><br><br>Thanks. And yes, it helped !<br><br>I chose option #2.<br><br>I created a runAndRename.cmake file:<br>&lt;&lt;&lt;&lt;&lt;<br>macro(COMMAND_EXEC1 P_COMMAND)<br>    execute_process(COMMAND ${P_COMMAND} -xml -o log/foo.xml RESULT_VARIABLE RESULT_VAR_COMMAND)<br>
    if(RESULT_VAR_COMMAND)<br>        message(FATAL_ERROR &quot;Error ${P_COMMAND}&quot;)<br>    endif()<br>endmacro()<br><br>macro(COMMAND_EXEC2 P_COMMAND)<br>    execute_process(COMMAND ${P_COMMAND} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} RESULT_VARIABLE RESULT_VAR_COMMAND)<br>
    if(RESULT_VAR_COMMAND)<br>        message(FATAL_ERROR &quot;Error ${P_COMMAND}&quot;)<br>    endif()<br>endmacro()<br><br>COMMAND_EXEC1(${COMMAND1})<br>COMMAND_EXEC2(${COMMAND2})<br>&gt;&gt;&gt;&gt;&gt;<br><br>And then in my CMakeLists.txt, I have now:<br>
&lt;&lt;&lt;&lt;&lt;<br>add_test( NAME ${PROJECT_NAME} COMMAND &quot;${CMAKE_COMMAND}&quot; -DCOMMAND1=$&lt;TARGET_FILE:${PROJECT_NAME}&gt;<br>                                                          -DCOMMAND2=renameExe<br>
                                                          -P &quot;${CMAKE_CURRENT_SOURCE_DIR}/runAndRename.cmake&quot;)<br>&gt;&gt;&gt;&gt;&gt;<br><br>It is working for me, even though there is still a lot of room for improvement:<br>
- I did not find the proper way to pass the needed arguments (-xml -o filename) ... so I created two macros :(.<br>- And I spent most of my time figuring out that I should &quot;transform&quot; myScript.BAT to a myScript.EXE to make my second part work !<br>
<br>I&#39;ll look into those later...<br><br>