Jarlaxle
Jarlaxle

Reputation: 901

How to enable c++11 syntax highlighting in Qt Creator for CMake project

How to enable C++11 syntax highlighting in Qt Creator for CMake project?

I have this code in CMakeLists.txt:

if(CMAKE_COMPILER_IS_GNUCXX)
    add_definitions(-std=c++11)
endif()

Everything builds without any problem.

I know how to force Qt Creator to use C++ 11 syntax highlighting for qmake-based projects (set QMAKE_CXXFLAGS to -std=c++11 in *.pro file). Is there any similar solution for CMake?

Upvotes: 9

Views: 3511

Answers (1)

John Schug
John Schug

Reputation: 439

C++11 syntax highlighting should be enabled by default for CMake projects in very recent versions of QtCreator 2.7.0+. In older versions just adding -std=c++0x to CMAKE_CXX_FLAGS should also work. To enable auto completion support for C++11 library features you may have to manually edit the generated cbp file and add the following under the compiler tag in the default target:

<Add option="-D__GXX_EXPERIMENTAL_CXX0X__" />

Upvotes: 3

Related Questions