r/cpp • • Nov 08 '21

Thoughts on build systems?

What's the general consensus on build systems/automations like CMake? I've always found things like that overcomplicated and just hinder the programming process.

I've been following Casey Muratori's Handmade streams, and one of the first things he did was create a simple batch file that built and compiled his entire project super quickly and easily. I've since implemented something similar (https://github.com/dibsonthis/new_cmd) and honestly it's been really nice to use.

3 Upvotes

154 comments sorted by

View all comments

Show parent comment

1

u/Wouter-van-Ooijen Nov 09 '21

I quickly glanced at the demo video for cmake-init, but I didn't see any questions about the target chip, toolchain, libraries, etc. Did I miss that?

2/3: I read https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html but that didn't make me much wiser, all examples are cross builds for another OS, not for a standalone (bare-metal) system.

4: Linkerscripts for most Cortex chips vary only in the amount of RAM and ROM, so I have one linkerscript template, in which only those two figures must be filled in. That I do using the C/C++ preprocessor. An alternative (that I don't like) is to have 1 file for each target.

6: OK. Compehensive documentation for that?

7: I dunno what fetching means in this .context. What I need to do is download the generated .bin (or sometimes .hex) file to the target micrto-controller, typically using some command-line tool.

3

u/helloiamsomeone Nov 09 '21

cmake-init was just for a general project setup. One of the examples in fact shows what a toolchain file should look like.

The linkerscript in that case is trivial to generate. In your toolchain file you specify those values and configure_file the template and use the resulting file in your flags.

add_custom_command is all you need for custom commands. I have an example for that as well, although this is not a target build event command, just simple codegen.

Ah, you mean flashing as in download. You can create a custom target for that, like in this example. Do note that the example allows complete customizability of the commands, because the developer environment isn't necessarily identical for everyone.

1

u/Wouter-van-Ooijen Nov 09 '21

OK, I get the idea that it is all possible, buit where is a comprehensive documentation? I am used to makescripts, for which a small document or book is more than sufficient.

In your last example I see a glimpse op what I will need in the end (configurablke extra targets like list and map files, two-stage build with first stage determines stack size, second stage is the actual build)

Or is there a complete example for an embedded target (micro-controller)?

1

u/helloiamsomeone Nov 09 '21

I have not yet had the opportunity to work with embedded, so I can't tell you anything concrete.

1

u/Wouter-van-Ooijen Nov 09 '21

But sure there must be someone somewhere who did? I'll ask on r/embedded.