set_source_files_properties does not apply to targets added in higher level directories
This was described in some detail in the replies to issue #18399 (closed) . In the fix for that issue, the specific use case of the GENERATED property was addressed but not the general issue.
I realize this issue is discussed in the documentation with the line "Source file properties are visible only to targets added in the same directory", but I think this is an issue that affects the ability to modularize a project and it would be valuable to address it in a general manner. For our usage, we create targets at the top of a directory hierarchy, and then in subdirectories add files to that target. This keeps the names of source files close to the CMakeLists.txt file for them. However, this means that we cannot specify per-source file properties in those locations - we have to go up to the top level of the hierarchy to set those. We do not do this often, but it sometimes comes up during development to allow compile-time selection of experimental features based on option settings.
Here is a contrived example demonstrating the issue I am talking about in detail. If you enable setting the property in the toplevel file set_source_files_properties/src/CMakeLists.txt
then the property works fine and takes effect; but if you set it in the subdirectory in set_source_files_properties/src/subdir/CMakeLists.txt
it does not.
set_source_files_properties.tar.gz
In some cases we can work around this by making an OBJECT
library in the subdirectory and linking that to the main target, but that gets challenging if the compilation environment required is not easy to extract or re-specify (for example the top-level target links against multiple libraries with complex conditions that we should not have to reproduce in the subdirectory).