问题描述
我不知何故我正在努力找出是否可能在CMake中定义一个导入的库,指定目标属性(include_directories和库路径),并希望CMake将附加include目录一旦我将该项目添加到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.
假设我在一个名为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魔法来自动附加include到另一个项目的include目录?
Question: Can I do some CMake magic to automatically append the include to the include directories of another project?
非常感谢。
Martin
Thanks a lot.Martin
推荐答案
INCLUDE_DIRECTORIES
INTERFACE_INCLUDE_DIRECTORIES
属性是传输性。
改为设置 INTERFACE_INCLUDE_DIRECTORIES
。
这篇关于是否可以将导入的库添加到target_link_libraries,以便处理包含目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!