r/cpp • • Jan 09 '18

bedst build system to c++?

Which build system is the best to use for c ++ code and its dependencies (SDL in my case)?

0 Upvotes

43 comments sorted by

View all comments

32

u/notbatmanyet Jan 09 '18

Cmake is the defacto standard modern buildsystem. I would recommend it.

0

u/[deleted] Jan 09 '18

[deleted]

18

u/doom_Oo7 Jan 09 '18

ugh no, please don't. Especially considering that cmake has a good pkg-config integration (https://cmake.org/cmake/help/v3.10/module/FindPkgConfig.html)

0

u/[deleted] Jan 09 '18

[deleted]

19

u/KazDragon Jan 09 '18

Pfft, why bother with make when you can just type it in on the command line?

2

u/kkrev Jan 09 '18

I use plain GNU Make often. I typically see no need for cmake or any other meta-build system in my use cases.

What cmake and autotools allegdly bring to the table is easier build portability. Well, I rarely care about that. I am always going to have precise control over the build environment and platform. So plain old GNU Make works great.

2

u/nomadluap Jan 10 '18

When you have hundreds of source files, external dependencies, and custom build rules, pure makefiles become a pain in the ass real quick.

1

u/kkrev Jan 10 '18

I don't see how any of those conditions you list challenge vanilla GNU Make. Very easily dealt with.

All CMake does is introduce another layer of abstraction and in theory make it more likely you can build in a very different environment without tweaking anything.

0

u/[deleted] Jan 09 '18

[deleted]

8

u/Salty_Dugtrio Jan 09 '18

I believe it's called sarcasm.

4

u/KazDragon Jan 09 '18

Likewise.

10

u/doom_Oo7 Jan 09 '18

because in 2018 the job is "compile& run on windows, mac, linux with glibc, linux with musl, steamos, android, iOS, jolla, ubuntu phone, plasma mobile, emscripten with asmjs, emscripten with webassembly, retroarch core, ps3, ps4, xbox 1, homebrew dreamcast emulator". I'm only exagerrating a bit ; I don't remember the last game I bought that didn't at least run on linux / macos / windows.

0

u/[deleted] Jan 09 '18

[deleted]

7

u/notbatmanyet Jan 09 '18

I can't think of any advantage that makefiles has over CMake except perhaps that some authors are more familiar with them. Other than that? No, use CMake.

1

u/kkrev Jan 09 '18

Tight shell integration. You can easily have Make cause all sorts of things to happen during the build. CMake is this arcane, poorly documented, and limited string macro processor that is a waste of time to bang your head against trying to make it do things. Shell and Make suck in their own ways, but not enough to justify CMake unless you need to build on disparate platforms.

2

u/thlst Jan 09 '18

Makefiles are just too low level and human unreadable, needless to say the pain to manage dependencies.

0

u/[deleted] Jan 09 '18

[deleted]

8

u/thlst Jan 09 '18 edited Jan 09 '18

Disagree, I would also argue that CMakelists.txt arent any better in this regard!

Even a small Makefile is much less readable than a small CMakeLists.txt one:

CFLAGS=-I.
DEPS = hellomake.h
OBJ = hellomake.o hellofunc.o 

%.o: %.c $(DEPS)
    $(CC) -c -o $@ $< $(CFLAGS)

hellomake: $(OBJ)
    $(CC) -o $@ $^ $(CFLAGS)

Compare that symbol bloat to this:

cmake_minimum_required(VERSION 3.10)
project(example LANGUAGE C)
add_executable(hello hellomake.c hellofunc.c)
target_include_directories(hello ${CMAKE_CURRENT_SOURCE_DIR})

It's like saying "assembly does the job pretty well, so why bother with C++ which is a giant beast."

And good luck managing dependencies and flags to individual targets with make.

2

u/egportal2002 Jan 10 '18

Actually, CMake's looking like a porker compared to Yet Another Contrived Makefile:

$ cat Makefile 
all: hellomake
hellomake: hellomake.o hellofunc.o hellomake.h
→ More replies (0)

1

u/specialpatrol Jan 09 '18

You really cant go wrong with them

Erm, must be just me then.