What are CMake vs qmake pros and cons?

I would like to know reasons for use CMake for particular project over qmake and vice versa.

Simply what are the pros and cons of both build systems?


Solution 1:

Both are build systems, but they're not very similar at all. 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. Even a Makefile is a type of build system; it tells the compiler and linker what to do, in order to create an executable (or a dynamic or static library).


If your project uses Qt, but you don't want to use qmake, you'll have to do a few more things yourself:

  • running the Meta Object Compiler (MOC)
  • include paths (tell the compiler where to look for Qt headers)
  • linking (tell the linker where to look for Qt libraries)

So, you'll have to do a bit more work to build a Qt project without qmake, but it is possible and it will teach you a lot about how Qt and qmake do things.

On a personal note (take this only as a recommendation, do further research yourself): I'm not a big fan of qmake. It helps you with the Qt stuff, but apart from that, I've found it to be pretty limited.


In any case, I would recommend learning to build a small project (~10 source files) without using any type of build system. Not using CMake, not with a Makefile, just using the compiler and linker directly. You shouldn't actually build any real project in this way, but you should learn how to do it, just to learn what build systems actually do. Knowing what they do will make them a lot easier to use.


A few months ago, we switched a project from qmake to Premake, which is also worth a look. It's highly scriptable (with Lua), which is great when you need to customize your build process.

That said, it is a bit more "manual", so prepare yourself to learn how compiling and linking works at a more basic level, without the use of a build system. It's also in beta (Premake 5), so there are some bits and pieces still missing.

You can also take a look at qbs, which is supposed to be a better qmake. It's still in a beta stage, so I'd wait while it matures and becomes easier to use.

Solution 2:

CMake is by far the more powerful build system. The syntax is "not so nice" to put it mildly. But then, for any complex project, what one has to do with QMake (or any buildsystem I know of) to achieve things isn't nice either. For simple projects, QMake is nicer to look at though.

If you need configure checks for third-party dependencies other than Qt, CMake is what you want, support for configure checks in QMake is minimal to non-existent.

QMake on the other hand works great with Qt Creator (CMake support in there is lacking, although it's doable to use CMake with Creator).

If you want to build and deploy for iOS and Android from within Qt Creator, I strongly suggest QMake. (Not sure if it's even possible these days with CMake - it will be certainly cause a lot more headache).