我有一个主项目(A),取决于2个图书馆项目(B,C)。
─A
├──src
├──dep
│ ├─B
│ │ ├──include
│ │ ├──src
│ │ └──CMakeLists.txt[B]
│ └─C
│ ├──include
│ ├──src
│ └──CMakeLists.txt[C]
└──CMakeLists.txt[A]
A的CMakeLists.txt就是这样(缩短):
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)
当构建B或C时,我想将输出目录复制到A的输出目录,以便它可以找到更新的编译库(.lib和.dll文件)。
这是我尝试使用的(在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>)
但显然没有被执行。
我尝试在A的PRE_BUILD步骤中执行此类副本:
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>)
它有效,但每次我在B或C上工作时都要重新编译A.
配置此功能的正确方法是什么?
答案 0 :(得分:1)
使用RUNTIME_OUTPUT_DIRECTORY目标属性更改目标目标:
# file dep/B/CMakeLists.txt
add_library(boo SHARED ...)
set_target_properties(boo PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")