Why is cmake file GLOB evil?

The problem is when you’re not alone working on a project.

Let’s say project has developer A and B.

A adds a new source file x.c. He doesn’t changes CMakeLists.txt and commits after he’s finished implementing x.c.

Now B does a git pull, and since there have been no modifications to the CMakeLists.txt, CMake isn’t run again and B causes linker errors when compiling, because x.c has not been added to its source files list.

2020 Edit: CMake 3.12 introduces the CONFIGURE_DEPENDS argument to file(GLOB which makes globbing scan for new files: https://cmake.org/cmake/help/v3.12/command/file.html#filesystem

This is however not portable (as Visual Studio or Xcode solutions don’t support the feature) so please only use that as a first approximation, else other people can have trouble building your CMake files under their IDE of choice!

Leave a Comment