[CMake] dependency in custom command?

Alexander Neundorf a.neundorf-work at gmx.net
Sat Sep 5 15:54:08 EDT 2009


On Friday 28 August 2009, King, Steven R wrote:
> Hello List,
> I'm new to cmake and liking it a lot.  I'm using cmake 2.6.3 on Linux.
>
> I'm building a dynamically loadable module and an executable to test it. 
> Each lives in a different directory.  My test program needs to know the
> location of the dll when calling dlopen().   To solve this, I created a
> custom command to copy the dll to the binary directory of the test program.
>   This works, but I have an annoying dependency problem.  Specifically, if
> the dll gets rebuilt, the copy command does not execute.  The copy command
...
> # Create a custom build step to copy the dynamically loaded .so file
> # into the this directory so our test executable can find it.
> add_custom_command        (
>                           TARGET test_my_module
>                           POST_BUILD
>                           DEPENDS my_module  # no effect?
>                           COMMAND ${CMAKE_COMMAND} -E copy ${SO_LOCATION}
> ${CMAKE_CURRENT_BINARY_DIR} COMMENT "CUSTOM COMMAND: Copy my_module to
> build directory" )
>
>
> What should I do make the copy happen if the dll is rebuilt?

I must be missing something, but can't you assign the custom command to the 
module instead to the executable ?

add_custom_command(TARGET my_module
                   POST_BUILD
                   COMMAND ${CMAKE_COMMAND} -E copy ${SO_LOCATION}
                           ${CMAKE_CURRENT_BINARY_DIR} 
                   )

Alex


More information about the CMake mailing list