Cmake on Windows doesn't add shared library paths (works on linux)

Viewed 3426

I've been using CMake and Eclipse on linux for a while and have been working with multiple target projects containing numerous executables and shared objects.

I use out of source builds and on linux the binaries are put into their own directories. When I do this on linux eclipse is somehow able to find the shared objects and run the executables fine but on windows this doesn't happen.

On Windows I am having to add a PATH environment variable that points to the dlls or I could build into a single bin and lib directory (although I had an issue I've forgotten in the past with CMake that made me want to avoid this).

Why is this working differently on Windows to linux? Is it a setting I'm missing or does this just not work?

The builds themselves are working perfectly. I'm using MinGW, Eclipse Kepler and Windows 7 64 bit.

Thanks in advance.

3 Answers

Thanks everyone for question and responses. I want just to summarize what you need to for windows support:

Please add the following code to root CMakeLists.txt:

# Common output directory is required for OS without rpath support.
set (CMAKE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/result")
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_OUTPUT_DIRECTORY})
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_OUTPUT_DIRECTORY})
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_OUTPUT_DIRECTORY})

Than you need to add working directory for every add_test:

add_test (
  NAME ${TEST_NAME}
  COMMAND ${TEST_TARGET}
  WORKING_DIRECTORY ${CMAKE_OUTPUT_DIRECTORY}
)

Please be aware that TEST_TARGET should be unique inside current project.

I've added windows support for lzws library using this method. You can always checkout source code and clarify remaining question.

Related