Usage includes contiguous subproject in cmake

I am developing a project consisting of several shared libraries and creating it using CMake. Each library is built through add_subdirectory() .

What is the best way to add all the fist library API headers to CMakeLists.txt of the second?

+6
source share
2 answers

Encode include directories for the very purpose:

http://www.cmake.org/cmake/help/git-master/manual/cmake-buildsystem.7.html#include-directories-and-usage-requirements

This document is new, but the target_include_directories command exists since CMake 2.8.11. Use it with the INTERFACE or PUBLIC option.

+7
source

To execute a steveire answer:

for the library that exports the API, we must write

 target_include_directories("target_with_api" INTERFACE "path_to_api_includes") 

and for a library using this API, we write

 target_include_directories("api_client_target_name" PRIVATE $<TARGET_PROPERTY:"target_with_api",INTERFACE_INCLUDE_DIRECTORIES>) 

where $<TARGET_PROPERTY:"target_with_api",INTERFACE_INCLUDE_DIRECTORIES>) returns us the target property assigned to the library with the API

+5
source

All Articles