mesonbuild / mesonbuild/meson

cmake subproject dependencies not working

Open
#8,089 27 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement module:cmake subprojects/wraps
Dominant language
Python
Stars
6.6k
Forks
1.9k
Avg merge
2d 6h
Merged PRs (30d)
33

Description

Describe the bug
DOSBox Staging is transitioning to meson. We depend on FluidSynth (2.x, a CMake project), which in turn depends on Glib-2.0 (a Meson project), both of which aren't guaranteed to exist on all our supported platforms - so we've written Meson wraps for them.

When both FluidSynth and Glib do not exist on a system, the fluidsynth subproject is not being provided the glib-2.0 dependencies generated from the glib subproject.

Here's how it plays out sequentially if Glib doesn't exist:

glib_dep = dependency('glib-2.0', fallback : ['glib'])
gthread_dep = dependency('gthread-2.0', fallback : ['glib'])

All goes well -- Meson falls back to the glib subproject wrap and reports the dependencies are found:

Run-time dependency glib-2.0 found: NO (tried pkgconfig and cmake)
Looking for a fallback subproject for the dependency glib-2.0
|Executing subproject glib method meson 
|Project name: glib
|Project version: 2.67.1
... 
Dependency glib-2.0 found: YES 2.67.1 (overridden)
Dependency gthread-2.0 found: YES 2.67.1 (overridden)

Great - so Meson is taking care of that for us. Onto FluidSynth..

Executing subproject fluidsynth method cmake 
||Configuring the build directory with CMake version 3.16.3
||-- Checking for modules 'glib-2.0>=2.6.5;gthread-2.0>=2.6.5'
||--   No package 'glib-2.0' found
||--   Package 'glib-2.0', required by 'gthread-2.0', not found
||  A required package was not found

So despite Meson telling us it has control of glib-2.0 found: YES 2.67.1 and gthread-2.0 found: YES 2.67.1, it's unable to provide them to the cmake subproject, despite FluidSynth being configured it with these dependencies:

fluidsynth_proj = cmake.subproject('fluidsynth')
fluidsynth_proj.dependency('glib-2.0', fallback: ['glib'])
fluidsynth_proj.dependency('gthread-2.0', fallback: ['glib'])

fluidsynth_dep = fluidsynth_proj.dependency(
  'fluidsynth',
  version : '>=2',
  fallback: ['fluidsynth'],
  dependencies: ['glib-2.0', 'gthread-2.0']
)

To Reproduce

See attached tarball consisting of tiny 19-line meson.build and two wraps to reproduce the issue.

cmake-subproject-deps.tar.gz

Note: To have Meson fallback to using the Glib subproject, you will need to hide your system's existing Glib library. You can do this temporarily by moving glib's pkg-config (.pc) file, such as:

cd /usr/lib/x86_64-linux-gnu/pkgconfig && sudo mv glib-2.0.pc glib-2.0.pc-bak

Expected behavior

If Meson says it has a given dependency (via system discovery or subproject fallback), then subsequently using that dependency (such as in other subprojects) should "just work".

I guess this means that Meson doesn't know how to provide dependencies to cmake.subprojects?

system parameters

  • Native Ubuntu 20.10 installation
  • Python 3.8.6
  • Meson 0.56.0
  • Ninja 1.10.0.git.kitware.jobserver-1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by unpacking the attached cmake-subproject-deps.tar.gz and running its 19-line meson.build with the two wraps under the reported Meson 0.56.0 environment. Trace how the glib and gthread dependencies found through the glib subproject are passed to the fluidsynth CMake subproject. Done means the reproduction configures successfully when both system dependencies are absent and the expected dependencies are available to the CMake subproject.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, python
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.