CMake mixed goal depending on other goals

I have one 3 rd third-party project providing a lot of libraries (albeit only libraries for headers only). I want to write CMake encapsulation for this project:

foo.cmake file

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

Home 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 fictitious target foo that depends on everyone else?

+5
source share
2 answers

Assuming you don't need a library containing all the libraries, you might need this:

 add_custom_target( foo ) add_dependencies( foo foo-aaa foo-bbb foo-ccc ) 
+3
source

When writing a question, I got an answer. My solution is INTERFACE goal without INCLUDE_DIRECTORIES.

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

Hope this answer can help someone.

+2
source

Source: https://habr.com/ru/post/1240955/


All Articles