I\'m new to programming so this is a more of a abstract question than a technical one. I\'ve been using IDE\'s to learn but I heard they tend to oversimplify the act of compilin
When compiling a large project with lots of files you can get lost if you call the compiler directly.
Of course you can put the related commands in a script and run it, but then you need to update the script if you add/remove a file. Also in that case you might want not to recompile everything every time you make a small change, so you want to only compile the parts that were changed. If you add this (and other quality of life) functionality in your hyphotetical script you are going to reinvent make
.
make
is designed to run only the compilation of the parts of your code that were changed till your last call to make
. It also allows you to automate adding sourcefiles and etc.
However if you want your code to work with several different compilers, and on several different platforms, and to link to different libraries, and so on, things get a little complicated for make
. You can still do it, but it is a lot of work. This is where cmake
comes.
cmake
builds makefiles (or similar build systems, example: Visual Studio) for the system you want. cmake
has prebuilt profiles for different compilers and systems that will automatically find the right set of compiler flags, find an link to the correct libraries and so on.
Of course if you are writing a "Hello World!" or similar program you don't need neither make
nor cmake
. If you don't need to support multiple compilers/platforms you don't need cmake
. If you are working on some huge library/application though make
and cmake
will help you do things easier.
Cmake is a "project generator". It doesn't actually build any object files etc.; what it does is generate the control files for other tools (such as GNU make) which will build object files, etc.
The advantage of using cmake instead of writing the makefile directly is that, using the same cmake input file, cmake can generate project files for all sorts of different build control tools: in addition to makefiles it can generate Xcode (Mac OS X) project files, Microsoft Visual Studio project files, and control files for other tools like Ninja. If you're writing software that needs to be built on lots of different platforms then cmake is often a good choice.
For your situation, it goes like this: cmake generates a set of makefiles (only). You typically only do this once when you have a clean workspace. Then you run make which uses those makefiles to invoke the compiler as needed, when various files change. The makefiles also have rules to re-run cmake itself if any of the cmake input files change.