Reputation: 1453
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?
Upvotes: 0
Views: 998
Reputation:
Use RUNTIME_OUTPUT_DIRECTORY target property to change target destination:
# file dep/B/CMakeLists.txt
add_library(boo SHARED ...)
set_target_properties(boo PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
Upvotes: 1