Skip to content

Introduce SOURCE_FILE_PROPERTY generator expression that operates on properties of source files

Generator expression that works only on subset of source files could be really useful in case of generated files.

I found one use case, where I wanted to increase warnings level for target's source files, but disable them for all generated files (with GENERATED property).

It could be easily done, if there was mechanism that understood $<$<SOURCE_FILE_PROPERTY:GENERATED>:/W0> syntax.

For my case, where generated file names are unknown in advance (Qt's AUTOMOC magic), I'd love to be able to attach such genex both for targets, as well as for source files.

Proposed API:

# ... somehow generate b.cpp
add_library(library a.cpp b.cpp)
# should propagate from target to source files
target_compile_options(library PRIVATE $<$<SOURCE_FILE_PROPERTY:GENERATED>:/W0>) # disables warnings for b.cpp

For consistency, this genex could work when directly applied to source properties as well:

# but should also allow to directly manage properties of source files
set_source_files_properties(a.cpp PROPERTIES COMPILE_DEFINITIONS $<$<SOURCE_FILE_PROPERTY:GENERATED>:GENERATED>) # adds -DGENERATED as compile definition

I suppose it would also allow to customize source files based on file extension (LOCATION) or language (LANGUAGE). I probably could find some use for LABELS property as well.

Related discussion: https://discourse.cmake.org/t/qt-autogen-source-files-custom-compilation-flags/3002 @ben.boeckel

Edited by Craig Scott
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information