[CMake] CMAKE_RUNTIME_OUTPUT_DIRECTORY best practice for Windows and Visual Studio

Mateusz Łoskot mateusz at loskot.net
Mon Nov 14 11:58:40 EST 2011


On 13 November 2011 19:51, Niels Dekker - address until 2014
<niels_dekker_address_until_2014 at xs4all.nl> wrote:
> Mateusz Loskot wrote:
>> 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})
>
> On Windows, it looks fine to me to have all the DLL's built by the project
> together with the executable that links against them, in one and the same
> CMAKE_RUNTIME_OUTPUT_DIRECTORY.

Good, I'm glad it's nothing weird neither wrong in this approach.

> The alternative of setting the PATH looks
> less reliable to me, because the PATH may easily be overruled by other
> locations (current directory, system directory or Windows directory),
> depending on that rather complicated "Dynamic-Link Library Search Order"
> thing, http://msdn.microsoft.com/en-us/site/ms682586  And eventually I guess
> you don't want your application to depend on the PATH at the end user machine.

Yes, you are right.
I have some projects configured in such way they try to generate
.vcproj.user file
which defines PATH with pointers to location of run-time dependencies.
For example: https://github.com/libLAS/libLAS/tree/master/cmake

> However, I haven't yet tried to build an "isolated application"
> according to your reference [3]
> (http://msdn.microsoft.com/en-us/library/aa375190%28VS.85%29.aspx).
> Would you recommend doing so?

Niels, I haven't tried it myself neither. I don't have experience with
this technique,
so I can't say if it is recommended.
Actually, I hoped to receive a related piece of advice here, from CMake users.

Best regards,
-- 
Mateusz Loskot, http://mateusz.loskot.net
Charter Member of OSGeo, http://osgeo.org
Member of ACCU, http://accu.org


More information about the CMake mailing list