Yet another CMake tutorial written by someone who has no idea how to use CMake.
They glob for sources which is bad enough, but then they glob recursively and without setting CONFIGURE_DEPENDS, which is outright incorrect and won't notice additions or removals of files without rerunning CMake (not just the build tool) manually.
The minimum version is 3.10, which is FAR from modern, while 3.16 is available everywhere and 3.20 is around the corner.
Skipped ahead to the "how to use libraries" section. The code doesn't use imported targets. So, again, not modern. Also, find_library doesn't have a REQUIRED argument until 3.18, so that code will just outright not work on the advertised version. Edit: worse, the video uses SFML in an unsupported way; the variables they expand were removed in 2018 in favor of imported targets. The example code doesn't even work on Ubuntu 20.04 LTS.
You list the source files manually. There are a lot of reasons for this.
The devs tell you not to. This is huge. It means that when something goes wrong, your bug reports get rejected.
CONFIGURE_DEPENDS is not guaranteed to work on all generators. Edit: a colleague tells me it's broken before Ninja 1.10.2.
When things go wrong, like during a git bisect, it's hard to figure out what went wrong and which file was mistakenly added or ignored.
It gets slower with more files since globbing is slow. It slows down your incremental builds too since it has to re-glob every time (with CONFIGURE_DEPENDS). This is particularly an issue on Windows.
The CONFIGURE_DEPENDS flag makes it so the glob is re-run on every build (eg. Make or Ninja run) so that CMake can run again if the glob result changes. Without it, the build is utterly broken. With it, you still run into issues. List your source files.
Listing files manually is a nonstarter for me and for a lot of other people I talk to. Thank you for mentioning configure_depends though! I’ll add a warning about that.
Don't listen to him. There was a talk from a packager for vcpkg who basically begs one to glob. It will make packaging much easier, and forces you to organize your library better for yourself. Edit: link https://m.youtube.com/watch?v=_5weX5mx8hc
Thank you! I've had a lot more issues with failing to add the source file when listing manually than I've ever had from globbing so even the slightly slower builds are worth it.
Adding source files manually is really not a big deal you know, it doesn't happen so often in everyday life, and when it happens adding them to CMakeLists.txt (or in your IDE) does not take such a long time, you add a few lines and voilà.
The codebase I work on is quite big (~2400 .h/.cpp files) and even on such size there is no need for globbing.
I've had to do it at work before so I understand it's just a minor thing but occasionally I do misspell it or get the path wrong, etc and it's just annoying. It might be personal preference from other languages where such files are tracked automatically by your build system but I still find it an annoyance.
32
u/AlexReinkingYale Feb 07 '21 edited Feb 07 '21
Yet another CMake tutorial written by someone who has no idea how to use CMake.
They glob for sources which is bad enough, but then they glob recursively and without setting CONFIGURE_DEPENDS, which is outright incorrect and won't notice additions or removals of files without rerunning CMake (not just the build tool) manually.
The minimum version is 3.10, which is FAR from modern, while 3.16 is available everywhere and 3.20 is around the corner.
Skipped ahead to the "how to use libraries" section. The code doesn't use imported targets. So, again, not modern. Also, find_library doesn't have a REQUIRED argument until 3.18, so that code will just outright not work on the advertised version. Edit: worse, the video uses SFML in an unsupported way; the variables they expand were removed in 2018 in favor of imported targets. The example code doesn't even work on Ubuntu 20.04 LTS.
Skip this.