It's not obvious or documented that you can't "add" include directories
- Dominant language
- Python
- Stars
- 6.6k
- Forks
- 1.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 33
Description
Using Meson 0.55.0 under a Python 3.7.3 virtualenv on Ubuntu 20.04.
This style of `meson.build` works:
```meson
ui_includes = include_directories(...)
proto_includes = include_directories(...)
other_includes = include_directories(...)
all_includes = []
all_includes += ui_includes
all_includes += proto_includes
all_includes += other_includes
executable(
'program',
sources : ui_sources + proto_sources + other_sources,
include_directories : all_includes,
)
```
This doesn't work:
```meson
ui_includes = include_directories(...)
proto_includes = include_directories(...)
other_includes = include_directories(...)
executable(
'program',
sources : ui_sources + proto_sources + other_sources,
include_directories : ui_includes + proto_includes + other_includes,
)
```
It fails with `ERROR: Invalid use of addition: unsupported operand type(s) for +: 'IncludeDirsHolder' and 'IncludeDirsHolder'`.
(Real, runnable examples follow below.)
This is made more confusing by the facts that:
- `IncludeDirsHolder` is not documented as a built-in object or returned object in the docs.
- This constraint is not mentioned in the docs for `include_directories()`.
- The same pattern works for source files.
I had to Google a variety of terms ("meson includedirsholder" ... "concatenation"? "add"? "direct sum" aha!) before I came across a post providing the solution above.
Expected behaviour: if `+=` with the type on an empty list works, I'd expect `+` to work between two objects of the same type.
Real example, working:
```meson
project('tmp', 'c')
ui_includes = include_directories()
proto_includes = include_directories()
other_includes = include_directories()
all_includes = []
all_includes += ui_includes
all_includes += proto_includes
all_includes += other_includes
executable(
'program',
sources : [],
include_directories : all_includes,
)
```
Real example, not working:
```meson
project('tmp', 'c')
ui_includes = include_directories()
proto_includes = include_directories()
other_includes = include_directories()
executable(
'program',
sources : [],
include_directories : ui_includes + proto_includes + other_includes,
)
```
Contributor guide
Research direction
Locate the documentation for include_directories() and the IncludeDirsHolder object, then compare how list concatenation and += behavior are described for include directories and source files. Document the restriction on using + between IncludeDirsHolder objects and include the working list-based workaround shown in the issue.
Written by the indexing model from the issue text.
Assessment
- Domain
- build-system, documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 40/100