Cmake supports file(GLOB MY_SOURCES src/*)
to select files with a wildcard.
This is generally bad: Is it better to specify source files with GLOB or each file individually in CMake?
For a simple example, git mergetool
leaves backup files when resolving merge conflicts (In a git merge conflict, what are the BACKUP, BASE, LOCAL, and REMOTE files that are generated?) - with the original extension, not *.bak or something. If using globbing/wildcards in cmake, these will automatically just be included in the next build and it'll fail. There are other gotchas, but this is one.
Some people still insist on using globs/wildcards. Is there a way to filter globbed files to only those tracked by git?
Something like setting MY_SOURCES from shelling out to git ls-files src/*
. Can this even be done at configure time?
- This way, cmake would ignore random other files that happen to match the wildcard.
- As a bonus, it'll help catch those times I forget to
git add
new source files before pushing :)
Sure, the project should still compile without the .git directory, so this will need to be a best effort/only-if-available approach that falls back to file(GLOB ...)
if git fails. Also still to be frowned upon .