<div dir="ltr"><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:13.600000381469727px;vertical-align:baseline;clear:both;color:rgb(0,0,0);font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:17.804800033569336px;background-image:initial;background-repeat:initial">
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 (<a href="http://stackoverflow.com/questions/23591085/how-to-correctly-set-cmake-custom-commands-for-external-projects">http://stackoverflow.com/questions/23591085/how-to-correctly-set-cmake-custom-commands-for-external-projects</a>).</p>
<p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:13.600000381469727px;vertical-align:baseline;clear:both;color:rgb(0,0,0);font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:17.804800033569336px;background-image:initial;background-repeat:initial">
I have a main project (A) depending on 2 library projects (B, C).</p><pre style="margin-top:0px;margin-bottom:10px;padding:5px;border:0px;font-size:13.600000381469727px;vertical-align:baseline;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;overflow:auto;width:auto;max-height:600px;word-wrap:normal;color:rgb(0,0,0);line-height:17.804800033569336px;background:rgb(238,238,238)">
<code style="margin:0px;padding:0px;border:0px;font-size:13.600000381469727px;vertical-align:baseline;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;white-space:inherit;background-image:initial;background-repeat:initial">─A
├──src
├──dep
│ ├─B
│ │ ├──include
│ │ ├──src
│ │ └──CMakeLists.txt[B]
│ └─C
│ ├──include
│ ├──src
│ └──CMakeLists.txt[C]
└──CMakeLists.txt[A]
</code></pre><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:13.600000381469727px;vertical-align:baseline;clear:both;color:rgb(0,0,0);font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:17.804800033569336px;background-image:initial;background-repeat:initial">
The CMakeLists.txt of A is something like this (shortened):</p><pre style="margin-top:0px;margin-bottom:10px;padding:5px;border:0px;font-size:13.600000381469727px;vertical-align:baseline;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;overflow:auto;width:auto;max-height:600px;word-wrap:normal;color:rgb(0,0,0);line-height:17.804800033569336px;background:rgb(238,238,238)">
<code style="margin:0px;padding:0px;border:0px;font-size:13.600000381469727px;vertical-align:baseline;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;white-space:inherit;background-image:initial;background-repeat:initial">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)
</code></pre><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:13.600000381469727px;vertical-align:baseline;clear:both;color:rgb(0,0,0);font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:17.804800033569336px;background-image:initial;background-repeat:initial">
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).</p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:13.600000381469727px;vertical-align:baseline;clear:both;color:rgb(0,0,0);font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:17.804800033569336px;background-image:initial;background-repeat:initial">
This is what I tried using (in CMakeLists.txt[A]):</p><pre style="margin-top:0px;margin-bottom:10px;padding:5px;border:0px;font-size:13.600000381469727px;vertical-align:baseline;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;overflow:auto;width:auto;max-height:600px;word-wrap:normal;color:rgb(0,0,0);line-height:17.804800033569336px;background:rgb(238,238,238)">
<code style="margin:0px;padding:0px;border:0px;font-size:13.600000381469727px;vertical-align:baseline;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;white-space:inherit;background-image:initial;background-repeat:initial">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>)
</code></pre><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:13.600000381469727px;vertical-align:baseline;clear:both;color:rgb(0,0,0);font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:17.804800033569336px;background-image:initial;background-repeat:initial">
But apparently is not executed.</p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:13.600000381469727px;vertical-align:baseline;clear:both;color:rgb(0,0,0);font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:17.804800033569336px;background-image:initial;background-repeat:initial">
I tried doing the copy on the PRE_BUILD step of A like this:</p><pre style="margin-top:0px;margin-bottom:10px;padding:5px;border:0px;font-size:13.600000381469727px;vertical-align:baseline;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;overflow:auto;width:auto;max-height:600px;word-wrap:normal;color:rgb(0,0,0);line-height:17.804800033569336px;background:rgb(238,238,238)">
<code style="margin:0px;padding:0px;border:0px;font-size:13.600000381469727px;vertical-align:baseline;font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif;white-space:inherit;background-image:initial;background-repeat:initial">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>)
</code></pre><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:13.600000381469727px;vertical-align:baseline;clear:both;color:rgb(0,0,0);font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:17.804800033569336px;background-image:initial;background-repeat:initial">
It works, but I have to recompile A every time I'm working on B or C.</p><p style="margin:0px 0px 1em;padding:0px;border:0px;font-size:13.600000381469727px;vertical-align:baseline;clear:both;color:rgb(0,0,0);font-family:Arial,'Liberation Sans','DejaVu Sans',sans-serif;line-height:17.804800033569336px;background-image:initial;background-repeat:initial">
What's the correct way to configure this?</p></div>