There is more

We mentioned that all generated files should be listed as dependencies of some target. However, we might be in a situation where we do not know this list of files, since it is determined by the scripts generating the files, depending on input that we provide to the configuration. In this case, we might be tempted to use file(GLOB ...) to collect generated files into a list (see https://cmake.org/cmake/help/v3.5/command/file.html).

However, remember that file(GLOB ...) is executed at configure time, whereas code generation happens at build time. Therefore, we may need an additional level of indirection, where we place the file(GLOB ...) command in a separate CMake script which we execute at using ${CMAKE_COMMAND} -P, in order ...

Get CMake Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.