The cmake-project Script Generating a CMake Project For a Single Executable in C++
If you ever need to create a project around a single C++ file (or just a few C++ files) in CMake, as you might for quick test cases, you might find it tedious to write a CMakeLists.txt file by hand every time. To make this easier, I’ve written a script called cmake-project that you can use to generate an initial CMakeLists.txt for you. Similar to qmake -project, it allows you to quickly create a project around a single or just a few C++ files. In addition, it automatically adds a link to Qt Widgets when the code uses QApplication.
A few special features that come with CMake are support for many languages (like Fortran, CUDA, and Objective-C), native support from many IDEs (Qt Creator and Visual Studio XCode), many active contributors, many out-of-the-box configuration checks, use of non-recursive make for faster build times, and out-of-the-box support for Ninja for even faster build times. These features are a few of the reasons why Qt 6 switched from QMake to CMake.
Add the cmake-project script on top of all these fantastic features and you can enjoy the only feature people miss from QMake while working in CMake. In turn, your productivity will be better than ever!
The cmake-project script is available for free, as part of KDToolBox: https://github.com/KDAB/KDToolBox/tree/master/qt/cmake-project
Feel free to give it a try!
If you’d like to know more about working with CMake, we have a CMake and Qt video series on YouTube that might interest you.