使用cmake生成项目时Eclipse indexer正确的c ++ 11语法突出显示 [英] Eclipse indexer proper c++11 syntax highlighting when generating projects with cmake
问题描述
我知道您可以使用此处描述的GXX_EXPERIMENTAL hack启用正确的语法突出显示: Eclipse CDT索引器不知道C ++ 11容器
I know you can enable proper syntax highlighting with the GXX_EXPERIMENTAL hack described here: Eclipse CDT indexer does not know C++11 containers
但是我认为,使用cmake生成项目时,根本不需要触摸项目设置.
But i think, when generating projects with cmake, one should never need to touch the project settings at all.
所以.有更简单的解决方案吗?
So. Is there a simpler solution?
推荐答案
答案很简单.
当解析符号时,eclipse cdt生成器将忽略通过add_definitions(...)添加的定义.而是使用CMAKE_CXX_COMPILER_ARG1. 因此,您要做的就是:调用cmake时添加-DCMAKE_CXX_COMPILER_ARG1 = -std = c ++ 11
The eclipse cdt generator ignores the definitions added with add_definitions(...) when parsing the symbols. Instead it uses the CMAKE_CXX_COMPILER_ARG1. So all you have to do is: Add -DCMAKE_CXX_COMPILER_ARG1=-std=c++11 when invoking cmake
从命令行生成项目文件:
Generating project files from commandline:
cmake ../../src -G"Eclipse CDT4 - MinGW Makefiles" -DCMAKE_ECLIPSE_VERSION=4.2 -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER_ARG1=-std=c++11
从cmake gui生成项目:
Generating projects from cmake gui:
- Select source and build directory.
- now BEFORE hitting configure or generate. Press "Add Entry" and add a new entry. Name:CMAKE_CXX_COMPILER_ARG1 Type:STRING Value:-std=c++11
- press Generate and create the Eclipse project
在进行配置或首次生成之前,预先设置CMAKE_CXX_COMPILER_ARG1很重要!
It is important to set the CMAKE_CXX_COMPILER_ARG1 upfront before hitting configure or generate the first time!
就是这样.该项目将使用正确的符号生成.索引器,语法突出显示和自动完成功能应该可以按预期工作,而无需手动更改任何项目设置.
That´s it. The project will be generated with correct symbols. indexer, syntax highlighting and autocompletion should work as intended without changing any project settings by hand.
这篇关于使用cmake生成项目时Eclipse indexer正确的c ++ 11语法突出显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!