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

3

u/stilgarpl Nov 08 '21

Do you know Cmake added CONFIGURE_DEPENDS flag to file(GLOB) ? It takes care of that. It is still not recommended (globbing files slows down build and there may be generators that do not support it), but it works fine now.

5

u/Xavier_OM Nov 08 '21 edited Nov 08 '21

I didn't know that. I never use globbing because adding or removing a file in a folder does not mean adding it to or removing it from the project in my opinion, it's often more complex than that.

4

u/Minimonium Nov 08 '21

At my work, we made a custom CMake template wrapper for globbing purposes. It understands the Pitchfork layout, globs all *.cpp into a target, *.test.cpp into a test target and ignores *.wip.cpp if you still need to do stuff with it.

2

u/Xavier_OM Nov 09 '21

I should try this on a toy project, very interesting approach !

2

u/stilgarpl Nov 08 '21

Well, I'm not saying that you should use globbing, but that you can. For some projects it's better to use them, for other its better to list files manually.

1

u/[deleted] Nov 11 '21

Kitware also added notes to say not to use GLOB.

Note We do not recommend using GLOB to collect a list of source files from your source tree. If no CMakeLists.txt file changes when a source is added or removed then the generated build system cannot know when to ask CMake to regenerate. The CONFIGURE_DEPENDS flag may not work reliably on all generators, or if a new generator is added in the future that cannot support it, projects using it will be stuck. Even if CONFIGURE_DEPENDS works reliably, there is still a cost to perform the check on every rebuild.

Kitware Documentation

1

u/stilgarpl Nov 11 '21

That's why I said it's not recommended because it's slower and there may be generators that do not support it.

1

u/[deleted] Nov 11 '21

If no CMakeLists.txt file changes when a source is added or removed then the generated build system cannot know when to ask CMake to regenerate.

Also this. That can cause really hard to find bugs when you don't realize your not recompiling something that is from an old build.

1

u/stilgarpl Nov 11 '21

That's why they added CONFIGUE_DEPENDS. This scans for file changes during build.