cmake:将包含目录传递给外部项目 [英] cmake: pass include directories to external project

查看:64
本文介绍了cmake:将包含目录传递给外部项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 cmake 外部项目模块通过 ExternalProject_Add

I'm using cmake and external project module via ExternalProject_Add.

我想为外部项目指定自定义标头位置(就像在该项目中使用 include_directories 一样,但是我无法修改其 CMakeLists.txt 并不要

I'd like to specify custom header location for external project (just exactly as if I use include_directories in that project, but I am not able to modify its CMakeLists.txt and don't want to apply patch).

是否有可能将某些包含路径传递给我的外部项目?

Is there any possibility to pass some include path to my external project?

我尝试了 CMAKE_ARGS -DCMAKE_INCLUDE_PATH =<必需的路径> ,但没有成功。

I tried CMAKE_ARGS -DCMAKE_INCLUDE_PATH=<required path> without success.

推荐答案

您可以通过将脚本的路径分配给变量 CMAKE_PROJECT_< PROJECT-NAME> _INCLUDE 文档)。

You may execute additional CMake script for external project by assigning path to this script to variable CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE (documentation).

外部项目使用CMake命令

project(e_cool)

而您想要执行

include_directories(/path/to/additional/include)

那个时候。

为此,您需要准备具有相应内容的cmake脚本:

For doing that, you need to prepare cmake script with corresponded content:

fix_e_cool.cmake

include_directories(/path/to/additional/include)

并通过主项目中 ExternalProject_Add 的CMAKE_ARGS选项传递此脚本:

And pass this script via CMAKE_ARGS option of ExternalProject_Add in the main project:

CMakeLists.txt

...
ExternalProject_Add(<name>
    ...
    CMAKE_ARGS -DCMAKE_PROJECT_e_cool_INCLUDE=${CMAKE_SOURCE_DIR}/fix_e_cool.cmake
)

这篇关于cmake:将包含目录传递给外部项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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