[CMake] CMAKE_RUNTIME_OUTPUT_DIRECTORY best practice for Windows and Visual Studio

Mateusz Łoskot mateusz at loskot.net
Fri Nov 11 19:00:52 EST 2011


Hi,

I have a CMake-based project which builds several shared libraries and
executables.
There are various run-time dependencies between those shared libraries
and executables.

On Windows, I use Visual Studio for development, so I have CMake-generated .sln
with projects. loaded into the IDE. I build. Then, I'd like to run one
of executables
(e.g. test.exe) which links against the DLLs also built by the project.
Obviously, it is necessary to deal with the run-time search path.

At the moment, I simplify things by outputting all .exe and .dll
binaries to common directory, so programs can find required DLLs:

set(MYPRJOUTDIR ${PROJECT_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${MYPRJOUTDIR})

This is also required to launch such executables under debugger.
However, I have heard opinions it is some kind of a hack unnatural to CMake.

On Linux, I do the same, but I imagine I could make use of rpath [1]
as CMake provides some degree of support in this area [2].

On Windows, there is no such concept as rpath. Isolated Applications [3]
seems to be the closest idea available there.

Is it a good idea to have all-in-one CMAKE_RUNTIME_OUTPUT_DIRECTORY?
Is there any CMake best practice for dealing with run-time search path
on Windows?
For example, automatically setting PATH in project
-> Configuration Properties -> Debugging -> Environment.


[1] http://en.wikipedia.org/wiki/Rpath
[2] http://www.vtk.org/Wiki/CMake_RPATH_handling
[3] http://msdn.microsoft.com/en-us/library/aa375190%28VS.85%29.aspx
-- 
Mateusz Loskot, http://mateusz.loskot.net


More information about the CMake mailing list