Differences and Connections Between CMake, NMake, and QMake

This article is reproduced from Zhihu, the link and author information are as follows.

Author: Hui Chang Ge Link: https://www.zhihu.com/question/27455963/answer/89770919 Source: Zhihu Copyright belongs to the author. For commercial reproduction, please contact the author for authorization, and for non-commercial reproduction, please indicate the source. I often forget these concepts, even after reading them several times, so I copied and pasted them from Zhihu for future reference.

1. GCC is the GNU Compiler Collection (which is the GNU compiler suite) and can simply be thought of as a compiler. It can compile many programming languages (including C, C++, Objective-C, Fortran, Java, etc.).

2. When your program has only one source file, you can directly use the gcc command to compile it.

3. However, when your program contains many source files, using the gcc command to compile them one by one can easily become confusing and labor-intensive.

4. Therefore, the make tool emerged. The make tool can be seen as an intelligent batch processing tool; it does not have the capability to compile and link itself but uses a batch-like method—by calling the commands specified by the user in the makefile to perform compilation and linking.

5. What is a makefile? Simply put, it is like a musical score, and the make tool is like a conductor. The conductor directs the orchestra based on the score, while the make tool compiles and links according to the commands in the makefile.

6. The commands in the makefile include calling gcc (or another compiler) to compile a certain source file.

7. A makefile can be manually created for simple projects, but when the project is very large, writing a makefile by hand becomes cumbersome, and if the platform changes, the makefile needs to be modified again.

8. This is where the CMake tool comes in; CMake can generate makefile files for the above make tool more easily. Of course, CMake has other functions, such as generating corresponding platform-compatible makefiles, so you do not have to modify them yourself anymore.

9. But what does CMake use to generate makefiles? It generates them based on a file called CMakeLists.txt (scientific name: configuration file).

10. Who writes the CMakeLists.txt file in the end? You do it yourself.

11. Of course, if you use an IDE like VS, it can generally help you set it up, and you just need to click that triangle.

12. Next is qmake. What is qmake? Let’s first talk about Qt. Qt is a cross-platform C++ graphical user interface application development framework. It can develop both GUI programs and non-GUI programs, such as console tools and servers. In simple terms, it is a third-party library for C++, and using this library allows you to easily generate graphical interfaces for platforms like Windows, Linux, and macOS. The current Qt also includes functional modules commonly needed for software development (networking, databases, XML, multithreading, etc.), making it more convenient and simpler than using C++ directly (which only comes with standard libraries).

13. You can easily implement very complex functions with Qt because Qt extends C++. When you write one line of code, Qt helps you write hundreds or thousands of lines behind the scenes, and this additional code is translated by Qt’s proprietary MOC (Meta-Object Compiler) and UIC (User Interface Compiler). The problem arises that before compiling the program, you must first call MOC and UIC to preprocess the Qt source files, and then call the compiler for compilation. The ordinary makefile mentioned earlier is not suitable; it cannot preprocess Qt source files. Thus, qmake was created.

14. The qmake tool was developed by the Qt company to generate Qt-specific makefile files, which can automatically and intelligently call MOC and UIC to preprocess and compile the source program. Qmake must also be cross-platform, just like CMake, and can generate corresponding makefile files for various platforms.

15. Qmake generates the corresponding makefile based on the Qt project file (.pro). The project file (.pro) is relatively simple, and you can generally write it by hand, but it is usually automatically generated by the Qt development environment, Qt Creator, so you just need to hit that evil triangle.

16. It’s not over yet. Since qmake is very simple and easy to use, supports cross-platform, and can be independent of its IDE, you can also use it in non-Qt projects, and it can still generate ordinary makefiles. Just add CONFIG -= qt in the .pro file.

17. So what is the difference between qmake and CMake? Sorry, CMake also supports Qt programs and can generate special makefiles for Qt programs; however, the CMakeLists.txt file is relatively more complex to write compared to the .pro file of qmake. Qmake is tailor-made for Qt and is very convenient to use, but CMake is more powerful than qmake. Generally, for Qt projects, you can directly use qmake, while the powerful features of CMake are generally not needed. When your project is very large, with Qt subprojects and subprojects in other languages, it is said that using CMake will be more convenient, but I have not tried it.

