Search code examples
c++c++11cmakemingweclipse-cdt

Eclipse indexer proper c++11 syntax highlighting when generating projects with cmake


I know you can enable proper syntax highlighting with the GXX_EXPERIMENTAL hack described here: Eclipse CDT indexer does not know C++11 containers

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?


Solution

  • The answer is pretty simple.

    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
    

    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
    

    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.