1

When file(GLOB ...) is called, CMake applies regex to all files it can find. The question is whether it's done only on first cmake invocation, or every time?

In other words, does use of file(GLOB ...) slows down Makefiles regenration process? The same question can be applied to file(GLOB_RECURSE ...).

arrowd
  • 33,231
  • 8
  • 79
  • 110

1 Answers1

1

It's done every time (the results might be different, naturally).

Don't worry about it slowing you down. Build systems have to do a stat (or equivalent) on tens, hundreds, or thousands of files every invocation and a glob or two won't even show up as a blip.

Dietrich Epp
  • 205,541
  • 37
  • 345
  • 415
  • Still, can't it be optimized if CMake would remember directory's last change time and compare it on next run? – arrowd Jan 08 '12 at 09:37
  • @arrowdodger: That would require a complicated caching mechanism. The operating system already caches directory entries, so the IO time during a second invocation is minimal. You'd be throwing hours of work after a couple milliseconds of speedup at best. – Dietrich Epp Jan 08 '12 at 09:55
  • "It's done every time" is not the entire story. When the `CMakeLists.txt` file containing the `file(GLOB ..)` statement has not changed, it is likely that `cmake` will **not** rerun the file, and _a fortiori_ will not rerun the globbing. For a discussion of this problem, see [a thread](http://stackoverflow.com/questions/32411963/cmake-file-glob-is-not-evil) I just opened. – Joachim W Sep 05 '15 at 13:59