QMake and NMake

April 11, 2012 14:34:09 Congwulong Read count 3230

<<<<<<<<<<<<<<<<<<<<<<<< What is qmake? Qmake is used to generate makefiles. What is a makefile for? The makefile records all the files in the project, and the compiler compiles according to the makefile. How does qmake generate makefiles? It is based on the project file (.pro file) created by the developer. If you are developing in Windows using VS, you first need to set the qmake environment variable to win32-msvc. The .pro file tells qmake how to generate the makefile, such as which source files and header files the project has, specific configurations for the application, such as additional libraries to link, or an additional include path. All of these should be placed in the project file. Summary: Writing a makefile by hand is difficult and error-prone; using qmake, developers only need to create a simple project file and run qmake to generate the appropriate makefile.

<<<<<<<<<<<<<<<<<<<<<<<< What is nmake? It processes makefile files, interprets the statements inside, and executes the corresponding instructions. When calling NMAKE, it checks all related files; if the timestamp of the target file is older than that of the dependency file, nmake executes the operations associated with that dependency. For example: foo.exe : first.obj second.obj link first.obj, second.obj The first line defines the dependency; the second line gives the operation associated with that dependency. If either first.obj or second.obj is modified, link.exe must be called to relink and generate foo.exe. This is the execution logic of nmake.

<<<<<<<<<<<<<<<<<<<<<<<< The syntax of makefile is slightly…

Summary: nmake is equivalent to an interpreter, while makefile is a programming language, and the program (makefile file) written is interpreted and executed by nmake.

Make-Makefile — Differences and Connections Between CMake, NMake, and QMake

April 20, 2018 10:13:10 Decisive Battle in the Forest Read count 182

1. Make is used to execute makefile files. The makefile is a script file similar to batch processing in a Unix-like environment (such as Linux). Its basic syntax is: target + dependencies + commands; commands are only executed if the target file does not exist or if the target is older than the dependency files. Thus, makefile and make can be applied to any task, not limited to programming. For example, it can be used to manage LaTeX.

2. Makefile + make can be understood as a project management tool in a Unix-like environment, but it is too basic, has a low level of abstraction, and is not very friendly in Windows (for Visual Studio users), which is why cross-platform project management tools like CMake emerged.

3. CMake is a cross-platform project management tool that organizes projects using a more abstract syntax. Although it still involves targets, dependencies, and similar concepts, it is more abstract and user-friendly. For example, you can use ‘math’ to represent the math library without needing to specify whether it is math.dll or libmath.so. In Windows, it will support generating Visual Studio projects, while in Linux, it will generate Makefiles, and it can even generate Eclipse project files. In other words, starting from the same abstract rules, it customizes project files for various compilers. CMake is a project management tool with a higher level of abstraction, and the commands executed by CMake are in the CMakeLists.txt file.

4. QMake is a Qt-specific project management tool, and the corresponding project file is *.pro. In Linux, it will also generate Makefiles, of course, in the command line you will need to manually execute qmake, but you can completely open the *.pro file in the specialized IDE Qt Creator, and you don’t have to worry about the tedious details of using the qmake command.

In summary, make is used to execute makefiles, CMake is used to execute CMakeLists.txt, and qmake is used to handle *.pro project files. The level of abstraction for makefile is the lowest, while CMake and qmake will eventually generate a makefile in Linux and other environments. CMake and qmake support cross-platform functionality, with CMake generating project files for specified compilers, while qmake operates independently. Nmake is generally used for compilation in Windows systems with Visual Studio.

CMake/QMake — Cross-platform — Generate Makefile

NMake — Windows VS — Generate Makefile

Make — Makefile

My personal summary, if there are any inaccuracies, please correct me. Thank you!

Differences and Connections Between CMake, NMake, and QMake

Leave a Comment