Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • CMake CMake
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 4,106
    • Issues 4,106
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 16
    • Merge requests 16
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • External wiki
    • External wiki
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • CMakeCMake
  • CMakeCMake
  • Issues
  • #21986
Closed
Open
Issue created Mar 25, 2021 by Artur Ryt@R2RTContributor

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 May 09, 2021 by Craig Scott
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking