<div dir="ltr">Thanx, it worked!<div><br></div><div>You might even be surprised that it worked without the "<span style="font-size:12.8000001907349px">TO_NATIVE_PATH" - my Windows (8.1) seems to know how to handle "/" in the "PATH"! Nevertheless I'll use it, to be on the safe side.</span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 2, 2015 at 11:15 AM, Roger Leigh <span dir="ltr"><<a href="mailto:rleigh@codelibre.net" target="_blank">rleigh@codelibre.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 02/09/2015 08:40, Yaron Cohen-Tal wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
My project is a shared library, and my tests are linked to that shared<br>
library. When I try to run the tests, they fail because they can't find<br>
the DLL of the project. The "CMakeLists.txt" of the tests is in a<br>
different folder ("test/") than that of the shared lib ("src/"), and<br>
therefore they're built in different directories. Currently I'm using<br>
Visual Studio, and the DLL of the project is built in "src\Debug\", and<br>
the executables of the tests are built in "test\Debug\"; That is, for a<br>
debug build of course. What would be the best solution to b able to run<br>
the tests? I'm currently with Visual Studio but I guess the same problem<br>
would arise on Linux and OS X, and it should work there too.<br>
</blockquote>
<br>
On Linux/BSD/MacOS it's using rpath so it works without any special effort on your part.<br>
<br>
On Windows, you do need to set the test environment so it can find all the DLLs.  To do this, I did this for libtiff:<br>
<br>
<br>
macro(tiff_test_reader name command infile)<br>
  add_test(NAME "${name}"<br>
           COMMAND "${CMAKE_COMMAND}"<br>
           [... other options...]<br>
           "-DTIFFINFO=$<TARGET_FILE:tiffinfo>"<br>
           "-DLIBTIFF=$<TARGET_FILE:tiff>"<br>
           -P "${CMAKE_CURRENT_SOURCE_DIR}/TiffTest.cmake")<br>
endmacro()<br>
<br>
where TIFFINFO is an executable run by the test and LIBTIFF is the library used by this executable.  Note we pass these options as generator expressions so you can run "ctest -C Debug|Release" and have it use the executable and library from the debug or release build.<br>
<br>
TiffTest.cmake is a wrapper to run the test.  It's doing this:<br>
<br>
# Add the directory containing libtiff to the PATH (Windows only)<br>
if(WIN32)<br>
  get_filename_component(LIBTIFF_DIR "${LIBTIFF}" DIRECTORY)<br>
  file(TO_NATIVE_PATH "${LIBTIFF_DIR}" LIBTIFF_DIR)<br>
  set(ENV{PATH} "${LIBTIFF_DIR};$ENV{PATH}")<br>
endif()<br>
<br>
and then it runs the test command and specified options via execute_process().<br>
<br>
i.e. we've added a level of indirection when running the tests via a standalone cmake script.<br>
<br>
There may be better ways of doing this.  I'd certainly be keen to simplify things!<br>
<br>
<br>
Regards,<br>
Roger<br>
-- <br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/cmake" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/cmake</a><br>
</blockquote></div><br></div>