r/cpp • u/beer118 • 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)?
14
u/Pand9 Jan 09 '18 edited Jan 09 '18
if you want something new, There are quite a few rising stars. saner syntax, integrated package manager, module support - from top of my head: build2, meson... I think there's some other one but I forgot.
https://www.reddit.com/r/cpp/comments/524844/recommend_a_build_system
edit: Conan.io - a package manager that you can integrate into your build system, cmake too.
2
-13
u/c0r3ntin Jan 09 '18
Meson still relies on make so it suffers from all the same issue cmake does.
18
u/jpakkane Meson dev Jan 09 '18
Meson does not use Make. It has never used Make. It will never support Make in any way. Any pull request adding Make support will be immediately and unconditionally rejected.
The official stance of the creator and project lead of Meson (i.e. me)
7
u/c0r3ntin Jan 09 '18
But it uses other build system, right ? I must I'm not very familiar with meson but the tutorial mention ninja. Both
qbsandbuild2actually run the command and I have found that not relying on a 2 stage / 2 tools process is less error prone.Thanks for clarifying and the work you do :)
1
u/jpakkane Meson dev Jan 09 '18
Currently yes, but there's nothing in the design that mandates it. We could invoke the build commands ourselves but haven't had a need because Ninja is so fast and reliable.
5
u/nuoHep Jan 09 '18
Except it doesn't. http://mesonbuild.com/FAQ.html#why-is-there-not-a-make-backend
32
u/notbatmanyet Jan 09 '18
Cmake is the defacto standard modern buildsystem. I would recommend it.
0
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
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
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
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
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
10
u/doom_Oo7 Jan 09 '18 edited Jan 09 '18
With cmake:
cmake_minimum_required (VERSION 3.10)
project (MyGame)
find_package(SDL REQUIRED)
add_executable(MyGame WIN32
src/game.hpp
src/game.cpp
src/main.cpp) # etc...
target_include_directories(MyGame
PRIVATE
${SDL_INCLUDE_DIR}
src)
target_link_libraries(MyGame
PRIVATE
${SDL_LIBRARY})
set_target_properties(MyGame
PROPERTIES
CXX_STANDARD 17) # you want to be modern and learn new stuff right ? 6
u/thlst Jan 09 '18
you want to be modern and learn new stuff right ?
What's wrong with
target_compile_features(target PRIVATE cxx_std_17)?5
u/doom_Oo7 Jan 09 '18
indeed, at the beginning I wanted to add a few more properties to show how it's done but doing it like this is better
4
u/hgjsusla Jan 09 '18
Doesn't the FindSDL module define imported targets? Using variables like that is the "old" way AFAIK
2
u/doom_Oo7 Jan 09 '18
sadly, no :( : https://cmake.org/cmake/help/v3.10/module/FindSDL.html
I guess it wouldn't be too hard of a first contribution to CMake though :p the Find modules depend entirely on volunteer work AFAIK.
1
Jan 09 '18
I'm currently trying to use the Visual Studio 2017 integrated CMake 3.9 and I want to stab myself.
Visual Studio is ignoring some compile flags (that I toggled with target_compile_options) so I couldn't get it to build with C++17 enabled.
The documentation for CMAKE is also poor, with many deprecated functions not being labelled so until I stumble upon another newer function that says that it should replace the former.
4
11
u/c0r3ntin Jan 09 '18
The "pragmatic" approach is to use cmake because the community is converging on it.
However, it's the worse option, and if you don't have a lot of external dependency and are not working on a popular open source library intended to be used in another open source project, i would encourage you to look elsewhere.
Some contenders would be build2 or QBS. They are actual build system, rather than makefiles generator, which make them actually reliable (Which is why I'm not including meson in that list).
2
u/germandiago Jan 09 '18
As a person with long experience trying build systems I settled on Meson. The documentation kicks in the ass CMake documentation. It supports also more targets out of the box and the DSL is understandable. I prefer it. Genrators for Visual Studio and XCode, were better in CMake last time I checked.
2
2
1
u/caprica Jan 09 '18
Consider looking into bazel, buck and please. They are all inspired or directly based on google's internal blaze build system. They all work very well if you have full control over your dependencies and don't need a lot of configuration. Personally bazel is my favourite.
6
u/alexeiz Jan 09 '18
Both Bazel and Buck depend on Java. They don't compare favorably to CMake which doesn't have any of such large dependencies. It may be fine to require Java in your organization but it's pretty much a no go for C++ open source projects.
4
u/Fazer2 Jan 09 '18
What are your requirements?