Let's assume I have a script that generates a set of source files forming a target I want to link against in a CMakeLists.txt
. If the file names are known to the latter then the usual add_custom_target()
and add_custom_command()
commands will make it possible to use the generated files as target sources.
Let's assume, though, that only the generator script knows the file names and locations. How can a target library be generated so that the parent CMakeLists.txt
can link against it without its knowing the actual file names?
Note that the dependency topic isn't in this question's scope as the script knows itself when to regenerate or not. It's not the finest use of CMake, but it's sufficient in this use case.
Idea #1
The script also generates a generated.cmake
file included by the parent one using include(generated.cmake)
. Problem: CMake doesn't find generated.cmake
as it isn't existing at configuration time.
Idea #2
Similar to idea #1, but the script is called with the execute_process()
so that generated.cmake
is present at configuration time. Problem: The script is not called anymore at subsequent builds, thus ignoring possible changes to its input.
Idea #3
The script passes back a list of targets and files that is somehow considered by the parent CMakeLists.txt
. So far I couldn't find a way to do so.