Possible to add an imported library to target_link_libraries that takes care of include directories too?(可以将导入的库添加到 target_link_libraries 来处理包含目录吗?)
问题描述
不知何故,我正在努力找出是否可以在 CMake 中定义导入的库,指定目标属性(include_directories 和库路径),并希望一旦我将该项目添加到另一个项目中的 target_link_libraries,CMake 将附加包含目录.
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.
假设我在名为 Module-Conf.cmake 的文件中有一个导入的库:
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)
CMake 会将 include_directories 属性附加到包含路径吗?现在我看不到路径,所以似乎我必须使用 get_target_property 自己完成?
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?
问题:我可以做一些 CMake 魔术来自动将包含附加到另一个项目的包含目录吗?
Question: Can I do some CMake magic to automatically append the include to the include directories of another project?
非常感谢.马丁
推荐答案
INCLUDE_DIRECTORIES
属性和 INTERFACE_INCLUDE_DIRECTORIES
属性之间的区别在于传递性.
The difference between the INCLUDE_DIRECTORIES
property and the INTERFACE_INCLUDE_DIRECTORIES
property is transitivity.
改为设置 INTERFACE_INCLUDE_DIRECTORIES
.
http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html#transitive-usage-requirements
这篇关于可以将导入的库添加到 target_link_libraries 来处理包含目录吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:可以将导入的库添加到 target_link_libraries 来处理包含目录吗?
基础教程推荐
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 从 std::cin 读取密码 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 使用从字符串中提取的参数调用函数 2022-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01