Dmitry, your suggestion will not work. He&#39;s asking how to achieve this from a wrapper script that he has written where $(OutDir) does not evaluate in the context of the script...<div><br></div><div>Steve, here&#39;s a technique that I use, but it has some caveats:</div>
<div>- it requires that the executable exist at the time of the script call</div><div>- it&#39;s a search for the exe in possible locations, so if multiple exist, it&#39;s possible to get the &quot;wrong&quot; one</div><div>
<br></div><div>Anyhow, here it is:</div><div><div><br></div><div># For an executable named &quot;my&quot;</div><div>#</div><div># If you make this part of a cmake -P script, you will have to pass in</div><div># CMAKE_BINARY_DIR and CMAKE_CONFIGURATION_TYPES with</div>
<div># -D *before* the -P...</div><div>#</div><div># If &quot;my&quot; does not exist in &quot;bin&quot; then find the first one that</div><div># does exist in a configuration type subdir of &quot;bin.&quot;</div><div># my_CMAKE_CONFIGURATION_TYPES is a list of possible configuration</div>
<div># types in &quot;recommended&quot; order. First existing one found wins.</div><div>#</div><div>SET(my_BASE_DIR &quot;${CMAKE_BINARY_DIR}&quot;)</div><div>SET(my_CMAKE_CONFIGURATION_TYPES ${CMAKE_CONFIGURATION_TYPES})</div>
<div>#</div><div># If you prefer a different search order than what is defined in CMAKE_CONFIGURATION_TYPES,</div><div># you may reorder them in my_CMAKE_CONFIGURATION_TYPES...</div><div><br></div><div>IF(NOT my_EXECUTABLE)</div>
<div>  SET(my_EXECUTABLE &quot;${my_BASE_DIR}/bin/my${CMAKE_EXECUTABLE_SUFFIX}&quot;)</div><div>ENDIF(NOT my_EXECUTABLE)</div><div><br></div><div>IF(NOT EXISTS &quot;${my_EXECUTABLE}&quot;)</div><div>  FOREACH(my_CONFIGURATION_TYPE ${my_CMAKE_CONFIGURATION_TYPES})</div>
<div>    IF(NOT EXISTS &quot;${my_EXECUTABLE}&quot;)</div><div>    IF(EXISTS &quot;${my_BASE_DIR}/bin/${my_CONFIGURATION_TYPE}/my${CMAKE_EXECUTABLE_SUFFIX}&quot;)</div><div>      SET(my_EXECUTABLE &quot;${my_BASE_DIR}/bin/${my_CONFIGURATION_TYPE}/my${CMAKE_EXECUTABLE_SUFFIX}&quot;)</div>
<div>    ENDIF(EXISTS &quot;${my_BASE_DIR}/bin/${my_CONFIGURATION_TYPE}/my${CMAKE_EXECUTABLE_SUFFIX}&quot;)</div><div>    ENDIF(NOT EXISTS &quot;${my_EXECUTABLE}&quot;)</div><div>  ENDFOREACH(my_CONFIGURATION_TYPE)</div><div>
ENDIF(NOT EXISTS &quot;${my_EXECUTABLE}&quot;)</div><div><br></div><div>MESSAGE(STATUS &quot;my_EXECUTABLE=&#39;${my_EXECUTABLE}&#39;&quot;)</div><div><br></div><div><br></div><div>Good luck!</div><div><br></div><div>Hope this helps,</div>
<div>David</div><div><br></div><div><br></div><br><div class="gmail_quote">On Sat, May 23, 2009 at 2:35 AM, Dmitry Bely <span dir="ltr">&lt;<a href="mailto:dmitry.bely@gmail.com">dmitry.bely@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;"><div><div></div><div class="h5">On Fri, May 22, 2009 at 11:46 PM, Steve Huston &lt;<a href="mailto:shuston@riverace.com">shuston@riverace.com</a>&gt; wrote:<br>

&gt; Hi John,<br>
&gt;<br>
&gt; Thanks for replying.<br>
&gt;<br>
&gt;&gt; On Fri, May 22, 2009 at 12:18 PM, Steve Huston<br>
&gt;&gt; &lt;<a href="mailto:shuston@riverace.com">shuston@riverace.com</a>&gt; wrote:<br>
&gt;&gt; &gt; I&#39;m using cmake for some cross-platform Linux/Windows stuff. When<br>
&gt;&gt; &gt; ctest runs my tests, there is often the need to have a wrapper script<br>
&gt;&gt; &gt; run the test - it sets up env variables (sometimes by reading the<br>
&gt;&gt; &gt; content of a file), runs the test, scans log files, runs valgrind,<br>
&gt;&gt; &gt; etc. So, I&#39;m passing the actual test exe name to the script, and the<br>
&gt;&gt; &gt; script runs it at the proper time.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; This works fine on Linux. On Windows, however, I&#39;m having a problem<br>
&gt;&gt; &gt; getting the actual path - when I get the LOCATION property, it has<br>
&gt;&gt; &gt; $(OutDir) embedded. Visual Studio can substitute this in if<br>
&gt; ctest/VS<br>
&gt;&gt; &gt; is directly executing the test. However, if passed to the wrapper<br>
&gt;&gt; &gt; script, the VS OutDir variable is not available. Is there a portable<br>
&gt;&gt; &gt; way to get the test executable&#39;s path (either relative or complete) so<br>
&gt;&gt; &gt; I can pass it to the wrapper script?<br>
&gt;&gt;<br>
&gt;&gt; Shouldn&#39;t you already know the path in your CMakeLists.txt?<br>
&gt;&gt;<br>
&gt;&gt; It should be somewhere off of<br>
&gt;&gt; ${PROJECT_BINARY_DIR}<br>
&gt;<br>
&gt; &quot;somewhere off of&quot; is the operative phrase... Exactly where is what I<br>
&gt; need to know. For example, in a Windows Debug build, it&#39;s in<br>
&gt; ${PROJECT_BINARY_DIR}\Debug.<br>
<br>
</div></div>Why not to use something like this:<br>
<br>
if(MSVC_IDE)<br>
  set(out_dir &quot;$(OutDir)&quot;) # expanded by Visual Studio<br>
else(MSVC_IDE)<br>
  set(out_dir ${PROJECT_BINARY_DIR})<br>
endif(MSVC_IDE)<br>
<br>
Nmake generator (instead of Visual Studio one) could be another option.<br>
<font color="#888888"><br>
- Dmitry Bely<br>
</font><div><div></div><div class="h5">_______________________________________________<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>