[CMake] dependency in custom command?

King, Steven R steven.r.king at intel.com
Fri Aug 28 20:19:19 EDT 2009


> Wrap your custom_command with a custom_target. See the CMake FAQ for
> some recipes.


OK, my CMakeLists.txt is growing rapidly.  :^(
All I've managed to do is cause the module to be copied every time.
Again, my goal is to copy the dll to the directory of the corresponding test program
if the dll has been rebuilt.

Any pointers are very much appreciated.  There must be some newb problems here.
My new approach with the add_custom_target:


add_dependencies          (
                          test_my_module
                          my_module
                          test_my_module_copy
                          )

target_link_libraries     (
                          test_my_module
                          dl
                          )

get_target_property       (
                          SO_LOCATION
                          my_module        # .so library target
                          LOCATION
                          )

get_target_property       (
                          SO_NAME
                          my_module        # .so library target
                          OUTPUT_NAME
                          )
                          
# 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        (
                          OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${SO_NAME}
                          COMMAND ${CMAKE_COMMAND} -E copy ${SO_LOCATION} ${CMAKE_CURRENT_BINARY_DIR}
                          DEPENDS my_module
                          COMMENT "CUSTOM COMMAND: Copy ${SO_NAME} to build directory"
                          )

add_custom_target         (
                          test_my_module_copy
                          DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${SO_NAME}
                          DEPENDS my_module
                          )



More information about the CMake mailing list