当从命令行调用它时,将包括目录添加到cmake [英] Adding include directories to cmake when calling it from command line

查看:256
本文介绍了当从命令行调用它时,将包括目录添加到cmake的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个情况下,我不应该打扰现有的CMakeLists.txt,但仍然应该添加一些g ++系统包含目录到我的构建。换句话说,我需要 -isystem / path / to / my / include 添加到我的编译器标志,但是当调用像 cmake .. 。也许像 cmake .. -DCMAKE_CXX_FLAGS =$ CMAKE_CXX_FLAGS -isystem / path / to / my / include?有什么办法吗?

I'm in a situation where I should not disturb the existing CMakeLists.txt but still should add some g++ system include directory to my build. In other words, I need -isystem /path/to/my/include added to my compiler flags but when calling something like cmake ... Maybe something like cmake .. -DCMAKE_CXX_FLAGS="$CMAKE_CXX_FLAGS -isystem /path/to/my/include"? Is there any way to do this?

推荐答案

我有同样的问题。我发现了两个解决方案:

I have the same problem. I found 2 solutions:


  1. sakra在上一个回答中提出的解决方案, e。用C ++标志设置环境变量:

  1. the one proposed by sakra in previous answer, i. e. setting environment variable with C++ flags:

export CXXFLAGS=-isystem\ /path/to/my/include
cmake <path to my sources>

同样的东西,但是环境变量只设置为 cmake 调用: call:

OR the same thing, but environment variable are set only for this cmake call:

CXXFLAGS=-isystem\ /path/to/my/include cmake <path to my sources>

重要:您必须目录(即清除cmake缓存),然后启动任何此窗体。没有清除缓存cmake将继续使用您之前运行的缓存 CMAKE_CXX_FLAGS

直接设置 CMAKE_CXX_FLAGS in cmake string:

Directly setting CMAKE_CXX_FLAGS in cmake string:

cmake -DCMAKE_CXX_FLAGS=-isystem\ /path/to/my/include <path to my sources>


我相信可以通过更多'native'的方式,但我没有找到变量负责路径头文件cmake。

I believe that it can be done by more 'native' way, but I didn't find variable responsible for paths to headers in cmake.

这篇关于当从命令行调用它时,将包括目录添加到cmake的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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