Adding a SUBDIRECTORIES_RECURSE directory property...


I’m looking into adding a DIRECTORY property SUBDIRECTORIES_RECURSE.
Currently I implemented this in cmake script, but getting the SUBDIRECTORIES property and then iterating over them to get all their SUBDIRECTORIES feels a bit much for the cmake language. Also it seems to be a bit slow.
I need this in order to collect all targets in all subdirs and then set some properties on each of them.

So I had a look at how the SUBDIRECTORIES property is implemented. So this is done in cmStateDirectory class. I have a bit a hard time figuring out how to add a recursive version there. I was assuming I would somehow see a vector of cmMakefile for each added subdirectory, but this is not the case.
Should I get the SUBDIRECTORY property and then get the cmMakefile for each of the returns dirs ? Or is there a more direct way to collect all the subdirs ?

Thanks for pointers

The cmState... infrastructure comes from a partially completed attempt at abstracting the CMake code model representation away from the cmake language implementation in cmMakefile.

From a cmStateDirectory you can iterate over its Children, and in each of those cmStateSnapshot instances, call .GetDirectory() to get a cmStateDirectory instance for each one, and then recurse into that.

And something to be careful of in the implementation: it is possible to add the same source subdirectory more than once, with different binary subdirectories. I’ve seen that in real projects. It’s rare, but in very specific circumstances it can be a valid approach (but not one I’d generally recommend if you have an alternative way of accomplishing your goal).

Here’s a first try: