idlmeson-build

Providing header dependency in meson


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)

Solution

  • 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],
        ...)