[CMake] Copying shared libraries in a post-build step
Walter Gray
chrysalisx at gmail.com
Tue Dec 9 18:38:37 EST 2014
Hey all,
I'm working on a module that will allow me to automatically copy all the
required .dll files as defined by well-formed import library targets to
the appropriate location (same folder for windows, Frameworks folder for
OSX bundle, ect). I've got the code that scans an executable's
INTERFACE_LINK_LIBRARIES property recursively to find all such shared
library, however I'm running into a small problem. I really like using
file globbing in higher level source directories to add all appropriate
sub-directories, but this means that sometimes a dependency will not be
fully defined yet. This is normally fine since these things are usually
resolved at *generation* time, but since I'm doing a manual traversal of
the list of link libraries at config time that's not really acceptable.
I realize I could just not do the globbing and just make sure the
directories were setup in the correct order, but I really don't like
making the add_subdirectory calls order dependent.
One solution I've come up with is to add the targets I want to do this
to to a global list, then iterate over that list as the last step in my
top-level cmake lists file, but that has the issue that I can no longer
use add_custom_command on those targets at that point. I'm wondering 3
things:
1)What is the reasoning behind not allowing add_custom_command on
targets not defined in the current directory? Especially now that SOURCE
can be modified, the restriction seems very arbitrary.
2)How stupid would it be to reserve the command using something like
add_custom_command(TARGET ${target} POST_BUILD COMMAND
$<TARGET_PROPERTY:COPY_SHARED_LIBS_COMMAND>)
then use set_property(TARGET ${target} APPEND PROPERTY
COPY_SHARED_LIBS_COMMAND to add more copy steps to the command?
3) Am I completely missing something and there's already a totally well
supported way of making sure that an executable's shared library
dependencies end up in the correct directory? I couldn't find a really
satisfactory answer on stack overflow or the archives.
Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20141209/4aa648ac/attachment.html>
More information about the CMake
mailing list