Replacing a list of sources with an extraction from the target later

Sorry for a very rookie question so please flame away.
I had a list of sources that were passed around and I wanted to use target_sources instead so I can use more “elegant” genex processing of including various sources based on build options etc, instead of crude ifs. This works well if I only build the thing.
Now the problem I had overlooked is that this list of sources was also used as input to a custom script. I thought I could then just get the sources out of the target via a property and feed it to the script and it would look the same. Not so easy alas.
Eg one parameter to this script is a semicolon separated list of files which was previously created with separate_arguments(res UNIX_COMMAND "${some_sources};${other_sources}"). The output of this is a list of files with the semicolon escaped, i.e. file1\;file2.
Replacing this with separate_arguments(res UNIX_COMMAND "$<TARGET_PROPERTY:my_tgt,INTERFACE_SOURCES>;${other_sources}") gives the sources from the target as just semicolon separated (not escaped that is) and the sources from ${other_sources} (a conventional list) as a “escaped semicolon” separated string.

Is there some good way of forcing the genex to be evaluated before I call the script so I can post-process it into the required shape? Or is it perhaps better to use some other method than this unorthodox usage of separate_arguments to create an “escaped semicolon” separated string?
Or perhaps I should just keep the list of sources and avoid the genexing.

You can use file(GENERATE) and $<LIST:JOIN,...,...> to solve the generator expressions and convert it to space separated for use in a script.

Thanks. Would this entail then putting the list in this file and then reading it back up again to have it evaluated? If so I think that’s enough overhead so I’ll just stick with a non-genex list floating around :).

You wrote that. Maybe you can show how that file list interacts with your script?

Yes, so I just tried to say that if I have to change the interface to this script (to read from a file instead of taking a parameter) then I’ll refrain from the change. It’s a custom python script that takes a bunch of parameters, one of them being a semicolon-separated string of source file names.
A little pity that the genex style comes with a few rather hard-to-swallow differences and/or drawbacks from using temporary variables.

Have it take them as separate arguments. You can then just use unquoted CMake expansion (possibly with VERBATIM) to get proper empty element dropping and quoting.