Feature request: Support the opposite of PROPAGATE in `block`
I'm not sure how feasible that would be but it would be quite practical if the block
command supported the reverse behavior of PROPAGATE
, i.e. instead of scoping every variables and letting only a few pass through to the parent scope, let every variable pass through and scope only a few ones.
We often need to push/pop variables (which is not so easy to do), having a way to say "at the end of this block, restore those variables to the value they had when entering" would be very valuable.
The last occurrence I had was in a dependency provider: to mimick the behavior of find_package
, I wanted to set CMAKE_FIND_PACKAGE_NAME
, xxx_FIND_COMPONENTS
and xxx_FIND_VERSION
before including some module. However, find modules are sometimes recursive, so I was re-entering my dependency provider, overriding these variables which were no longer correct when returning to the original call. I couldn't use a block
because I wanted all variables set by modules to be available after the call, so I had to push/pop those variables manually.
Another example that comes to my mind is setting some variables for configuring a subproject, for instance setting ENABLE_TESTING
to OFF
before some add_subdirectory
, while retaining the original value.
I think block
could be used to implement this kind of things, but an alternative could be a PUSH/POP
option in set
.