Hello everyone, I hope you can help me understand this. I originally asked
the same question on stackoverflow, so if you want you can check there too (
http://stackoverflow.com/questions/23591085/how-to-correctly-set-cmake-custom-commands-for-external-projects
).

I have a main project (A) depending on 2 library projects (B, C).

─A
 ├──src
 ├──dep
 │   ├─B
 │   │ ├──include
 │   │ ├──src
 │   │ └──CMakeLists.txt[B]
 │   └─C
 │     ├──include
 │     ├──src
 │     └──CMakeLists.txt[C]
 └──CMakeLists.txt[A]

The CMakeLists.txt of A is something like this (shortened):

project(A)

add_subdirectory(dep/B)
include_directories(dep/B/include)

add_subdirectory(dep/C)
include_directories(dep/C/include)

add_executable(A ...src/files...)

target_link_libraries(A B)
target_link_libraries(A C)

When B or C are built I'd like to have the output directories copied to the
output directory of A, so that it can find the updated compiled libraries
(.lib and .dll files).

This is what I tried using (in CMakeLists.txt[A]):

add_custom_command(TARGET B POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy_directory
        $<TARGET_FILE_DIR:B>
        $<TARGET_FILE_DIR:A>)

add_custom_command(TARGET C POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy_directory
        $<TARGET_FILE_DIR:C>
        $<TARGET_FILE_DIR:A>)

But apparently is not executed.

I tried doing the copy on the PRE_BUILD step of A like this:

add_custom_command(TARGET A PRE_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy_directory
        $<TARGET_FILE_DIR:B>
        $<TARGET_FILE_DIR:A>)

add_custom_command(TARGET A PRE_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy_directory
        $<TARGET_FILE_DIR:C>
        $<TARGET_FILE_DIR:A>)

It works, but I have to recompile A every time I'm working on B or C.

What's the correct way to configure this?
-- 

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://www.cmake.org/mailman/listinfo/cmake

Reply via email to