Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the major differences between makefile and CMakeList

Tags:

makefile

cmake

I've searched for the major differences between makefile and CMakeLists, but found weak differences such as CMake automates dependency resolution whereas Make is manual.

I'm seeking major differences, what are some pros and cons of me migrating to CMake?

like image 251
Ahmed Adel Avatar asked Sep 05 '12 11:09

Ahmed Adel


People also ask

What is Cmakelist for?

Last modified: 12 February 2022. CMakeLists. txt file contains a set of directives and instructions describing the project's source files and targets (executable, library, or both). When you create a new project, CLion generates CMakeLists. txt file automatically and places it in the project root directory.

What is the difference between GCC and make?

gcc is a compiler like javac . You give it source files, it gives you a program. make is a build tool. It takes a file that describes how to build the files in your project based on dependencies between files, so when you change one source file, you don't have to rebuild everything (like if you used a build script).

Should I use CMake or Makefile?

cmake is a system to generate make files based on the platform (i.e. CMake is cross platform) which you can then make using the generated makefiles. While make is you directly writing Makefile for a specific platform that you are working with. If your product is crossplatform, then cmake is a better choice over make .

Is Ninja better than make?

Differences between Make and Ninja For incremental builds, Make is significantly slow. Ninja is faster and helps developers spend less time on building software. This becomes a driving force for large projects such as Google Chrome. In general, performance of Ninja is much better than Make.


1 Answers

You can compare CMake with Autotools. It makes more sense! If you do this then you can find out the shortcomings of make that form the reason for the creation of Autotools and the obvious advantages of CMake over make.

Autoconf solves an important problem—reliable discovery of system-specific build and runtime information—but this is only one piece of the puzzle for the development of portable software. To this end, the GNU project has developed a suite of integrated utilities to finish the job Autoconf started: the GNU build system, whose most important components are Autoconf, Automake, and Libtool.

Make can't do that. Not out of the box anyway. You can make it do it but it would take a lot of time maintaining it across platforms.

CMake solves the same problem (and more) but has a few advantages over GNU Build System.

  1. The language used to write CMakeLists.txt files is readable and easier to understand.
  2. It doesn't only rely on make to build the project. It supports multiple generators like Visual Studio, Xcode, Eclipse etc.

When comparing CMake with make there are several more advantages of using CMake:

  1. Cross platform discovery of system libraries.
  2. Automatic discovery and configuration of the toolchain.
  3. Easier to compile your files into a shared library in a platform agnostic way, and in general easier to use than make.

Overall CMake is clearly the choice when compared to make but you should be aware of a few things.

  • CMake does more than just make so it can be more complex. In the long run it pays to learn how to use it but if you have just a small project on only one platform, then maybe make can do a better job.
  • The documentation of CMake can seem terse at first. There are tutorials out there but there are a lot of aspects to cover and they don't do a really good job at covering it all. So you'll find only introductory stuff mostly. You'll have to figure out the rest from the documentation and real life examples: there are a lot of open source projects using CMake, so you can study them.
like image 153
Cristian Bidea Avatar answered Oct 26 '22 21:10

Cristian Bidea