Rienhart_
Rienhart_

Reputation: 259

CMake or make. Do I need both?

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?

Upvotes: 22

Views: 14931

Answers (3)

Florian
Florian

Reputation: 42842

How to frame the concept behind CMake

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?

What does the "c" in cmake stand for?

But - in combination with , and - 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.

  • Cross-Compile
  • Cross-Platform
  • Cross-Language
    • It does support mainly C/C++ but has also support for e.g. Asm, RC, Fortran and with CMake version 3.8 C#
    • It does eliminate the need to learn other script languages (often used to perform pre- or post-build steps), because it has a mid-sized script language embedded

Difference between using Makefile and cmake to compile the code

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

Upvotes: 15

DevSolar
DevSolar

Reputation: 70213

CMake is a meta-buildsystem.

Using cmake and the settings in CMakeLists.txt, CMake will generate the build files for the target platform. That could be Makefiles, Visual Studio solutions, Ninja files, KDevelop project files, ...

If the project is set up to utilize CMake, you should have no need to even look at the buildfiles (Makefiles) generated. They are strictly temporary.

Upvotes: 2

Tatsuyuki Ishi
Tatsuyuki Ishi

Reputation: 4031

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:

  • Passing the -j flag for parallel
  • make V=1 for verbose output
  • make clean for cleaning
  • make install and the DESTDIR parameters

Upvotes: 2

Related Questions