0

According to Modern CMake: Do's and Don'ts and Why is cmake file GLOB evil? CMake's file(GLOB) should not be used to collect source files.

In our project environment, we have the guarantee that Ninja will be used as the build system. I also understand that CONFIGURE_DEPENDS comes with a small performance drop at build time. I can live with that.

Is it possible to use file(GLOB CONFIGURE_DEPENDS "*.cpp") with these constraints without problems or are there other points besides build system portability and performance that speak against GLOB?

Benjamin Buch
  • 4,752
  • 7
  • 28
  • 51
  • 1
    Not sure what kind of answer do you expect. The [referenced question](https://stackoverflow.com/questions/32411963/4821621) describes possible downsides of globbing. If you understand these downsides and think that you can handle them, then you are free to use globbing. – Tsyvarev Jun 07 '23 at 12:35
  • @Tsyvarev Modern CMake unfortunately does not list any reasons for the recommendation and the referenced answer does not specifically address Ninja. I hope for an answer that tells me that there are no limitations with Ninja or expect an answer that lists these limitations. – Benjamin Buch Jun 07 '23 at 12:54
  • 1
    "I hope for an answer that tells me that there are no limitations with Ninja" - Well, this is the valid reason. But I don't think anyone is able to give such definite answer. Just design your project to use `file(GLOB)` and after some time of approbations come back and share your experience as an answer. (Just to avoid misunderstanding: Nothing about implies that your question post is wrong. I find the post perfectly on-topic). – Tsyvarev Jun 07 '23 at 13:29
  • 2
    I'd expect the logic generated by cmake to be similar for all build systems resulting in the same drawbacks. Regardless of the quality of the generated project there's one thing that makes using `file(GLOB)` for this purpose a bit no-no for me: You won't be able to tell easily see the changes in the source file sets using the your source control software of your choice; you'd need to list the added/removed files and filter by a pattern to determine this. If you list the sources one per line in your `CMakeLists.txt`, you just need to do a diff... – fabian Jun 07 '23 at 15:29
  • @Tsyvarev That's true. It's the same problem as in the natural sciences: Experiments can always only falsify, but never finally confirm. If there are problems, I would learn them early from a reply and do not have to experiment myself. Thanks about your "avoid misunderstanding" note :-) – Benjamin Buch Jun 07 '23 at 15:33
  • @fabian The version control diff is a valid point. Can you please make that part of your comment an answer? I will not immediately accept it as the correct answer, but it is a good point and [many users do not read comments](https://meta.stackoverflow.com/a/294792/4821621). – Benjamin Buch Jun 07 '23 at 15:43
  • This whole discussion has been led in minute detail both in the question you link and [Is it better to specify source files with GLOB or each file individually in CMake?](https://stackoverflow.com/questions/1027247/is-it-better-to-specify-source-files-with-glob-or-each-file-individually-in-cmak) I don't see any merit in doing it again. – Friedrich Jun 07 '23 at 20:24

0 Answers0