Skip to content

Better support for globbing in generators #2709

@jhasse

Description

@jhasse

Globbing support in CMake:

file(GLOB SOURCES src/*.cpp )
add_executable(foo ${SOURCES})

This results in two problems:

  • When removing a .cpp file: Ninja fails because an input is missing.
  • When adding a .cpp file: Linker error because of missing symbols. Or even worse, incremental build succeeds, but clean build would fail.

There's a workaround:

file(GLOB SOURCES CONFIGURE_DEPENDS src/*.cpp )
add_executable(foo ${SOURCES})

But it's slow and causes other issues, e.g. #2507 and #2707.

I propose we implement a new attribute to the build manifest:

glob = src/*.cpp

Ninja would then rerun that rule if glob changes. The result of the glob wouldn't be available.

Also I would suggest that we only support * and nothing else. Also we're always case-sensitive.
This simplifies the implementation.
Of course that makes the implementation not correct 100% of the time (at least with CMake), but currently it works 0% of the time. And perfect is the enemy is good.

If someone wanted to match CMake's exact behavior he could still use CONFIGURE_DEPENDS. Also I think that globbing is only used by pragmatists anyway ;)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions