question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cmake subproject dependencies not working

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:26 (17 by maintainers)

github_iconTop GitHub Comments

2reactions
mensindacommented, Dec 15, 2020

OK, I managed to get -uninstalled.pc files to work with #8104. However, the project still has some minor issues (somehow the include path for <gmodule.h> is missing + a tricky bug involving generated source files):

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

cmake = import('cmake')

cm_opts = cmake.subproject_options()
cm_opts.add_cmake_defines({'enable-ladspa': false})

fluidsynth_proj = cmake.subproject('fluidsynth', options: cm_opts)
meson build
ninja -C build subprojects/fluidsynth/gentables-install
ninja -C build
1reaction
kcgencommented, Dec 13, 2020

Maybe it would make sense to automatically add the meson-uninstalled directory to the pkg_config_path for at least cmake subprojects. Less manual intervention for the user trying to do the build.

Yes please 😃 Otherwise we’ll be wrapping meson in shell script to do this.

Ideally we could describe the dependencies of a cmake.subproject, something like:

subproj = cmake.subproject(
    'my_subproj',
    dependencies : [ 'glib-2.0', 'gthread-2.0'])

Where meson has previously been told how to resolve those dependencies:

glib_dep = dependency('glib-2.0', fallback : ['glib'])
gthread_dep = dependency('gthread-2.0', fallback : ['glib'])
  • If those are available in the system, then carry on.
  • If they’re provided via fallback, then add the meson-uninstalled directory for the respective dependency to the respective cmake-subproject’s pkg_config_path
Read more comments on GitHub >

github_iconTop Results From Across the Web

cmake subproject dependency - c++ - Stack Overflow
In project there is a CMakeLists.txt file: add_subdirectory(folder1) add_subdirectory(folder2). Subproject generator creates a required.cpp ...
Read more >
[CMake] Setting dependencies between libraries (cmake ...
Previous message: [CMake] Setting dependencies between libraries ... to use ADD_DEPENDENCIES(c a b) but it does not seem to work > either.
Read more >
CMake Dependency Management - That One Game Dev
But it would be way easier to start from public libraries that already solve these problems. Table of Contents. Before you begin; Subdirectories ......
Read more >
Dependencies - The Meson Build system
Meson's subprojects make it simple to use system dependencies when they are available and to build dependencies manually when they are not. To...
Read more >
Handling dependencies with CMake - Acarg
Second strategy: add_subdirectory · What happens if your dependency does not support CMake? · How does it work with transitive dependencies? · Every...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found