Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support compile-only dependencies #7516

Open
Nikratio opened this issue Jul 30, 2020 · 10 comments
Open

Support compile-only dependencies #7516

Nikratio opened this issue Jul 30, 2020 · 10 comments
Assignees

Comments

@Nikratio
Copy link

I have a pkgconfig dependency for which I only need the headers - I do not want to link against the shared library. I tried to accomplish this with:

libfuse_dep = dependency('fuse3', version: '>=3.5.0')
fuse_headers = include_directories(libfuse_dep.get_pkgconfig_variable('includedir'))
# ...
executable('foo', 'foo.c', include_directories: [fuse_headers]

Unfortunately that did not work, the compile command did not include the include directory.

Bug or feature? I suspect that include_directories is not intended for absolute paths - but is there another solution?

$ meson --version
0.49.2
@dcbaker
Copy link
Member

dcbaker commented Jul 30, 2020

You want:

executable(
  'foo',
  'foo.c',
  dependencies : dep.partial_dependency(includes : true),
)

https://mesonbuild.com/Reference-manual.html#dependency-object

@dcbaker dcbaker closed this as completed Jul 30, 2020
@Nikratio
Copy link
Author

Thank you!

@Nikratio
Copy link
Author

Hmm. It doesn't seem to work:

executable('readahead', 'readahead.cpp', 'readahead_main.cpp', 'common.cpp',
           dependencies: [ boost_dep, libfuse_dep.partial_dependency(includes: true) ],
           install: false)

gives me:

$ ninja kernel_read_tracing/readahead
[1/3] Compiling C++ object 'kernel_re...@readahead@exe/readahead_main.cpp.o'.
FAILED: kernel_read_tracing/ece328b@@readahead@exe/readahead_main.cpp.o 
c++ -Ikernel_read_tracing/ece328b@@readahead@exe -Ikernel_read_tracing -I../kernel_read_tracing -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wnon-virtual-dtor -g -D_REENTRANT -DHAVE_CONFIG_H -D_GNU_SOURCE -Wall -Wextra -Wno-sign-compare -Wconversion -Wmissing-declarations -Wwrite-strings -Wno-unused-function -fno-strict-aliasing -Wno-unused-result  -MD -MQ 'kernel_read_tracing/ece328b@@readahead@exe/readahead_main.cpp.o' -MF 'kernel_read_tracing/ece328b@@readahead@exe/readahead_main.cpp.o.d' -o 'kernel_read_tracing/ece328b@@readahead@exe/readahead_main.cpp.o' -c ../kernel_read_tracing/readahead_main.cpp
In file included from ../kernel_read_tracing/readahead.hpp:10,
                 from ../kernel_read_tracing/readahead_main.cpp:13:
../kernel_read_tracing/../fs/readahead.hpp:19:10: fatal error: fuse_lowlevel.h: No such file or directory
 #include <fuse_lowlevel.h>
          ^~~~~~~~~~~~~~~~~
compilation terminated.
[...]

If I change this to:

executable('readahead', 'readahead.cpp', 'readahead_main.cpp', 'common.cpp',
           dependencies: [ boost_dep, libfuse_dep ],
           install: false)

then it works:

$ ninja -v kernel_read_tracing/readahead 
[0/1] /usr/bin/meson --internal regenerate /home/nikratio/consulting/valve/steamfs /home/nikratio/consulting/valve/steamfs/build --backend ninja
The Meson build system
Version: 0.49.2
[...]
[1/4] c++ -Ikernel_read_tracing/ece328b@@readahead@exe -Ikernel_read_tracing -I../kernel_read_tracing -I/usr/include/fuse3 -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wnon-virtual-dtor -g -D_REENTRANT -DHAVE_CONFIG_H -D_GNU_SOURCE -Wall -Wextra -Wno-sign-compare -Wconversion -Wmissing-declarations -Wwrite-strings -Wno-unused-function -fno-strict-aliasing -Wno-unused-result  -MD -MQ 'kernel_read_tracing/ece328b@@readahead@exe/readahead.cpp.o' -MF 'kernel_read_tracing/ece328b@@readahead@exe/readahead.cpp.o.d' -o 'kernel_read_tracing/ece328b@@readahead@exe/readahead.cpp.o' -c ../kernel_read_tracing/readahead.cpp

(this includes the -I/usr/include/fuse3)

Am I missing something?

@Nikratio
Copy link
Author

The problem is the same with Meson 0.55.0 (the reference manual says something about this not working right until v 0.50.1).

@dcbaker dcbaker reopened this Aug 1, 2020
@dcbaker
Copy link
Member

dcbaker commented Aug 1, 2020

This looks like it might be a bug. is your project available somewhere that I could test it?

@dcbaker dcbaker self-assigned this Aug 1, 2020
@Nikratio
Copy link
Author

Nikratio commented Aug 3, 2020

Here is a minimal example:

$ cat meson.build 
project('foo', ['cpp', 'c'], version: '0.1',
        meson_version: '>= 0.51',
        default_options: [ 'buildtype=debugoptimized',
                           'warning_level=2' ])
cc = meson.get_compiler('cpp')
libfuse_dep = dependency('fuse3', version: '>=3.5.0')
libfuse_headers = libfuse_dep.partial_dependency(includes: true)
executable('main', 'main.cpp', dependencies: libfuse_headers)

$ cat main.cpp 
#include <cstdio>
#include <fuse_lowlevel.h>

int main(int argc, char** argv) {
    printf("sizeof(fuse_ino_t): %d\n", (int) sizeof(fuse_ino_t));
    return 0;
}

Repro:

$ md build
$ cd build
$ meson ..
The Meson build system
Version: 0.55.0
Source dir: /home/nikratio/in-progress/mesonbug
Build dir: /home/nikratio/in-progress/mesonbug/build
Build type: native build
Project name: foo
Project version: 0.1
C compiler for the host machine: cc (gcc 8.3.0 "cc (Debian 8.3.0-6) 8.3.0")
C linker for the host machine: cc ld.bfd 2.31.1
C++ compiler for the host machine: c++ (gcc 8.3.0 "c++ (Debian 8.3.0-6) 8.3.0")
C++ linker for the host machine: c++ ld.bfd 2.31.1
Host machine cpu family: x86_64
Host machine cpu: x86_64
Found pkg-config: /usr/bin/pkg-config (0.29)
Run-time dependency fuse3 found: YES 3.7.0
Build targets in project: 1

Found ninja-1.8.2 at /usr/bin/ninja

$ ninja
[1/2] Compiling C++ object main.p/main.cpp.o
FAILED: main.p/main.cpp.o 
c++ -Imain.p -I. -I.. -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wnon-virtual-dtor -Wextra -O2 -g -MD -MQ main.p/main.cpp.o -MF main.p/main.cpp.o.d -o main.p/main.cpp.o -c ../main.cpp
../main.cpp:2:10: fatal error: fuse_lowlevel.h: No such file or directory
 #include <fuse_lowlevel.h>
          ^~~~~~~~~~~~~~~~~
compilation terminated.
ninja: build stopped: subcommand failed.

@Nikratio
Copy link
Author

Nikratio commented Aug 3, 2020

...and:

$ cat /usr/lib/x86_64-linux-gnu/pkgconfig/fuse3.pc 
prefix=/usr
libdir=${prefix}/lib/x86_64-linux-gnu
includedir=${prefix}/include

Name: fuse3
Description: Filesystem in Userspace
Version: 3.7.0
Libs: -L${libdir} -lfuse3 -lpthread
Libs.private: -ldl -pthread -lrt
Cflags: -I${includedir}/fuse3

@Nikratio
Copy link
Author

Nikratio commented Aug 3, 2020

libfuse also uses meson: https://github.com/libfuse/libfuse/blob/master/meson.build

@nirbheek nirbheek added this to the 0.55.1 milestone Aug 3, 2020
@dcbaker
Copy link
Member

dcbaker commented Aug 5, 2020

Not a regression, but a legitimate bug. The InternalDependency type has a separate field for includes, while ExternalDependencies store all compile args mixed together as a single list. I'm not exactly clear how to solve this as a whole. For pkg-config this is relatively easy since there's --cflags-only-I and --cflags-only-other. For other dependencies this is probably going to be painful.

In the short term using dep.partial_dependency(compile_args : true) will add the necessary -I flags.

sigh for bugs.

@dcbaker dcbaker removed this from the 0.55.1 milestone Aug 5, 2020
@dcbaker
Copy link
Member

dcbaker commented Aug 5, 2020

I'm removing this from the milestone. This is probably going to be a pretty invasive fix.

EBADBEEF added a commit to EBADBEEF/SRM that referenced this issue May 30, 2024
Without this, the examples can't find a libdrm include:
  ./SRMTypes.h:10:10: fatal error: drm_fourcc.h: No such file or directory

Also note that it seems 'compile_args' contains the gcc include paths,
not 'includes'. Some discussion here at
mesonbuild/meson#7516
EBADBEEF added a commit to EBADBEEF/SRM that referenced this issue May 30, 2024
Without this, the examples can't find a libdrm include:
  ./SRMTypes.h:10:10: fatal error: drm_fourcc.h: No such file or directory

Note that when using meson partial_dependency(), 'compile_args' contains
the gcc include paths, not 'includes'. Some discussion here at
mesonbuild/meson#7516
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants