cmake并GenerateExportHeader [英] cmake and GenerateExportHeader

查看:1963
本文介绍了cmake并GenerateExportHeader的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用GenerateExportHeader模块从CMake的。

I'm trying to use GenerateExportHeader module from cmake.

我的CMakeLists.txt的一部分:

part of my CmakeLists.txt:

add_compiler_export_flags()
add_library(gui SHARED ${gui_CPP} ${gui_HPP})
generate_export_header(gui)

它适用于GUI项目本身不错,但是当我尝试,包括在另一个项目贵的.h文件,一个#includegui_export.h无法找到。
这是显而易见的gui_export.h在GUI的build目录这不包括其他项目的路径中创建。

it works nice for gui project itself, but when I try to include gui's .h files in another project, an #include "gui_export.h" cannot be find. This is obvious as gui_export.h was created in gui's build dir which is not in include path of other projects.

简单的解决办法是增加贵的build目录到其他项目包括,但是:
1.我不觉得它作为一个犹太解决方案
2.我不能真正甚至找不到如何找出什么是目标的build目录

The simple solution would be to add gui's build dir to other project's includes but: 1. I don't find it as a kosher solution 2. I could not actually even find how to find out what is the build dir of a target

我怎么能解决这个问题呢?

how can I solve this problem well?

推荐答案

随着现代(即2.8.11或更高版本)CMake的,在preferred机制是:

With modern (i.e. 2.8.11 or later) CMake, the preferred mechanism is:

target_include_directories(gui PUBLIC ${CMAKE_BINARY_DIR}/exports)

而当导出()的库(你应该做的!),或者以其他方式在目标接口特性已知的情况下使用(例如,在相同的总CMake的项目,这似乎是你在做什么) ,target_link_libraries(富GUI)也将拿起必要的include目录。

Then when you export() your library (which you should do!) or otherwise use it in a context where the target interface properties are known (e.g. in the same overall CMake project, which seems to be what you are doing), target_link_libraries(foo gui) will also pick up the necessary include directory.

把它在一个公知的目录是有点正交。在这两种情况下,建议使用target_include_directories告诉消费者在哪里可以找到你的库的头文件。

Putting it in a well known directory is somewhat orthogonal. In either case, it is recommended to use target_include_directories to tell consumers where to find your library's headers.

这篇关于cmake并GenerateExportHeader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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