[CMake] Copying target output file to another directory

Robert Maynard robert.maynard at kitware.com
Tue Jul 18 11:54:55 EDT 2017


Question: Is there a specific reason why you don't want to do this as
part of the install step?

If this can't be done at install time, you can look at using
add_custom_command Generating File signature with a target dependency
on ${target}

On Tue, Jul 18, 2017 at 10:44 AM, Robert Dailey
<rcdailey.lists at gmail.com> wrote:
> So I need to copy the output *.so from a target to an arbitrary
> directory outside the CMAKE_BINARY_DIR. I tried doing this as a post
> build event using generator expressions:
>
> add_custom_command(
>     TARGET ${target} POST_BUILD VERBATIM
>     COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:${target}>" ${dir}
> )
>
> This fails because I'm running it outside of the directory where
> ${target} is defined:
>
> CMake Error at Core/CMake/third-party.cmake:86 (add_custom_command):
>   TARGET 'MagickCore' was not created in this directory.
>
>
> How can I do this without moving my add_custom_command() to the same
> directory that created the target? I need to add all the custom
> commands at the end of generation because it depends on certain global
> properties which are not completely done being set until the very end.
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake


More information about the CMake mailing list