NickBroon
NickBroon

Reputation: 421

Using @BASENAME@ with install_dir of custom_target() in Meson

@BASENAME@ does not appear to work in the install_dir: parameter of the Meson custom_target() function.

protoc = find_program('protoc')

protobuf_sources= [
'apples.proto',
'oranges.proto',
'pears.proto'
]

protobuf_generated_go = []
foreach protobuf_definition : protobuf_sources

protobuf_generated_go += custom_target('go_' + protobuf_definition,
       command: [protoc, '--proto_path=@CURRENT_SOURCE_DIR@', '--go_out=paths=source_relative:@OUTDIR@', '@INPUT@'],
       input: protobuf_definition,
       output: '@[email protected]',
       install: true,
       install_dir: 'share/gocode/src/github.com/foo/bar/protobuf/go/@BASENAME@/'
)

endforeach

I need the generated files to end up in at directory based on the basename of the input file:

share/gocode/src/github.com/foo/bar/protobuf/go/apples/apples.pb.go
share/gocode/src/github.com/foo/bar/protobuf/go/oranges/oranges.pb.go
share/gocode/src/github.com/foo/bar/protobuf/go/pears/pears.pb.go

If I use @BASENAME@ in install_dir: to try and create the directory needed, it does not expand, and instead just creates a literal '@BASENAME@' directory.

share/gocode/src/github.com/foo/bar/protobuf/go/@BASENAME@/apples.pb.go
share/gocode/src/github.com/foo/bar/protobuf/go/@BASENAME@/oranges.pb.go
share/gocode/src/github.com/foo/bar/protobuf/go/@BASENAME@/pears.pb.go

How can the required installed directory location based on the basename be achieved? (just 3 files in the above example, I actually have 30+ files)

Upvotes: 1

Views: 474

Answers (1)

pmod
pmod

Reputation: 10997

Yes, it looks as there is no support for placeholders like BASENAME for install_dir parameter since this feature aims at file names not directories. But you can process iterator that is string in a loop:

foreach protobuf_definition : protobuf_sources
       ...

       install_dir: '.../go/@0@'.format(protobuf_definition.split('.')[0]) 

endforeach

Upvotes: 1

Related Questions