12

I have one 3rdparty project providing many libraries (let's say header-only libraries). I want to write a CMake encapsulation for this project:

File 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)

Question:
How to write a dummy target foo that depends on all others?

oHo
  • 51,447
  • 27
  • 165
  • 200

2 Answers2

11

Assuming you don't want a library that contains all the libraries, you might want this instead:

add_custom_target( foo )
add_dependencies( foo foo-aaa foo-bbb foo-ccc )
BenC
  • 8,729
  • 3
  • 49
  • 68
Scott
  • 1,179
  • 7
  • 17
10

While writing the question I got the answer. My solution is an INTERFACE target without INCLUDE_DIRECTORIES.

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

Hope this answer may help someone.

oHo
  • 51,447
  • 27
  • 165
  • 200