
But as I read in several places, making simple things with CMake is simple, it’s custom things that make everything horrible and awful - something I am yet to see.Īnd when it comes to Visual Studio Code as an IDE for Qt development, I have to admit - Qt Creator is still better. Well, it turned out to be easier than I thought - to use CMake for building Qt applications, though I spent a couple of days till I made it work.
Linking CXX executable qt -widgets -cmake. Building CXX object CMakeFiles\qt -widgets -cmake. dir\qt -widgets -cmake_autogen\mocs_compilation. Executing command : e:\tools\cmake\bin\cmake.EXE -build e:/code/qt-widgets-cmake/build -config Debug -target all -j 18 Automatic MOC and UIC for target qt-widgets-cmake Building CXX object CMakeFiles\qt -widgets -cmake. If it’s all good, run CMake: Build and you’ll get your application executable in the build folder. 27023 /bin/Host圆4/圆4/cl.exe - works Detecting CXX compiler ABI info 27023 /bin/Host圆4/圆4/cl.exe Check for working CXX compiler : E:/tools/vs/VC/Tools/MSVC/ 14. Check for working CXX compiler : E:/tools/vs/VC/Tools/MSVC/ 14. 27023 /bin/Host圆4/圆4/cl.exe - works Detecting C compiler ABI info 27023 /bin/Host圆4/圆4/cl.exe Check for working C compiler : E:/tools/vs/VC/Tools/MSVC/ 14. 27030.1 Check for working C compiler : E:/tools/vs/VC/Tools/MSVC/ 14. 27030.1 The CXX compiler identification is MSVC 19.16. The C compiler identification is MSVC 19.16.
So here’re the changes to be made in CMakeLists.txt:
since QML files are part of resources, you need to tell CMake about that. instead of Widgets you now need Quick and Qml modules. there is no need in CMAKE_AUTOUIC as you won’t be using widgets-based. Qt QuickĬMake project file for a Qt Quick application is not that difficult either. And of course you can define your own variables: for instance, I used my variable sources to gather all the source files for add_executable(). So instead of writing the name of the project ( qt-widgets-cmake) I just refer to the CMAKE_PROJECT_NAME variable. Set( CMAKE_AUTOUIC ON) message( "Looking for Qt.") # Qt modules () you're using in your applicationįind_package( Qt5 REQUIRED Widgets) if ( $ construction - that’s how you use variables in CMake. Set( CMAKE_AUTOMOC ON) # if you're using Widgets and editing. Set( CMAKE_INCLUDE_CURRENT_DIR ON) # run moc automatically Project( "qt-widgets-cmake") # find includes in the corresponding build directories Qt WidgetsĪnyway, here a project file for a Qt Widgets based application:Ĭmake_minimum_required( VERSION 3.10) # your project name Surprisingly, the simplest one turned out to be the one from the official Qt documentation - who would have thought, as usually it’s the other way around. Lots of examples from the internet didn’t work and were way too complex and overloaded in general. And having spent some time I’ve managed to create correct CMakeLists.txt files for both projects, although I can’t tell that it was very straightforward. I’ve never used CMake for anything before, so to get familiar with it I decided to create two very basic applications, one with Qt Widgets and another with Qt Quick. I tried it on Windows 10 with MSVC 2017, however it will work on other systems too. I also wanted to try Qt development with Visual Studio Code, and now is a good occasion for that. Let’s see then what it takes to switch from qmake to CMake with a couple of basic examples. So I guess we should start using CMake for building Qt applications as well. After numerous promises of how Qbs will be the Qt’s default build system, The Qt Company suddenly killed it, announced that qmake is a dead man walking too, and actually Qt is switching to CMake.