Use includes of adjacent subproject in cmake

假装没事ソ 提交于 2019-12-08 21:52:37

问题


I develop a project which consisting of several shared libraries and build it with CMake. Each library is built via add_subdirectory().

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


回答1:


Encode the include directories in the target itself:

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

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




回答2:


To make an answer of steveire complete:

for the library which exports API we should write

target_include_directories("target_with_api" INTERFACE "path_to_api_includes")

and for the library which uses 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 target property assigned to the library with API



来源:https://stackoverflow.com/questions/21440698/use-includes-of-adjacent-subproject-in-cmake

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!