1. The Birth of GCC!
In 1985, on a dark night where one could hardly see their hand in front of their face, a bearded, short-statured man with long, unkempt hair began to write a C language compiler. This man later became known as the “greatest programmer” and the “father of free software,” Richard Stallman. After two years of tireless effort, with a longer beard and even messier hair, Richard Stallman completed the first version of the C language compiler, called GNU C Compiler, which is the source of the now-famous GCC. Over time, GCC rapidly evolved, and now it can compile not only C but also C++, Fortran, Pascal, Objective-C, Java, and Ada among others. In the 80s and 90s, personal computer CPU frequencies, hard drive sizes, and memory sizes were all measured in MB, and even KB. The number of program files to be compiled was relatively small, and using the GCC command was sufficient.
2. New Troubles Arise! (make & makefile)
3. New Troubles Arise Again! (CMake & CMakeLists)
While makefiles can be manually written for simple projects, it becomes cumbersome as projects grow larger. Additionally, various platforms have emerged with different makefiles, such as GNU make, QT’s qmake, Microsoft’s MSnmake, BSD Make (pmake), Makepp, and others. These make tools follow different specifications and standards, leading to a wide variety of makefile formats. This brings about a serious issue: if software wants to be cross-platform, it must ensure it can be compiled on different platforms. Using the aforementioned make tools means writing a makefile for each standard, which can be frustrating, as switching platforms requires modifying the makefile again.
Therefore, CMake was introduced. CMake simplifies the generation of makefiles for the aforementioned make tool. CMake can also generate platform-specific makefiles, eliminating the need for manual modifications. CMake serves as a higher-level tool for makefiles, aiming to produce portable makefiles and reduce the significant workload of writing them by hand. But how does CMake generate makefiles? It does so based on a file called CMakeLists.txt (officially known as a configuration file). Who writes the CMakeLists.txt file? That would be you, the user.
4. New Troubles Arise Yet Again! (Ninja)
As software engineering becomes increasingly complex, the slow execution speed of make has become a growing concern.
Thus, a Google programmer introduced Ninja, a build tool focused on speed. Ninja discards various advanced features, with a very simple syntax and usage, specifying exactly what needs to be done, allowing for very fast compilation startup times. According to actual tests, even with over 30,000 source files, it can begin real builds within one second. In contrast, Makefiles crafted by experienced engineers require 10-20 seconds to start building.
5. The Perfect Conclusion!
CMake can generate .ninja and .makefile files. To alleviate concerns that many users may not be familiar with the writing of makefile and ninja files, CMake allows users to simply describe the source files (in the CMakeLists.txt file), automatically generating a project’s makefile or ninja file, which can then be used to initiate compilation with Ninja or make.
Humanity progresses by solving one problem after another!
Richard Stallman, the author of GCC and Make, is known as the greatest programmer and the father of free software. Recommended reading includes the following article.
The Father of Free Software—Richard M. Stallman
Disclaimer:
The copyrights of original and reprinted articles, images, etc. belong to the original authors. If there is any infringement, please contact us for removal.