Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake dummy target depending on other targets

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?

like image 675
oHo Avatar asked Jan 19 '16 20:01

oHo


People also ask

How do I add a target in Cmake?

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.

What does Cmake Target_link_libraries do?

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.


2 Answers

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 )
like image 108
Scott Avatar answered Sep 30 '22 09:09

Scott


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.

like image 39
oHo Avatar answered Sep 30 '22 07:09

oHo