blob: 452114c7f165003e1815e3c4fc0303b53aaef1e0 [file] [log] [blame]
William A. Kennington III7e145862024-02-01 15:56:33 -08001binaryblob_proto_kwargs = {
2 'output': [
3 '@BASENAME@.pb.h',
4 '@BASENAME@.pb.cc',
Jie Yangb988dbb2021-08-06 18:34:49 -07005 ],
William A. Kennington III7e145862024-02-01 15:56:33 -08006 'command': [
7 find_program('protoc', native: true, disabler: true, required: get_option('tests')),
8 '-I@SOURCE_ROOT@/proto',
9 '--cpp_out=@BUILD_ROOT@/proto',
10 '@INPUT@',
Jie Yangb988dbb2021-08-06 18:34:49 -070011 ],
William A. Kennington III7e145862024-02-01 15:56:33 -080012}
Willy Tubaa8d402021-12-07 19:44:31 -080013
William A. Kennington III7e145862024-02-01 15:56:33 -080014nanopb = find_program('nanopb_generator.py', native: true, required: false)
15if not nanopb.found()
16 nanopb_opts = import('cmake').subproject_options()
17 nanopb_opts.add_cmake_defines({'BUILD_SHARED_LIBS': 'ON'})
18 nanopb_proj = import('cmake').subproject('nanopb', options: nanopb_opts)
19 nanopb = find_program(meson.global_source_root() + '/subprojects/nanopb/generator/nanopb_generator.py', native: true)
20 nanopb_dep = nanopb_proj.dependency('protobuf_nanopb')
21else
22 nanopb_dep = meson.get_compiler('cpp').find_library('protobuf-nanopb')
23endif
24
25binaryblob_nanopb_kwargs = {
26 'output': [
27 '@BASENAME@.pb.n.h',
28 '@BASENAME@.pb.n.c',
29 ],
30 'command': [
31 nanopb,
32 '-q',
33 '-s', 'packed_struct:0',
34 '-H.n.h',
35 '-S.n.c',
36 '-I@SOURCE_ROOT@/proto',
37 '-D@BUILD_ROOT@/proto',
38 '@INPUT@',
39 ],
40}
41
42binaryblob_proto_src = []
43binaryblob_proto_hdr = []
44binaryblob_nanopb_src = []
45binaryblob_nanopb_hdr = []
46protos = [
47 'binaryblob',
48]
49
50foreach proto : protos
51 tgt = custom_target(
52 proto + '.pb.hcc',
53 input: proto + '.proto',
54 kwargs: binaryblob_proto_kwargs,
55 build_by_default: false)
56 binaryblob_proto_hdr += tgt[0]
57 binaryblob_proto_src += tgt[1]
58
59 tgt = custom_target(
60 proto + '.pb.n.hc',
61 input: proto + '.proto',
62 kwargs: binaryblob_nanopb_kwargs)
63 binaryblob_nanopb_hdr += tgt[0]
64 binaryblob_nanopb_src += tgt[1]
65endforeach
66
67binaryblob_proto_pre = declare_dependency(
Willy Tubaa8d402021-12-07 19:44:31 -080068 include_directories: include_directories('.'),
William A. Kennington III7e145862024-02-01 15:56:33 -080069 sources: binaryblob_proto_hdr,
70 dependencies: [
71 dependency('protobuf', disabler: true, required: get_option('tests')),
72 ])
Willy Tubaa8d402021-12-07 19:44:31 -080073
William A. Kennington III7e145862024-02-01 15:56:33 -080074binaryblob_proto_lib = static_library(
Willy Tubaa8d402021-12-07 19:44:31 -080075 'binaryblob_proto',
William A. Kennington III7e145862024-02-01 15:56:33 -080076 binaryblob_proto_src,
Willy Tubaa8d402021-12-07 19:44:31 -080077 implicit_include_directories: false,
William A. Kennington III7e145862024-02-01 15:56:33 -080078 dependencies: binaryblob_proto_pre,
79 build_by_default: false)
Willy Tubaa8d402021-12-07 19:44:31 -080080
William A. Kennington III7e145862024-02-01 15:56:33 -080081binaryblob_proto_dep = declare_dependency(
82 dependencies: binaryblob_proto_pre,
83 link_with: binaryblob_proto_lib)
84
85binaryblob_nanopb_pre = declare_dependency(
86 include_directories: include_directories('.'),
87 sources: binaryblob_nanopb_hdr,
88 dependencies: [
89 nanopb_dep,
90 ])
91
92binaryblob_nanopb_lib = static_library(
93 'binaryblob_nanopb',
94 binaryblob_nanopb_src,
95 implicit_include_directories: false,
96 dependencies: binaryblob_nanopb_pre)
97
98binaryblob_nanopb_dep = declare_dependency(
99 dependencies: binaryblob_nanopb_pre,
100 link_with: binaryblob_nanopb_lib)