The CMake configure_file
command can be used to create concrete files from templates. Calling configure_file(foo.h.in foo.h)
will generate the foo.h
file which did not existed prior to running cmake
.
Yet, it's not marked with the GENERATED
property. Calling get_source_file_property(is_generated foo.h GENERATED)
returns NOTFOUND
.
What is the rational behind this behavior that I'm missing?
CodePudding user response:
According to documentation, the purpose of a source file's property GENERATED is to prevent checking of the file during configuration process:
This information is then used to exempt the file from any existence or validity checks.
E.g. add_executable
command could emit an error if one of its source files does not exist at the time of configuration. This check could reveal problems before one attempts to build the configured project.
But marked with GENERATED
file is not checked until the build stage.
Because configure_file
creates the file immediately, it is perfectly correct to check the file's existence when this file is used for e.g. add_executable
call.
That is, there is no reason to mark this file as GENERATED.
The first paragraph in the property's documentation
Is this source file generated as part of the build or CMake process.
looks controversial, as configure_file
creates the file during the "CMake process".
Probably, by noting "CMake process" they wanted to fit that file(GENERATE)
actually sets that property. But there is fundamental difference between configure_file
and file(GENERATE)
about a file's generation time:
configure_file
creates the file immediately, before CMake would execute the next command inCMakeLists.txt
.- but
file(GENERATE)
creates the file only at the end of configuration process, after allCMakeLists.txt
are processed.