CMake虚拟目标取决于其他目标

时间:2016-01-19 20:31:39

标签: cmake dependencies target

我有一个3 rd 派对项目提供了许多库(让我们说只有标题库)。我想为这个项目写一个CMake封装:

档案foo.cmake

add_library(          foo-aaa INTERFACE IMPORTED GLOBAL)
set_target_properties(foo-aaa PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_LIST_DIR}/aaa/inc)

add_library(          foo-bbb INTERFACE IMPORTED GLOBAL)
set_target_properties(foo-bbb PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_LIST_DIR}/bbb/inc)

add_library(          foo-ccc INTERFACE IMPORTED GLOBAL)
set_target_properties(foo-ccc PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_LIST_DIR}/ccc/inc)

add_library(          foo-ddd INTERFACE IMPORTED GLOBAL)
set_target_properties(foo-ddd PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_LIST_DIR}/ddd/inc)

add_library(          foo-eee INTERFACE IMPORTED GLOBAL)
set_target_properties(foo-eee PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_LIST_DIR}/eee/inc)

[...] And many more

# For convenience I also want to provide 
# a global/dummy target depending on all above libraries
add_library( foo ????? )

Main CMakeLists.txt

cmake_minimum_required(VERSION 3.1)
project(bar CXX)
include(path/to/3rdparty/foo/foo.cmake)
add_executable(bar bar.cpp)
target_link_libraries(bar foo)

问题:
如何编写取决于所有其他目标的虚拟目标foo

2 个答案:

答案 0 :(得分:4)

假设您不想要包含所有库的库,您可能需要这样:

add_custom_target( foo )
add_dependencies( foo foo-aaa foo-bbb foo-ccc )

答案 1 :(得分:3)

在写这个问题时,我得到了答案。我的解决方案是没有INCLUDE_DIRECTORIES的INTERFACE目标。

add_library(foo INTERFACE)
target_link_libraries(foo foo-aaa foo-bbb foo-ccc foo-ddd foo-eee [...])

希望这个答案对某人有所帮助。