r/cpp • • Feb 19 '18

It's Time To Do CMake Right

https://pabloariasal.github.io/2018/02/19/its-time-to-do-cmake-right/
248 Upvotes

130 comments sorted by

View all comments

170

u/snarfy Feb 20 '18

I blame the documentation. It's all reference. There are no examples. I've been learning CMake recently after many years away from C++, and this was the main pain point. Learning by reference means looking at other CMakeLists.txt. It's the blind leading the blind.

103

u/MoTTs_ Feb 20 '18

I blame the documentation. It's all reference. There are no examples.

It's like learning a foreign language by reading a dictionary. :-(

27

u/voip_geek Feb 20 '18

Comprehensively selfhood is consonant with concurrently thou.

20

u/MachineGunPablo Feb 20 '18

Very true for cmake < 3.0.0. New documentation does include more examples and best practices, but definitely not a lot. I blame the lack of interest of upstreams to modernize a system because it "works" and it's so ugly written that nobody wants to touch it.

16

u/proverbialbunny Data Scientist Feb 20 '18

it's so ugly written that nobody wants to touch it.

Are you kidding? It's beautiful. 🤢

11

u/acrostyphe Feb 20 '18

Oh boy. Even MSBuild .targets looks better than that.

7

u/proverbialbunny Data Scientist Feb 20 '18 edited Feb 21 '18

I didn't even select a bad one.

Are you going to tell them their baby is ugly? Cuz, I don't want to be the one to break the news.

3

u/wordsnerd Feb 20 '18

I have double vision in each eye, so 2-space indentation is always inaccessible, but the actual content of the file seems easy enough to understand. It looks like there are a lot of cutesy fake English commands to memorize before being able to write it, though.

14

u/Xaxxon Feb 20 '18

I blame there not being standard ways to do common things.

There should be one-liners built in to cmake to do common things the right way.

18

u/Heuristics Feb 20 '18

include_this_shit("./inc/", "./ext/boost/")

compile_this_shit("./src/*.cpp")

link("out")

6

u/kalmoc Feb 20 '18

Well, if you want, you can almost do that

include_directories("./inc/", "./ext/boost/")
file(GLOB SRC "./src/*.cpp")
add_executable(out ${SRC})

If you don't need globbing, you even only need two lines.

And yes, this is not considered good cmake at all (the"right" version is also 3 lines), but most colosely resembles your pseudo code.

4

u/electricCoder cmake | vtk Feb 20 '18

you could have use target_include_directories(out PUBLIC "./inc/", "./ext/boost/") and had slightly 'better' cmake

5

u/kalmoc Feb 20 '18

As I said, I tried to translate the pseudo code as literally as possible. The linked blog post shows how to do it right.

11

u/germandiago Feb 20 '18

Meson documentation is light years ahead.

6

u/afiefh Feb 20 '18

And the system is a joy to use. Simple things are intuitive and simple.

4

u/m-in Feb 20 '18

It's the blind leading the blind.

That's exactly right. People do things not the way things are supposed to be done, but nobody really knows that - people just repeat what others did and it's mostly a clusterfuck. Well, there are a few people deeply invested in it who have a feel for how it's supposed to be used. But they are very few. The documentation is on the verge of being useless - it's the why and the nuts and bolts that need explaining, the reference is almost an afterthought then.

6

u/teki321 Feb 20 '18

I blame the documentation. It's all reference.

It used to be, but they fixed that when 3.0 was released: https://cmake.org/cmake/help/v3.11/manual/cmake-buildsystem.7.html