[CMake] Question about install()

Michael Jackson mike.jackson at bluequartz.net
Sun Dec 7 08:01:29 EST 2008


On Dec 7, 2008, at 1:20 AM, Robert Dailey wrote:

> Hi,
>
> I have a couple of DLL files I want to copy to my executable's  
> directory as a post-build event in the CMake-generated visual studio  
> project files. I know I have to use install() for this, however I'm  
> not sure how I can tell install() to copy these DLL files to the  
> directory containing the compiled EXE file. I can't seem to find a  
> CMAKE variable that represents the containing directory of this EXE  
> file. Note I'm building out of source.
>
> Thanks.

There are a few variables that control where the final executables,  
libraries and archives are created.

CMAKE_RUNTIME_OUTPUT_DIRECTORY
CMAKE_LIBRARY_OUTPUT_DIRECTORY
CMAKE_ARCHIVE_OUTPUT_DIRECTORY

	• RUNTIME_OUTPUT_DIRECTORY: Output directory in which to build  
RUNTIME target files.
This property specifies the directory into which runtime target files  
should be built. There are three kinds of target files that may be  
built: archive, library, and runtime. Executables are always treated  
as runtime targets. Static libraries are always treated as archive  
targets. Module libraries are always treated as library targets. For  
non-DLL platforms shared libraries are treated as library targets. For  
DLL platforms the DLL part of a shared library is treated as a runtime  
target and the corresponding import library is treated as an archive  
target. All Windows-based systems including Cygwin are DLL platforms.  
This property is initialized by the value of the variable  
CMAKE_RUNTIME_OUTPUT_DIRECTORY if it is set when a target is created

So you can do something like:

SET (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Bin CACHE PATH
   "Single Directory for all executables"
   )
SET (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Bin CACHE PATH
   "Single Directory for all dynamic Libraries"
   )
SET (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Bin CACHE PATH
   "Single Directory for all static Libraries"
   )

BEFORE any "add_library" or "add_executable" is called. That way all  
your built products will be created in the same directory when being  
built. Now, that assumes that your "couple of dlls" were built by your  
project. If they were NOT built by your project (say for example, Qt  
libraries) then you will want to try something a bit different.

cmake -E can be used to copy files.

You may want to look at the add_custom_command(TARGET ${yourExeTarget}
						POST_BUILD
						COMMAND ${CMAKE_COMMAND} -E {path to source dll} {path to dest}
						..... )

This will probably copy the files _every_ time the target is built  
although I am not sure on that point.

You can look up the help for add_custom_command and see if this will  
help you out.

_________________________________________________________
Mike Jackson                  mike.jackson at bluequartz.net
             www.bluequartz.net



More information about the CMake mailing list