William A. Kennington III | 7e14586 | 2024-02-01 15:56:33 -0800 | [diff] [blame^] | 1 | binaryblob_proto_kwargs = { |
| 2 | 'output': [ |
| 3 | '@BASENAME@.pb.h', |
| 4 | '@BASENAME@.pb.cc', |
Jie Yang | b988dbb | 2021-08-06 18:34:49 -0700 | [diff] [blame] | 5 | ], |
William A. Kennington III | 7e14586 | 2024-02-01 15:56:33 -0800 | [diff] [blame^] | 6 | '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 Yang | b988dbb | 2021-08-06 18:34:49 -0700 | [diff] [blame] | 11 | ], |
William A. Kennington III | 7e14586 | 2024-02-01 15:56:33 -0800 | [diff] [blame^] | 12 | } |
Willy Tu | baa8d40 | 2021-12-07 19:44:31 -0800 | [diff] [blame] | 13 | |
William A. Kennington III | 7e14586 | 2024-02-01 15:56:33 -0800 | [diff] [blame^] | 14 | nanopb = find_program('nanopb_generator.py', native: true, required: false) |
| 15 | if 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') |
| 21 | else |
| 22 | nanopb_dep = meson.get_compiler('cpp').find_library('protobuf-nanopb') |
| 23 | endif |
| 24 | |
| 25 | binaryblob_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 | |
| 42 | binaryblob_proto_src = [] |
| 43 | binaryblob_proto_hdr = [] |
| 44 | binaryblob_nanopb_src = [] |
| 45 | binaryblob_nanopb_hdr = [] |
| 46 | protos = [ |
| 47 | 'binaryblob', |
| 48 | ] |
| 49 | |
| 50 | foreach 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] |
| 65 | endforeach |
| 66 | |
| 67 | binaryblob_proto_pre = declare_dependency( |
Willy Tu | baa8d40 | 2021-12-07 19:44:31 -0800 | [diff] [blame] | 68 | include_directories: include_directories('.'), |
William A. Kennington III | 7e14586 | 2024-02-01 15:56:33 -0800 | [diff] [blame^] | 69 | sources: binaryblob_proto_hdr, |
| 70 | dependencies: [ |
| 71 | dependency('protobuf', disabler: true, required: get_option('tests')), |
| 72 | ]) |
Willy Tu | baa8d40 | 2021-12-07 19:44:31 -0800 | [diff] [blame] | 73 | |
William A. Kennington III | 7e14586 | 2024-02-01 15:56:33 -0800 | [diff] [blame^] | 74 | binaryblob_proto_lib = static_library( |
Willy Tu | baa8d40 | 2021-12-07 19:44:31 -0800 | [diff] [blame] | 75 | 'binaryblob_proto', |
William A. Kennington III | 7e14586 | 2024-02-01 15:56:33 -0800 | [diff] [blame^] | 76 | binaryblob_proto_src, |
Willy Tu | baa8d40 | 2021-12-07 19:44:31 -0800 | [diff] [blame] | 77 | implicit_include_directories: false, |
William A. Kennington III | 7e14586 | 2024-02-01 15:56:33 -0800 | [diff] [blame^] | 78 | dependencies: binaryblob_proto_pre, |
| 79 | build_by_default: false) |
Willy Tu | baa8d40 | 2021-12-07 19:44:31 -0800 | [diff] [blame] | 80 | |
William A. Kennington III | 7e14586 | 2024-02-01 15:56:33 -0800 | [diff] [blame^] | 81 | binaryblob_proto_dep = declare_dependency( |
| 82 | dependencies: binaryblob_proto_pre, |
| 83 | link_with: binaryblob_proto_lib) |
| 84 | |
| 85 | binaryblob_nanopb_pre = declare_dependency( |
| 86 | include_directories: include_directories('.'), |
| 87 | sources: binaryblob_nanopb_hdr, |
| 88 | dependencies: [ |
| 89 | nanopb_dep, |
| 90 | ]) |
| 91 | |
| 92 | binaryblob_nanopb_lib = static_library( |
| 93 | 'binaryblob_nanopb', |
| 94 | binaryblob_nanopb_src, |
| 95 | implicit_include_directories: false, |
| 96 | dependencies: binaryblob_nanopb_pre) |
| 97 | |
| 98 | binaryblob_nanopb_dep = declare_dependency( |
| 99 | dependencies: binaryblob_nanopb_pre, |
| 100 | link_with: binaryblob_nanopb_lib) |