r/cpp • • Sep 10 '16

Recommend a build system

I'm curious what people are currently recommending as build systems for C++ based projects. Specifically I'm after the following features:

  • Cross-Platform, supporting at the very least OSX and Linux

  • Easy to support C++14, preferably without needing to do per-platform/per-compiler configuration

  • Easy support for multiple libraries/executables as one project, and dependencies between libraries/executables in the project - especially regarding finding include files if the different modules are in different areas of the source tree.

  • Decent support for external dependencies. I'm ok with needing to have installed the dependency libraries first though

  • Support for dynamically finding source files if possible. (I'm used in Java, and most of the Java build tools just use every single file in the source directory for a given module)

  • Support for building and executing tests

  • Support for static checks

  • Support for generating documentation, and generally running other tools as part of the build

  • Ideally, support for being able to execute tooling before and after test execution - to be able to start up externally required services such as databases.

Is there anything that supports this entire list? (I'm assuming not) Or what would people recommend for use that at least comes close. I'm perfectly happy with tools that are opinionated about how the source tree should be laid out, if that fits the bill better.

60 Upvotes

189 comments sorted by

View all comments

0

u/[deleted] Sep 10 '16

[deleted]

6

u/AntiProtonBoy Sep 11 '16

Curious, what are the complaints with CMake? At first glance it looks more inviting than autotools.

4

u/wrosecrans graphics and network things Sep 13 '16

more inviting than autotools.

That's largely also true of a sign saying "Trespassers will be shot, also beware of angry dog."

0

u/[deleted] Sep 11 '16

[deleted]

8

u/streu Sep 11 '16

As with C++, there's a much cleaner language within struggling to get out.

One thing I recommend everyone to stop using is "file(glob...)": this makes it guesswork what CMake will build, and requires the manual re-run to pick up new source files. Save that manual-work slot for adding the file to the CMakeLists. Another thing is its auto-detection for various environment parameters. Cool if it works, sucks if it doesn't. Better give it explicit parameters ("today, I want to build for Cygwin; tomorrow I want to build for Win32").

OK, and another thing that makes CMake suck is its abuse of Makefiles in the Makefile generator. "Recursive make considered harmful".

7

u/[deleted] Sep 11 '16

Agreed. I've seen horrible, horrible bugs shipped as a result of people putting globs in a build system, then not discovering components have been shipping broken for months in some unrelated part of the system because inputs were moved around, and nobody noticed because the build "succeeded". Globs make figuring out what depends on what in large build trees impossible.

0

u/[deleted] Sep 11 '16

[deleted]

6

u/streu Sep 11 '16

I'm objecting to use "file(glob...)" as the means to gather up source code just because it seems convenient during development.

I'm not objecting to using "file(glob...)" to locate plugins. Locate a list of subdirectories in folder plugins/, pass them to add_subdirectory - fine. Actually, our CMake-based build system works totally like that. But that's about the only place where "file(glob...)" makes sense.

My criticism with CMake is that it has few if any conventions, and people happily start using its internals wherever they see fit. My CMakeLists consist of an add_executable and maybe some add_definitions. That's easy to reproduce or to port. Others poke within internals using target and file properties, dozens of if's with all sorts of semi-undocumented variable names, etc. That's definitively not a joy to maintain if no two CMakeLists look alike.

1

u/Pand9 Sep 11 '16

If "cmake <sourcedir>" can detect that GLOB's value changed - then you're right. If you use GLOB on a single directory, it's still only a local "ambiguousity", right? It doesn't interfere with other subdirectories. I can live with contract like this. Difference between this and manually specifing files in CMakeLists is only whether you edit that file or not.

That's how it should be. I'm not sure if it is, though.

-2

u/render787 Sep 11 '16

I strongly disagree, globbing your source directory is correct, and manually specifying the files is a tedious and needless waste of time. It's not "guesswork" -- it's going to build everything in the directory. What is ambiguous about that. And even if you manually curate the list, you are going to have to rerun cmake anyways whenever you update it, and you will get "confused" if you don't. I fail to see any logic in your argument.

7

u/[deleted] Sep 11 '16

No, because when you add the file to CMakeLists.txt the build system sees that it is out of date and runs the correct bits for you automatically. You just type ninja or make and you get correct incremental behavior.

1

u/pfultz2 Sep 12 '16

Instead of editing the CMakeLists.txt, you can just do touch CMakeLists.txt and cmake will see its out of date and update. Although you could forget to run touch, you can also forget to add the source file to CMakeLists.txt as well, so I don't see the difference.

→ More replies (3)
→ More replies (5)

4

u/streu Sep 12 '16

I'm doing a little inhouse support for developers, and forgetting to have re-run CMake to update file globs is the single most frequent problem I see.

Building the wrong code appears less often, but it does appear: CMake picking up a temporary test file that was not intended to build. Or a backup file from the editor or SCM system because the glob pattern was overly broad (or the file name badly chosen).

If you want deterministic behaviour, say what you want. Easy as that.

3

u/[deleted] Sep 11 '16 edited Oct 06 '16

[deleted]
0.7992

What is this?

9

u/steveire Contributor: Qt, CMake, Clang Sep 11 '16

No one should do this. You must have broken content in your cmake files.

1

u/[deleted] Sep 11 '16 edited Oct 06 '16

[deleted]
0.2136

What is this?

4

u/sazzer Sep 11 '16

Doesn't CMake automatically reconfigure itself if the CMakeLists.txt changes?

→ More replies (4)

3

u/encyclopedist Sep 11 '16

You can also reconfigure quickly using

make rebuild-cache

2

u/steveire Contributor: Qt, CMake, Clang Sep 11 '16

You do not have to delete your cache and cmakefiles.

1

u/[deleted] Sep 11 '16 edited Oct 06 '16

[deleted]
0.1955

What is this?

1

u/steveire Contributor: Qt, CMake, Clang Sep 11 '16

Ok. I don't know how that is possible. If you want to not have to delete the cache and cmakefiles, I recommend you create a http://sscce.org/ and file a bug.

1

u/[deleted] Sep 11 '16 edited Oct 06 '16

[deleted]
0.9652

What is this?

→ More replies (0)

5

u/lluad Sep 11 '16

CMake being complete shit doesn't mean it's not better than autotools in almost every respect.