I don’t understand what the DIRECTORY scoping does to these commands. That’s sort of the preamble question.
The main question is if it’s possible to change/append the COMPILE_OPTIONS for all the source files in a given directory, without using a glob.
My ideal of “how it should work” would be
set_property(SOURCE DIRECTORY SomeSubdir APPEND PROPERTY COMPILE_OPTIONS -Wblah)
to enable warning blah on all the files that came in through SomeSubdir, with bonus points if it also applied to SomeSubdir/AddtlSubdir files too.
Also, there’s just one target in play here. All the files from all the subdirs get added to this one target. But my wish is to change how some of them get compiled. There’s a SO answer here that talks about doing it through the use of a glob. Is it possible without globbing?
I think I figured out the DIRECTORY param though experimentation. As the docs state, the properties on source files can only be set from the directory in which the target consuming that source file is defined. So if you want to set a source file property from another directory you need to specify the DIRECTORY that defined the target. And I guess TARGET_DIRECTORY is a helper that allows you to refer to the target, and not hardcode a path in DIRECTORY.
Coming back to my example, if I had SomeSubdir/foo.c, I could change the source properties from directory SomeSubdir/CMakeLists.txt if I had
Your assessment of the DIRECTORY keyword to set_property and set_source_files_properties is correct.
The directory-scoped command available is add_compile_options. This command adds compile options to all source files in the current directory and below. This command is syntactic sugar for set_property (DIRECTORY PROPERTY COMPILE_DEFINITIONS <opts...>)