Allow passing multiple targets to target_compile_options, target_compile_definitions etc.
In modern CMake, we set target-level properties rather than setting CMake-file-scope/directory-scope properties; and this is the case particularly for compile definitions; for example, we use target_compile_options()
instead of COMPILE_OPTIONS
. However - target_compile_options()
and similar functions only apply to a single target a time, while we often want to apply the same options, definitions etc. to multiple targets.
This can be overcome by creating a list of targets and looping over them, invoking target_compile_options()
(and other commands) for each of them; but - other commands, like target_link_libraries()
for example, are willing to accept multiple targets, or list of targets, from the get-go. It is more convenient for that to be possible.
So, I ask that the commands:
target_include_directories()
target_compile_options()
target_compile_definitions()
target_compile_features()
target_link_directories()
target_link_options()
target_sources()
target_precompile_headers()
and any other similar command, be modified to support specifying multiple targets.
Inspired by this SO question reaching 10,000 views.