mesonbuild / mesonbuild/meson

Relative paths for include_directories is enforced on Ubuntu but not on Windows

Open
#8,640 4 comments 2 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
6.6k
Forks
1.9k
Avg merge
2d 6h
Merged PRs (30d)
33

Description

I have a large collection of 3rd party libraries that various parts of my project need to link to. I've been doing this like so:

At the top level of my project I have an absolute path to the collection of libraries: `DEPS_REPO = join_paths(meson.current_source_dir(), '../../../3rdPartyRepo)`

Having this as an absolute path is nice since:
- `find_library` requires an absolute path for its `dirs` argument.
- The path remains valid even when using it from nested subdirectories in my project.

I then do this:
```
SDK_dir = join_paths(DEPS_REPO, 'path_to_specific_sdk')
SDK_lib = meson.compiler('cpp').find_library('sdklibname', dirs: join_paths(SDK_dir, 'lib64'), static: true)
SDK_inc = include_directories(join_paths(SDK_dir, 'include'))
library('MyDriver', sources, include_directories: SDK_inc, dependencies: SDK_dep, install: true)
```

This works fine for me on Windows with Meson 0.57.1, however with the same version of Meson on Ubuntu 20.04 I get `ERROR: Tried to form an absolute path to a source dir. You should not do that but use relative paths instead.`

Aside from the issue of getting inconsistent behavior between OS's I don't understand why these restrictions are in place. It would be nice if both `include_directories` and `find_library(..., dir:` would allow the usage of both relative and absolute paths.

Is there an entirely different way that I should go about this? I had considered using `declare_dependency` since it would allow me to bundle the linker path and the include directory into a single dependency object but it seemed like this was going against the intended behavior since these aren't dependencies which will be used in other parts of the project, as soon as they are created they are passed to `library(..., dependencies:` and never used again.

As final note, I think it would be really useful if the "FS" module had functionality similar to Python's `os.path.abspath` and `os.path.relpath` for converting paths as needed.

Contributor guide

Open the contributing guide

Research direction

Start by tracing the path validation used by include_directories and the dirs argument to find_library, then reproduce the example on Ubuntu 20.04 and Windows with Meson 0.57.1. Done should mean the cross-platform behavior is consistent, with the supported handling of absolute and relative paths made clear.

Written by the indexing model from the issue text.

Assessment

Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.