从命令行调用包含目录到CMake时 [英] Adding include directories to CMake when calling it from the command line
问题描述
我处于一种不应该打扰现有CMakeLists.txt文件的情况,但是我仍然应该在构建中添加一些g ++系统包含目录。
I'm in a situation where I should not disturb the existing CMakeLists.txt files, but I still should add some g++ system include directory to my build.
换句话说,我需要在编译器标志中添加 -isystem / path / to / my / include
,但是在调用 cmake ..
。
In other words, I need -isystem /path/to/my/include
added to my compiler flags, but when calling something like cmake ..
.
也许类似于 cmake .. -DCMAKE_CXX_FLAGS = $ CMAKE_CXX_FLAGS -isystem / path / to / my / include
?有办法吗?
Maybe something like cmake .. -DCMAKE_CXX_FLAGS="$CMAKE_CXX_FLAGS -isystem /path/to/my/include"
? Is there a way to do this?
推荐答案
我也有同样的问题。我找到了两种解决方案:
I have the same problem. I found two solutions:
The one proposed by sakra in a previous answer, i.e. setting an environment variable with C++ flags:
export CXXFLAGS=-isystem\ /path/to/my/include
cmake <path to my sources>
OR 相同,但仅为此环境变量设置 CMake 呼叫:
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
。
IMPORTANT: you must clean your build directory (i.e. clean the CMake cache) before launching any of this form. Without cleaning the cache, CMake will continue using your cached CMAKE_CXX_FLAGS
from the previous run.
直接设置 CMAKE_CXX_FLAGS
在cmake字符串中:
Directly setting CMAKE_CXX_FLAGS
in cmake string:
cmake -DCMAKE_CXX_FLAGS=-isystem\ /path/to/my/include <path to my sources>
我相信可以通过更多的本机方式,但是我没有找到负责CMake中标头路径的变量。
I believe that it can be done by a more 'native' way, but I didn't find a variable responsible for paths to headers in CMake.
这篇关于从命令行调用包含目录到CMake时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!