I’m hitting what seems to me like some unexpected behavior of the CMP0118 policy (found as part of trying to solve QTBUG-95200). My straw man test project is creating a library in the top level CMakeLists.txt file and doing something in a subdirectory that adds a generated .cpp file to it. After some experimentation, I’ve found that the global visibility of the source file’s GENERATED property depends on the value of the CMP0118 policy at the end of the directory scope in which the target was created. That’s problematic for SDK’s like Qt which generate code but are not in control of the policy setting at the end of the directory scope of the targets from user projects. What I’m finding is that this policy setting is essentially useless in these situations because I’m finding that I’m still having to manually propagate the GENERATED source file property to the target’s scope in order to guarantee the target knows the file is generated. This seems like a broken promise of what CMP0118 was supposed to do. I don’t know if there’s much we can do about it now though, since this policy was introduced in CMake 3.20.
I also note that the behavior of when the CMP0118 policy takes effect is not mentioned at all in the CMP0118 policy docs. The actual behavior was about third on the list of what I thought might be the way it works. The docs need to be updated to clearly spell out how and when the CMP0118 policy is used.
I also note further confusion as discussed in Unexpected behavior of the GENERATED source file property and CMP0118, which also highlights other scenarios where the intuitively expected behavior doesn’t match the actual behavior.
I’ve created this thread for initial discussion. It’s not clear whether there are bugs in the implementation, whether behavior changes are needed, or both. Regardless, doc updates will be required, but consensus is needed on what the behavior should actually be first.