[CMake] Unable to locate the project's shared library when running the tests

J Decker d3ck0r at gmail.com
Wed Sep 2 13:20:05 EDT 2015


On Wed, Sep 2, 2015 at 8:40 AM, Yaron Cohen-Tal <yaronct at gmail.com> wrote:
> Thanx, it worked!
>
> You might even be surprised that it worked without the "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.
>
I'm not surprised. It would work on NT 3.51.
Windows never cared about the direction of slashes in file paths. It's
only applications that do.
(command line arguments often used '/' so they use it as a flag that
it should be an argument)

> On Wed, Sep 2, 2015 at 11:15 AM, Roger Leigh <rleigh at codelibre.net> wrote:
>>
>> On 02/09/2015 08:40, Yaron Cohen-Tal wrote:
>>>
>>> Hi,
>>>
>>> My project is a shared library, and my tests are linked to that shared
>>> library. When I try to run the tests, they fail because they can't find
>>> the DLL of the project. The "CMakeLists.txt" of the tests is in a
>>> different folder ("test/") than that of the shared lib ("src/"), and
>>> therefore they're built in different directories. Currently I'm using
>>> Visual Studio, and the DLL of the project is built in "src\Debug\", and
>>> the executables of the tests are built in "test\Debug\"; That is, for a
>>> debug build of course. What would be the best solution to b able to run
>>> the tests? I'm currently with Visual Studio but I guess the same problem
>>> would arise on Linux and OS X, and it should work there too.
>>
>>
>> On Linux/BSD/MacOS it's using rpath so it works without any special effort
>> on your part.
>>
>> 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:
>>
>>
>> macro(tiff_test_reader name command infile)
>>   add_test(NAME "${name}"
>>            COMMAND "${CMAKE_COMMAND}"
>>            [... other options...]
>>            "-DTIFFINFO=$<TARGET_FILE:tiffinfo>"
>>            "-DLIBTIFF=$<TARGET_FILE:tiff>"
>>            -P "${CMAKE_CURRENT_SOURCE_DIR}/TiffTest.cmake")
>> endmacro()
>>
>> 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.
>>
>> TiffTest.cmake is a wrapper to run the test.  It's doing this:
>>
>> # Add the directory containing libtiff to the PATH (Windows only)
>> if(WIN32)
>>   get_filename_component(LIBTIFF_DIR "${LIBTIFF}" DIRECTORY)
>>   file(TO_NATIVE_PATH "${LIBTIFF_DIR}" LIBTIFF_DIR)
>>   set(ENV{PATH} "${LIBTIFF_DIR};$ENV{PATH}")
>> endif()
>>
>> and then it runs the test command and specified options via
>> execute_process().
>>
>> i.e. we've added a level of indirection when running the tests via a
>> standalone cmake script.
>>
>> There may be better ways of doing this.  I'd certainly be keen to simplify
>> things!
>>
>>
>> Regards,
>> Roger
>> --
>>
>> Powered by www.kitware.com
>>
>> Please keep messages on-topic and check the CMake FAQ at:
>> http://www.cmake.org/Wiki/CMake_FAQ
>>
>> Kitware offers various services to support the CMake community. For more
>> information on each offering, please visit:
>>
>> CMake Support: http://cmake.org/cmake/help/support.html
>> CMake Consulting: http://cmake.org/cmake/help/consulting.html
>> CMake Training Courses: http://cmake.org/cmake/help/training.html
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/cmake
>
>
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake


More information about the CMake mailing list