[CMake] add_test and locating dependent DLL's on Windows

Scott Gray sgray at inventa.com
Mon May 11 15:14:00 EDT 2009


All,

I currently have a test program that is used to test an API in shared 
library that I am producing as part of the build.  The build of the 
shared library and running of the test program is working on Linux but 
not on Windows because it appears to me that my test program cannot find 
the DLL for the library it is testing.

My directory structure looks like:

   util/
      build/
         lib/
      include/
      src/
      test/

==== util/CMakeLists.txt ====
set(LIBRARY_OUTPUT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/build/lib")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")

file(GLOB header_files "include/*.hpp")
file(GLOB src_files "include/*.hpp")

add_library(util ${header_files} ${src_files})
target_link_libraries(util log4cplus)

add_subdirectory(test)

==== util/test/CMakeLists.txt ====
link_directories("${LIBRARY_OUTPUT_PATH}")

add_executable(my_test my_test.cpp)
target_link_libraries(util log4cplus)

add_test(my_test my_test)


As I said, on Linux when I do "make test", my_test gets run fine--I 
think because rpath is properly recording the location of the shared 
libraries.   On windows (Visual Studio 2005), my_test will not run. When 
I execute ctest by hand, I am told that it cannot locate 'util.dll' (as 
well as icuuc.dll, etc.)

Forgive me if there is a simple answer to this...Windows is a strange 
and foreign land to me.

Thanks,
-scott



More information about the CMake mailing list