2

I am using meson build system 0.49.0 on ubuntu 18.04. My project has some idl files and i want to include header files from another folder. How do I add provide include_directories in meson.

idl_compiler  = find_program('widl')

idl_generator = generator(idl_compiler,
  output       : [ '@BASENAME@.h' ],
  arguments    : [ '-h', '-o', '@OUTPUT@', '@INPUT@' ])

idl_files = [ .... ]
header_files = idl_generator.process(idl_files)
debonair
  • 2,505
  • 4
  • 33
  • 73

1 Answers1

0

You can add include directories directly to generator() arguments:

idl_generator = generator(idl_compiler,
  output       : '@BASENAME@.h',
  arguments    : [ 
        '-h',
        '-o', '@OUTPUT@', 
        '-I', '@0@/src/'.format(meson.current_source_dir()),
        '@INPUT@' ])

I added -I option which according to docs can be used to

Add a header search directory to path. Multiple search directories are allowed.

and used meson's string formatting together with meson's object method current_source_dir() which

returns a string to the current source directory.

Note also that output argument is string, not list.

Or, for example, if you have several of them and need to use them as dependency later, you can have array:

my_inc_dirs = ['.', 'include/xxx', 'include']

generate args for generator:

idl_gen_args = [ '-h', '-o', '@OUTPUT@', '@INPUT@' ]
foreach dir : my_inc_dirs
   idl_gen_args += ['-I', '@0@/@1@'.format(meson.current_source_dir(), dir)]
endforeach

idl_generator = generator(idl_compiler,
  output       : '@BASENAME@.h',
  arguments    : idl_gen_args)

and use later for dependency:

my_exe = executable(
    ...
    include_directories : [my_inc_dirs],
    ...)
pmod
  • 10,450
  • 1
  • 37
  • 50
  • Thank you.! Do you mind sharing the sources? I had a hard time to find this :/ – debonair Jun 07 '21 at 04:11
  • @debonair no I don't mind, you mean you'd like to share your sources? :) – pmod Jun 07 '21 at 06:46
  • or you mean meson sources? Anyway I hope the above is at least close to working because I haven't tested, just gave an idea :) – pmod Jun 07 '21 at 06:53
  • I mean where did you find this: `'-I', '@0@/@1@'.format(meson.current_source_dir()` and yes, it is working. – debonair Jun 07 '21 at 07:30