I have one 3rdparty project providing many libraries (let's say header-only libraries). I want to write a CMake encapsulation for this project:
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 ????? )
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?
Adds a target with the given name that executes the given commands. The target has no output file and is always considered out of date even if the commands try to create a file with the name of the target. Use the add_custom_command() command to generate a file with dependencies.
Specify libraries or flags to use when linking a given target and/or its dependents. Usage requirements from linked library targets will be propagated. Usage requirements of a target's dependencies affect compilation of its own sources.
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 )
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With