CMake没有获取链接库的INTERFACE_INCLUDE_DIRECTORIES [英] CMake doesn't pick up INTERFACE_INCLUDE_DIRECTORIES of linked library

查看:573
本文介绍了CMake没有获取链接库的INTERFACE_INCLUDE_DIRECTORIES的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的cmake文件中有这个

  get_target_property(moggle_interface_includes moggle INTERFACE_INCLUDE_DIRECTORIES)
消息( Moggle界面包括:$ {moggle_interface_includes})

target_link_libraries(motor
moggle


get_target_property(motor_includes motor INCLUDE_DIRECTORIES)
message( MOTOR包括$ {motor_includes})

哪个输出

  Moggle界面包括: / home / nick / code / onegame / motor / moggle / include 
Motor包括:

这怎么可能?当链接到moggle时,根据此

 ,CMake还应传播链接库目标中的使用需求。用法
要求会影响< target>中源的编译。它们由在链接目标上定义的
属性指定。在生成系统的过程中,CMake
将使用需求属性值与
< target>的相应构建属性集成:

INTERFACE_COMPILE_DEFINITONS:追加到COMPILE_DEFINITONS
INTERFACE_INCLUDE_DIRECTORIES :附加到INCLUDE_DIRECTORIES

...拿起INTERFACE_INCLUDE_DIRECTORIES并将其添加到电机中,那么我是什么




  • CMake版本:cmake版本2.8.12.2

  • 操作系统:Arch Linux

解决方案

CMake在配置时间进行一些处理,在生成时间进行一些处理。



message()在配置时执行,但是链接库仅在生成时才进行评估。因为您的包含目录取决于链接的库,所以包含目录在生成时间之前不会完全解析。



file(GENERATE)命令在生成时评估生成器表达式的内容,并将其写入文件,因此,类似的操作会将最终的include目录写入include.txt:

  file(GENERATE 
OUTPUT includes.txt
CONTENT $< TARGET_PROPERTY:motor,INCLUDE_DIRECTORIES> \ \n

如果要调试,请尝试将CMAKE_VERBOSE_MAKEFILE设置为 1 查看编译器命令行或尝试设置

  set(CMAKE_DEBUG_TARGET_PROPERTIES INCLUDE_DIRECTORIES) 

,它将向您显示每个目标上每个include目录来自何处的回溯。 / p>

http://www.cmake.org/cmake/help/v3.0/manual/cmake-generator-expressions.7.html



http://www.cmake.org/cmake /help/v3.0/manual/cmake-buildsystem.7.html



http://www.cmake.org/cmake/help/v3.0/variable/CMAKE_DEBUG_TARGET_PROPERTIES.html



http://www.cmake.org/cmake/help /git-master/command/file.html


I have this in my cmake-file

get_target_property(moggle_interface_includes moggle INTERFACE_INCLUDE_DIRECTORIES)
message("Moggle interface includes: ${moggle_interface_includes}")

target_link_libraries(motor
    moggle
)

get_target_property(motor_includes motor INCLUDE_DIRECTORIES)
message("MOTOR includes ${motor_includes}")

Which outputs this

Moggle interface includes: "/home/nick/code/onegame/motor/moggle/include"
Motor includes:" "

How can this be? When moggle is linked, it should also, according to this

CMake will also propagate "usage requirements" from linked library targets. Usage 
requirements affect compilation of sources in the <target>. They are specified by 
properties defined on linked targets. During generation of the build system, CMake 
integrates usage requirement property values with the corresponding build properties for 
<target>:

     INTERFACE_COMPILE_DEFINITONS: Appends to COMPILE_DEFINITONS
     INTERFACE_INCLUDE_DIRECTORIES: Appends to INCLUDE_DIRECTORIES

... pick up the INTERFACE_INCLUDE_DIRECTORIES and add them to motor's, so what am I doing wrong?

  • CMake verison: cmake version 2.8.12.2
  • OS: Arch Linux

解决方案

CMake does some processing at 'configure time' and some processing at 'generate time'.

The message() is executed at configure time, but linked libraries are only evaluated later at generate time. Because your include directories depend on the linked libraries, the include directories are not fully resolved until generate time.

The file(GENERATE) command evaluates generator expression content at generate time and writes it to a file, so something like this will write the final include directories to includes.txt:

file(GENERATE 
    OUTPUT "includes.txt" 
    CONTENT "$<TARGET_PROPERTY:motor,INCLUDE_DIRECTORIES>\n"
)

If your purpose is debugging, then try setting CMAKE_VERBOSE_MAKEFILE to 1 to see the compiler command lines or try setting

set(CMAKE_DEBUG_TARGET_PROPERTIES INCLUDE_DIRECTORIES)

and it will show you a backtrace for where each of the include directories on each target comes from.

http://www.cmake.org/cmake/help/v3.0/manual/cmake-generator-expressions.7.html

http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html

http://www.cmake.org/cmake/help/v3.0/variable/CMAKE_DEBUG_TARGET_PROPERTIES.html

http://www.cmake.org/cmake/help/git-master/command/file.html

这篇关于CMake没有获取链接库的INTERFACE_INCLUDE_DIRECTORIES的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