Skip to content

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.

About KDAB

If you like this article and want to read similar material, consider subscribing via our RSS feed.

Subscribe to KDAB TV for similar informative short video content.

KDAB provides market leading software consulting and development services and training in Qt, C++ and 3D/OpenGL. Contact us.

Categories: C++ / CMake / KDAB Blogs / KDAB on Qt / Qt / Technical

Tags: / / /

3 thoughts on “The cmake-project Script”

  1. Thanks, that comes in quite handy!
    My colleagues will love this 😉

    Best regards,
    Markus

  2. David Faure

    I just added the feature of being able to choose the Qt version (5, 6, or none for pure C++ projects).

Leave a Reply

Your email address will not be published. Required fields are marked *