mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.39k stars 1.55k forks source link

no way to install headers produced by a generator #7368

Open nickbroon opened 4 years ago

nickbroon commented 4 years ago

Describe the bug There is no way to install headers produced by a generator

Perhaps an install and install_dir options (and some method to filter the output of the generator process) could support this.

To Reproduce

protobuf_sources = files(
        'Envelope.proto  Message.proto Data.proto'
)

protoc = find_program('protoc')

protobuf_c_generator = generator(protoc,
        output: ['@BASENAME@.pb-c.c', '@BASENAME@.pb-c.h'],
        arguments: ['--proto_path=@CURRENT_SOURCE_DIR@', '--c_out=@BUILD_DIR@', '@INPUT@']
)

generated_c = protobuf_c_generator.process(protobuf_sources)

proto_c_dep = dependency('libprotobuf-c')

sample_proto_library = shared_library(
        'sample-proto',
        sources: [generated_c],
        dependencies: [proto_c_dep],
        install: true,
        soversion: 1
)

install_headers('Envelope.pb-c.h', 'Message.pb-c.h', 'Data.pb-c.h' subdir: 'sample/proto')

Expected behavior

Some way to install Envelope.pb-c.h and Message.pb-c.h produced by the generator. (But not Envelope.pb-c.c nor Message.pb-c.c)

system parameters meson 0.49.2 ninja 1.8.2

mnkp commented 3 years ago

Looks like duplicate of #3206

nickbroon commented 3 years ago

The alternative approach I've also used is:

protobuf_sources = [
        'Envelope.proto  Message.proto Data.proto'
]

protoc = find_program('protoc')

generated_c = []
foreach protobuf_definition : protobuf_sources
        generated_c += custom_target('c_' + protobuf_definition,
        command: [protoc, '--proto_path=@CURRENT_SOURCE_DIR@', '--c_out=@OUTDIR@', '@INPUT@'],
        input: protobuf_definition,
        output: ['@BASENAME@.pb-c.c', '@BASENAME@.pb-c.h'],
                install: true,
                install_dir: [false, get_option('includedir') / 'sample' / 'protobuf']
        )
endforeach

proto_c_dep = dependency('libprotobuf-c')

sample_proto_library = shared_library(
        'sample-proto',
        sources: [generated_c],
        dependencies: [proto_c_dep],
        install: true,
        soversion: 1
)

Both the original example using a generator but having to list all the output in a direct call to install_header afterwards, and this example using custom_target but inside a foreach loop list of names instead of 'files', seem sub optimal and not really meson idiomatic.