Newbie question. I recently came across a project that contained lots of files and external libraries. Some of these libraries contained Makefiles and CMakeLists.txt. Im building a similar project that involves external libraries. Is it necessary to learn both CMake and make. Or is CMake sufficient?
CMake is much more high-level. It's tailored to compile C++, for which you write much less build code, but can be also used for general purpose build. make has some built-in C/C++ rules as well, but they are useless at best.
When comparing CMake with Make, there are several advantages of using CMake: Cross platform discovery of system libraries. Automatic discovery and configuration of the toolchain. Easier to compile your files into a shared library in a platform agnostic way, and in general easier to use than make.
CMake is a generator of build systems that can produce Makefiles for Unix like systems, Visual Studio Solutions for Windows and XCode projects for Mac OS.
The short answer is that you don't, but it would probably be difficult to build the project without it. CMake does not build code, but is instead a build file generator. It was developed by KitWare (during the ITK project around 2000) to make building code across multiple platforms "simpler".
Unlike Make, CMake’s two stage build process lets the programmer work with platform’s debugging tools if necessary. During the CMake build process it is customary to create a folder named `build` that keeps all the build artifacts. This prevents source code getting polluted with build related artifacts like object files.
You can also use “Make” to control installing or uninstalling a package, generate tags tables for it, or anything else you want to do often enough to make it worth while writing down how to do it. CMake. CMake stands for Cross-platform Make. CMake recognizes which compilers to use for a given kind of source.
With CMake, the compiler flags and build system are generated for you, and so you can use Visual Studio, NMake, Make, Ninja, Android.mk, XCode, etc. all with the same inputs.
CMake comes bundled with a GUI for all platforms it supports. This makes a smoother learning curve for CMake that greatly influenced its quick adoption. Using GUI of CMake, the programmer can configure the build first and then generate the build. The well-designed GUI of CMake guides the programmer to get a build.
No need to learn to write a makefile
, since CMake is an abstraction layer or "meta-make" generating the makefiles for you. And as any abstraction layer you just need to learn using its functions. But you also need to understand the task its was developed for. In this case e.g. What is a build tool? or What is a native build environment?
But cmake - in combination with ctest, cpack and cdash - is much more then that, it does (mostly) eliminate the need to learn the compiler/linker switches, your platforms/frameworks handling of libraries/executables and their installation, etc.
Out of my experience with using CMake in my projects:
The downside: you need to put it to a test on all your targeted environments (admittedly that's nothing specific for CMake). In an closed environment (e.g. inside a company) it's relatively easy to maintain, but in e.g. an opensource setting there will always be the one or other precedent where you will need to tweak your CMake script a little.
The upside: CMake is widely used/supported in C/C++ projects and it gives me as potential user of your project the option to take my build environment and make tool of choice (e.g. I have replaced make
with ninja
in my projects).
References
CMake is a Makefile (and other project files) generator. You don't need to learn make
unless you're going to hook into CMake itself.
However, some classical make
knowledges are still useful, such as:
-j
flag for parallelmake V=1
for verbose outputmake clean
for cleaningmake install
and the DESTDIR
parametersIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With