Generate lots of files and folder @ build-time

Hi All,

I’m currently refactoring an old CMake infrastructure which used to
generate huge amount of source folders and source files @cmake-config
step using several different scripts. I have to move them into the build
step to be able to maintain dependencies between them better.
Furthermore there are several input files for those scripts available
at earliest @cmake-gen step. Thus using ‘execute_process’ is not an
option anymore.

The problem is I never know how many and which files are really
generated. The process to deduce those is just to complex to deal with
it in the config step.

The question is now: could I create an ‘add_executable’ or ‘add_library’
statement without knowing all the relevant source files in advance, yet
they aren’t available.

Would it help if I rewrite my generator scripts and force them to write
all the output into one single folder?
Bit even if, how could I glob them?
Is there a way to define something like:
add_executable(myExec “somePath/*”)
This would help a lot.

Thanks in advance for your help

could I create an add_executable or add_library statement without knowing all the relevant source files in advance

The full list of sources needs to be known when CMake runs, though the actual files can be generated at build time.

To generate a bunch of sources not known ahead of time and then use them to build a project, you’ll need to configure build rules to generate the files first and then run CMake on a new inner project at build time. The ExternalProject module may help with that. The inner project will need to be given the list of sources in a generated .cmake file that it includes (or could use file(GLOB) but we do not recommend that in general for collecting source lists).

This is tip looks promising. I’ll give it a shot today.