<div>The behavior you&#39;re seeing is intentional.</div><div><br></div>In CMake itself we do the following 3 things to force a configuration even if the user does not run ctest with -C :<div><br></div><div><br></div><div>
(1) In the main CMakeLists.txt file:</div><div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo"># Set up test-time configuration.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo">SET_DIRECTORY_PROPERTIES(PROPERTIES</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo">  TEST_INCLUDE_FILE &quot;${CMake_BINARY_DIR}/Tests/EnforceConfig.cmake&quot;)</p><div><br></div><div><br></div>(2) Then in the Tests/CMakeLists file, we configure EnforceConfig.cmake:</div>
<div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo">CONFIGURE_FILE(${CMake_SOURCE_DIR}/Tests/<a href="http://EnforceConfig.cmake.in">EnforceConfig.cmake.in</a></p>

<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo">               ${CMake_BINARY_DIR}/Tests/EnforceConfig.cmake @ONLY)</p></div><div><br></div><div><br></div><div>(3) Then, in <a href="http://EnforceConfig.cmake.in">EnforceConfig.cmake.in</a>:</div>
<div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008419"><br></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008419"># Choose a configuration with which to drive CTest tests.</p>

<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo"><span style="color: #c22a9f">IF</span>(CTEST_CONFIGURATION_TYPE)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #da2e24"><span style="color: #000000">  </span><span style="color: #c22a9f">SET</span><span style="color: #000000">(CTestTest_CONFIG </span>&quot;${CTEST_CONFIGURATION_TYPE}&quot;<span style="color: #000000">)</span></p>

<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo"><span style="color: #c22a9f">ELSE</span>(CTEST_CONFIGURATION_TYPE)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo">  <span style="color: #c22a9f">SET</span>(CTestTest_CONFIG <span style="color: #da2e24">&quot;@CTestTest_CONFIG@&quot;</span>)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo"><span style="color: #c22a9f">ENDIF</span>(CTEST_CONFIGURATION_TYPE)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; min-height: 16.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008419"># Choose a configuration that was built if none is given.</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo"><span style="color: #c22a9f">IF</span>(<span style="color: #c22a9f">NOT</span> CTEST_CONFIGURATION_TYPE)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #da2e24"><span style="color: #000000">  </span><span style="color: #c22a9f">SET</span><span style="color: #000000">(CTEST_CMD </span>&quot;@CMAKE_CTEST_COMMAND@@CMAKE_EXECUTABLE_SUFFIX@&quot;<span style="color: #000000">)</span></p>

<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #c22a9f"><span style="color: #000000">  </span>GET_FILENAME_COMPONENT<span style="color: #000000">(CTEST_DIR </span><span style="color: #da2e24">&quot;${CTEST_CMD}&quot;</span><span style="color: #000000"> </span>PATH<span style="color: #000000">)</span></p>

<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #c22a9f"><span style="color: #000000">  </span>GET_FILENAME_COMPONENT<span style="color: #000000">(CTEST_EXE </span><span style="color: #da2e24">&quot;${CTEST_CMD}&quot;</span><span style="color: #000000"> </span>NAME<span style="color: #000000">)</span></p>

<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo">  <span style="color: #c22a9f">FOREACH</span>(cfg Release Debug MinSizeRel RelWithDebInfo)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo">    <span style="color: #c22a9f">IF</span>(<span style="color: #c22a9f">NOT</span> CTEST_CONFIGURATION_TYPE)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #da2e24"><span style="color: #000000">      </span><span style="color: #c22a9f">IF</span><span style="color: #000000">(</span><span style="color: #c22a9f">EXISTS</span><span style="color: #000000"> </span>&quot;${CTEST_DIR}/${cfg}/${CTEST_EXE}&quot;<span style="color: #000000">)</span></p>

<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo">        <span style="color: #c22a9f">SET</span>(CTEST_CONFIGURATION_TYPE ${cfg})</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #da2e24"><span style="color: #000000">      </span><span style="color: #c22a9f">ENDIF</span><span style="color: #000000">(</span><span style="color: #c22a9f">EXISTS</span><span style="color: #000000"> </span>&quot;${CTEST_DIR}/${cfg}/${CTEST_EXE}&quot;<span style="color: #000000">)</span></p>

<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo">    <span style="color: #c22a9f">ENDIF</span>(<span style="color: #c22a9f">NOT</span> CTEST_CONFIGURATION_TYPE)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #c22a9f"><span style="color: #000000">  </span>ENDFOREACH<span style="color: #000000">(cfg)</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo">  <span style="color: #c22a9f">IF</span>(<span style="color: #c22a9f">NOT</span> CTEST_CONFIGURATION_TYPE)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo">    <span style="color: #c22a9f">SET</span>(CTEST_CONFIGURATION_TYPE NoConfig)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo">  <span style="color: #c22a9f">ENDIF</span>(<span style="color: #c22a9f">NOT</span> CTEST_CONFIGURATION_TYPE)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #da2e24"><span style="color: #000000">  </span><span style="color: #c22a9f">MESSAGE</span><span style="color: #000000">(</span>&quot;Guessing configuration ${CTEST_CONFIGURATION_TYPE}&quot;<span style="color: #000000">)</span></p>

<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo"><span style="color: #c22a9f">ENDIF</span>(<span style="color: #c22a9f">NOT</span> CTEST_CONFIGURATION_TYPE)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; min-height: 16.0px"><br></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo">@TEST_HOME_ENV_CODE@</p></div><div><br></div><div><br></div><div>The net result is that EnforceConfig.cmake gets included at ctest time because of the TEST_INCLUDE_FILE directory property. And... even if the user does not use -C, CTEST_CONFIGURATION_TYPE gets set to a reasonable value at ctest time.</div>
<div><br></div><div><br></div><div>HTH,</div><div>David</div><div><br></div><div><br><div class="gmail_quote">On Mon, Aug 23, 2010 at 9:21 AM, Iman Brouwer <span dir="ltr">&lt;<a href="mailto:iman.brouwer@gmail.com">iman.brouwer@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hi Michael,<br>
<br>
I had tried the syntax you mention:<br>
<div class="im"><br>
ADD_TEST(NAME &quot;python test&quot;<br>
        COMMAND ${PYTHON_EXECUTABLE} $&lt;TARGET_FILE:my_test&gt;)<br>
<br>
</div>But what happened is that the test gets put in configuration-dependent<br>
if statements, e.g. the cTestTestfile.cmake looks similar to:<br>
<br>
IF(&quot;${CTEST_CONFIGURATION_TYPE}&quot; MATCHES &quot;^([Dd][Ee][Bb][Uu][Gg])$&quot;)<br>
      ADD_TEST(  ... path matching debug ...)<br>
ENDIF(&quot;${CTEST_CONFIGURATION_TYPE}&quot; MATCHES &quot;^([Dd][Ee][Bb][Uu][Gg])$&quot;)<br>
IF(&quot;${CTEST_CONFIGURATION_TYPE}&quot; MATCHES &quot;^([Rr][Ee][Ll][Ee][Aa][Ss][Ee])$&quot;)<br>
      ADD_TEST(  ... path matching release ...)<br>
ENDIF(&quot;${CTEST_CONFIGURATION_TYPE}&quot; MATCHES &quot;^([Rr][Ee][Ll][Ee][Aa][Ss][Ee])$&quot;)<br>
etc.<br>
<br>
Because of the if statements, the tests only show up when running<br>
ctest with a specific configuration, e.g. &quot;ctest -C Debug&quot; or &quot;ctest<br>
-C Release&quot;. They do not show up when running just &quot;ctest&quot;, even if<br>
ctest chooses to run a specific configuration anyway.<br>
<br>
On the other hand, when using add_test(testname Exename arg1 arg2<br>
...), the CTestTestfile.cmake contains an Exename that includes the<br>
basepath. In visual studio usually the basepath actually doesn&#39;t<br>
contain the executable. When ctest is run though, it actually replaces<br>
this basepath with the correct path (often basepath/Debug or<br>
basepath/Release).<br>
<br>
So apparently  when ctest is run without specifying a configuration,<br>
it knows where to find the executables that were build with cmake ( it<br>
knows to look into the right debug or release sub directory), it  just<br>
seems to do this substitution only for the second argument in add_test<br>
and i&#39;m wondering if it is possible to get the substitution for other<br>
arguments as well, for example by specifying a variable. Or is the<br>
recommended way to use the ADD_TEST( NAME... COMMAND ....) syntax and<br>
make sure people specify a configuration (e.g. run ctest -C ... )? My<br>
only problem with the latter is that if people forget to specify the<br>
configuration, not all tests will be run.<br>
<br>
Thanks,<br>
<font color="#888888"><br>
Iman<br>
</font><div><div></div><div class="h5"><br>
<br>
<br>
On Sat, Aug 21, 2010 at 1:21 PM, Michael Hertling &lt;<a href="mailto:mhertling@online.de">mhertling@online.de</a>&gt; wrote:<br>
&gt; On 08/20/2010 09:44 PM, Iman Brouwer wrote:<br>
&gt;&gt; Hello,<br>
&gt;&gt;<br>
&gt;&gt; The path to a binary target built by cmake depends on the<br>
&gt;&gt; configuration type when using the Visual Studio generators. Is it<br>
&gt;&gt; possible to pass this path the ctest without having to run ctest with<br>
&gt;&gt; the -c option?<br>
&gt;&gt;<br>
&gt;&gt; I&#39;d like to do the following:<br>
&gt;&gt; I create an executable with cmake as follows, and add a test for it:<br>
&gt;&gt;<br>
&gt;&gt; add_executable( my_test main.cpp )<br>
&gt;&gt; add_test( &quot;test_name&quot; my_test )<br>
&gt;&gt;<br>
&gt;&gt; Let&#39;s assume this executable gets built in bin_path\debug or<br>
&gt;&gt; bin_path\release, dependent on the configuration. Cmake generates the<br>
&gt;&gt; following line in the CTestTestfile.cmake:<br>
&gt;&gt;<br>
&gt;&gt; ADD_TEST( test_name &quot;bin_path/my_test&quot; )<br>
&gt;&gt;<br>
&gt;&gt; Note that the my_test path will not contain the executable, it will be<br>
&gt;&gt; in a configuration dependent subdirectory. However, when running<br>
&gt;&gt; &quot;ctest&quot;, ctest will automatically pick a configuration and will change<br>
&gt;&gt; the path in CTestTestfile.cmake to the right path for this<br>
&gt;&gt; configuration.<br>
&gt;&gt;<br>
&gt;&gt; In my case i&#39;d like to call a python script to which i pass the<br>
&gt;&gt; executables name including path, so i&#39;d to do something like:<br>
&gt;&gt;<br>
&gt;&gt; add_test( &quot;python test&quot; ${PYTHON_EXECUTABLE}  my_test )<br>
&gt;&gt;<br>
&gt;&gt; In this case, &quot;my_test&quot; does not get expanded in CTestTestfile.cmake<br>
&gt;&gt; to &quot;bin_path/my_test&quot;. Also, if I replace &quot;my_test&quot; here with<br>
&gt;&gt; &quot;bin_path/my_test&quot;, ctest will not do the automatic substitution to of<br>
&gt;&gt; the base path to the right configuration dependent path anymore.<br>
&gt;&gt;<br>
&gt;&gt; Alternatively, i tried replacing the add_test line with the add_test(<br>
&gt;&gt; NAME.... COMMAND ...)  syntax, but then all the tests are inside ctest<br>
&gt;&gt; configuration specific ifs. Basically the tests drops of the list of<br>
&gt;&gt; tests when just running &quot;ctest&quot;, it only appears when running ctest<br>
&gt;&gt; with an explicit configuration, e.g. &quot;ctest -C Debug&quot;.<br>
&gt;&gt;<br>
&gt;&gt; Is it possible to have ctest automatically figure out the right path<br>
&gt;&gt; to a cmake-built binary, without having to run ctest with an explicit<br>
&gt;&gt; configuration?<br>
&gt;<br>
&gt; AFAIK, the &quot;generator expressions&quot; have been added to ADD_TEST() in<br>
&gt; order to address this issue; have you already tried the following?<br>
&gt;<br>
&gt; ADD_TEST(NAME &quot;python test&quot;<br>
&gt;         COMMAND ${PYTHON_EXECUTABLE} $&lt;TARGET_FILE:my_test&gt;)<br>
&gt;<br>
&gt; Regards,<br>
&gt;<br>
&gt; Michael<br>
&gt; _______________________________________________<br>
&gt; Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
&gt;<br>
&gt; 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>
&gt;<br>
&gt; 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>
&gt;<br>
&gt; Follow this link to subscribe/unsubscribe:<br>
&gt; <a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br>
&gt;<br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</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>
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>
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></div>