[CMake] Copying files to runtime directory

Jeroen Dierckx jeroen.dierckx at gmail.com
Mon Sep 21 08:54:04 EDT 2009


Hi,

In Windows, we need to copy a bunch of files (dlls and other runtime
dependencies) to the runtime directory, mostly belonging to external
dependencies. Those files are different for debug and release builds.
So I created a function to do just that. I came across several
problems or limitations in cmake while doing that. Here is how I did
it, and some remarks for each step

- For a certain external dependency, I look for a specific
platform-dependent directory, with some shared files, and some only
for debug or release builds. I have to exclude certain files and
directories (.svn directories in this case). It would be nice to have
an EXCLUDE parameter for the file(GLOB* functions, like in the install
function. I worked around this by iterating over all the files in the
list and removing them when they match a certain REGEX.

- I wanted to create post-build command to copy the necessary files
after building, because they are only needed when actually
running/debugging the application. There currently is no way to
generate different custom commands for different configurations. I
could work around this by using some if-tests inside the custom
command itself, but I decided against it because it would be too
Visual Studio-specific.

- So I copy all files to each build directory (one for each
configuration that is generated, mind that for Visual Studio no build
configuration is chosen at configure time) in cmake. This of course is
not very optimal, as it copies the files for all configurations, also
the ones I will probably never build. Here I used the cmake command
with -E copy_if_different. This works, but spawns a new process for
each file to be copied. I could use configure_file, but that seemed a
bit hacky to me.

All in all, my method works, but to summarize, the following features
would be a nice addition to cmake:
- an EXCLUDE parameter for the file globbing commands
- configuration-specific custom commands
- a cmake command to copy files (with a parameter to only do it when
the files differ)

Greetz,
JeDi


More information about the CMake mailing list