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?
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 .
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.
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.
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__" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With