Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do we need cmake?

I don't understand, why do we need cmake to build libraries ? I am sorry if my question is stupid, but i need to use some libraries on Widnows, and what ever library i choose i need to build it and/or compile it with cmake.. What is it for ? Why cant i just #include "path" the things that i need into my project, and than it can be compiled/built at the same time as my project ?

And also, sometimes i needed to install Ruby, Perl, Python all of them some specific version so cmake can build libraries... Why do i need those programs, and will i need them only to build library or later in my project too ? (concrete can i uninstall those programs after building libraries ?)

like image 923
Vess Avatar asked Oct 17 '16 10:10

Vess


People also ask

Do you need CMake for C++?

Installation. C++ CMake tools for Windows is installed as part of the Desktop development with C++ and Linux Development with C++ workloads. Both C++ CMake tools for Windows and Linux Development with C++ are required for cross-platform CMake development.

When should I run CMake?

The answer is simple: The cmake binary of course needs to re-run each time you make changes to any build setting, but you wont need to do it by design; hence "never" is correct regarding commands you have to issue.

Why is CMake better than make?

So, what is the real difference? 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.


1 Answers

Building things in c++ on different platforms is a mess currently.

There are several different build system out there and there is no standard way to do this. Just providing a visual studio solution wont help compilation on linux or mac.

If you add a makefile for linux or mac you need to repeat configurations between the solution and the makefiles. Which can result in a lot of maintenance overhead. Also makefiles are not really a good build tool compared to the new ones out there.

That you have only CMake libraries is mostly a coincidence. CMake is though a popular choice currently.

There are several solutions out there to unify builds. CMake is a build tool in a special way. It can create makefiles and build them but you can also tell cmake to create a visual studio solution if you like.

The same goes with external programs. They are the choice of the maintainer of the library you use and there are no standards for things like code generation.

While CMake may not be "the" solution (although the upcoming visual studio 2015 is integrating cmake support) but the trend for those build system which are cross-platform is going more and more in this direction.


To your question why you cannot only include the header:

Few libraries are header only and need to be compiled. Either you can get precompiled libs/dlls and just include the header + add the linker path. This is easier in linux because you can have -dev packages which just install a prebuild library and it's header via the package manager. Windows has no such thing natively.

Or you have to build it yourself with whatever buildtool the library uses.

like image 55
Hayt Avatar answered Sep 21 '22 17:09

Hayt