是否可以将导入的库添加到 target_link_libraries 来处理包含目录?

Possible to add an imported library to target_link_libraries that takes care of include directories too?(是否可以将导入的库添加到 target_link_libraries 来处理包含目录?)
本文介绍了是否可以将导入的库添加到 target_link_libraries 来处理包含目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

somehow I am struggling with finding out whether it is possible to define an imported library in CMake, specifying target properties (include_directories and library path) and hoping that CMake will append the include directories once I add that project to target_link_libraries in another project.

Let's say I have an imported library in a file called Module-Conf.cmake:

add_library(mymodule STATIC IMPORTED)
set_target_properties(mymodule PROPERTIES IMPORTED_LOCATION "${OUTPUT_DIR}/lib")
set_target_properties(mymodule PROPERTIES INCLUDE_DIRECTORIES "${OUTPUT_DIR}/include")

And in a project I add the dependency:

include(Module-Conf)
target_link_libraries(${PROJECT_NAME} mymodule)

Will CMake append the include_directories property to the include path? Right now I cannot see the path so it seems that I have to do it by myself by using get_target_property?

Question: Can I do some CMake magic to automatically append the include to the include directories of another project?

Thanks a lot. Martin

解决方案

The difference between the INCLUDE_DIRECTORIES property and the INTERFACE_INCLUDE_DIRECTORIES property is transitivity.

Set INTERFACE_INCLUDE_DIRECTORIES instead.

http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html#transitive-usage-requirements

这篇关于是否可以将导入的库添加到 target_link_libraries 来处理包含目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Clang Tool (libtooling): set header search path to standard libs headers. Foundation framework(Clang 工具 (libtooling):将标头搜索路径设置为标准库标头.基础框架)
C++ Library Include(C++ 库包含)
How can I get the contents of a file at build time into my C++ string?(如何在构建时将文件的内容获取到我的 C++ 字符串中?)
C++ previous definition error(C++以前的定义错误)
Writing or Copying Visual C++ console output to text file(将 Visual C++ 控制台输出写入或复制到文本文件)
C++ class, its base class and circular include includes(C++ 类,它的基类和循环包含包括)