Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 532
Jarlaxle Avatar asked Jan 04 '13 11:01

Jarlaxle


People also ask

Does Qt Creator support CMake?

You can use CMake from Qt Creator to build applications for the desktop, as well as mobile and embedded devices. You can also build single files to test your changes. Qt Creator automatically detects the CMake executable specified in the PATH .

Should I use qmake or CMake?

If your project uses Qt, you're probably best off using qmake. CMake is more generic, and fits pretty much any type of project. Both qmake and CMake generate a Makefile, which is read by make to build the project. Not all build systems generate a Makefile, but many do.

Does CMake come with GCC?

CMake generates files for other build systems. These can be Makefiles, Ninja files or projects files for IDEs like Visual Studio or Eclipse. The build files contain calls to compilers like GCC, Clang, or cl.exe.


1 Answers

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__" />
like image 62
John Schug Avatar answered Nov 02 '22 12:11

John Schug