A really weird scenario was discussed on IRC recently: declare a C++ program by referencing only the main.cpp file, and have the build system add other source files by looking at the includes. For example:
  • main.cpp includes foo.h
  • foo.h has a corresponding foo.cpp file
  • foo.cpp includes a bar.h file
  • the file bar.h has a corresponding bar.cpp file
The program to be built declares main.cpp as unique source file, but the build system must detect and add the files foo.cpp and bar.cpp automatically.

The request was a bit surprising, because in large projects it is usually the norm to declare the source files explicitly to avoid confusing other developers. Even globs are used rarely in practice, as they conceal the exact source files to use.

For a single developer working on his project it probably does not matter anyhow, so an example was added in the playground area. Here is the link to the example.