Dmitry, your suggestion will not work. He'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'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's a search for the exe in possible locations, so if multiple exist, it's possible to get the "wrong" one</div><div>
<br></div><div>Anyhow, here it is:</div><div><div><br></div><div># For an executable named "my"</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 "my" does not exist in "bin" then find the first one that</div><div># does exist in a configuration type subdir of "bin."</div><div># my_CMAKE_CONFIGURATION_TYPES is a list of possible configuration</div>
<div># types in "recommended" order. First existing one found wins.</div><div>#</div><div>SET(my_BASE_DIR "${CMAKE_BINARY_DIR}")</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 "${my_BASE_DIR}/bin/my${CMAKE_EXECUTABLE_SUFFIX}")</div><div>ENDIF(NOT my_EXECUTABLE)</div><div><br></div><div>IF(NOT EXISTS "${my_EXECUTABLE}")</div><div> FOREACH(my_CONFIGURATION_TYPE ${my_CMAKE_CONFIGURATION_TYPES})</div>
<div> IF(NOT EXISTS "${my_EXECUTABLE}")</div><div> IF(EXISTS "${my_BASE_DIR}/bin/${my_CONFIGURATION_TYPE}/my${CMAKE_EXECUTABLE_SUFFIX}")</div><div> SET(my_EXECUTABLE "${my_BASE_DIR}/bin/${my_CONFIGURATION_TYPE}/my${CMAKE_EXECUTABLE_SUFFIX}")</div>
<div> ENDIF(EXISTS "${my_BASE_DIR}/bin/${my_CONFIGURATION_TYPE}/my${CMAKE_EXECUTABLE_SUFFIX}")</div><div> ENDIF(NOT EXISTS "${my_EXECUTABLE}")</div><div> ENDFOREACH(my_CONFIGURATION_TYPE)</div><div>
ENDIF(NOT EXISTS "${my_EXECUTABLE}")</div><div><br></div><div>MESSAGE(STATUS "my_EXECUTABLE='${my_EXECUTABLE}'")</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"><<a href="mailto:dmitry.bely@gmail.com">dmitry.bely@gmail.com</a>></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 <<a href="mailto:shuston@riverace.com">shuston@riverace.com</a>> wrote:<br>
> Hi John,<br>
><br>
> Thanks for replying.<br>
><br>
>> On Fri, May 22, 2009 at 12:18 PM, Steve Huston<br>
>> <<a href="mailto:shuston@riverace.com">shuston@riverace.com</a>> wrote:<br>
>> > I'm using cmake for some cross-platform Linux/Windows stuff. When<br>
>> > ctest runs my tests, there is often the need to have a wrapper script<br>
>> > run the test - it sets up env variables (sometimes by reading the<br>
>> > content of a file), runs the test, scans log files, runs valgrind,<br>
>> > etc. So, I'm passing the actual test exe name to the script, and the<br>
>> > script runs it at the proper time.<br>
>> ><br>
>> > This works fine on Linux. On Windows, however, I'm having a problem<br>
>> > getting the actual path - when I get the LOCATION property, it has<br>
>> > $(OutDir) embedded. Visual Studio can substitute this in if<br>
> ctest/VS<br>
>> > is directly executing the test. However, if passed to the wrapper<br>
>> > script, the VS OutDir variable is not available. Is there a portable<br>
>> > way to get the test executable's path (either relative or complete) so<br>
>> > I can pass it to the wrapper script?<br>
>><br>
>> Shouldn't you already know the path in your CMakeLists.txt?<br>
>><br>
>> It should be somewhere off of<br>
>> ${PROJECT_BINARY_DIR}<br>
><br>
> "somewhere off of" is the operative phrase... Exactly where is what I<br>
> need to know. For example, in a Windows Debug build, it's in<br>
> ${PROJECT_BINARY_DIR}\Debug.<br>
<br>
</div></div>Why not to use something like this:<br>
<br>
if(MSVC_IDE)<br>
set(out_dir "$(OutDir)") # 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>