What are the differences and similarities between CMake and qmake?

Hareen Laks picture Hareen Laks · Dec 19, 2015 · Viewed 35.3k times · Source

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? I searched and found few documents but feel difficult to understand.

Answer

Kankaristo picture Kankaristo · Dec 19, 2015

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.