r/cpp • • Jul 21 '22

CMake is a hell of a software, period.

Really CMake is good only for one thing being the sacred build generator system in the c/cpp world.

F*** the weird syntax and werid structures.

edit 1: some might argue it's the best avaiable solution to the problem domain, and it is. the problem is the syntax, the unintiutive way of specifiying option and simple compile parameters and options and lack of examples and resources on how to do the simplist things is a wasting too much time.

yeah modern cmake that encourge using targets and their properties is by far a lot better but still is extremely unintuitve due to the syntax and logic around it.

sorry for the typos.

edit 2:

i am really considering changing my main language for personal projects to rust or the new thing called carbon by google at least there is not a hell of backward compatibility garbage i need to know.

358 Upvotes

319 comments sorted by

View all comments

Show parent comments

10

u/Drugbird Jul 21 '22

I've used / written both cmake and make files, and have to say that I generally prefer the makefile syntax.

I find it refreshingly straightforward how you can simply write: "to get file A, you need files B, C and D and then call command X".

Because you have direct access to the tools which are used, some things which can be tricky in Cmake can be trivial in make.

Because of this, I find that writing makefiles is a bit similar to writing docker files.

This direct approach is obviously impossible in Cmake, because it has to be platform independent. But the downside is that you need to go through the CMake middleman syntax.

Also, don't misunderstand me. Make is also horrible, especially when it comes to debugging (lol, good luck).

3

u/AlexReinkingYale Jul 22 '22

Where Make falls down for me is specifying rules that generate multiple outputs. CMake models this well and when it uses Ninja as a backend, it's more efficient, too.

1

u/Drugbird Jul 22 '22

I didn't recall much issues with multiple proud to be honest.

A quick Google shows this syntax works well for the case where data.hpp and data.cpp are both created from data.foo in a single command.

data.c data.h: data.foo 
        foo data.foo 

data.h: data.c

What issues did you run into?

3

u/AlexReinkingYale Jul 22 '22

That creates two separate rules: one for data.c and another for data.h. So if both go out of date, the command will run twice.

1

u/Drugbird Jul 22 '22

The second line introduces a dependency between the .h and .c file. So if make wants to build both, the .h will wait until the .c has been created and then will notice that the .h is newer than the .foo file, so the rule won't run again.

2

u/AlexReinkingYale Jul 22 '22

That assumes foo will touch the header even if its contents are unchanged.

1

u/Drugbird Jul 22 '22

That seems like an issue with every makefile recipe, not really specific to the multiple output file situation.

Anyhow, if this is an issue, just add "touch data.hpp" to the recipe.

I've personally never encountered this issue with any tool I've used.

2

u/AlexReinkingYale Jul 22 '22

That's not a solution because then sources that depend on data.hpp will be unnecessarily rebuilt. The unfortunate fact is that Make doesn't do this well. Weirdly, Make gets it right for pattern rules with multiple outputs, but that doesn't apply 100% of the time.

Ninja gets it right 100% of the time and CMake's Ninja backend uses Ninja's multi-output feature correctly.

2

u/arthurno1 Jul 22 '22

Debugging makefiles is still better than debugging cmake lists.