11285115cSWilliam A. Kennington III# Copyright 2021 Google LLC
21285115cSWilliam A. Kennington III#
31285115cSWilliam A. Kennington III# Licensed under the Apache License, Version 2.0 (the "License");
41285115cSWilliam A. Kennington III# you may not use this file except in compliance with the License.
51285115cSWilliam A. Kennington III# You may obtain a copy of the License at
61285115cSWilliam A. Kennington III#
71285115cSWilliam A. Kennington III#      http://www.apache.org/licenses/LICENSE-2.0
81285115cSWilliam A. Kennington III#
91285115cSWilliam A. Kennington III# Unless required by applicable law or agreed to in writing, software
101285115cSWilliam A. Kennington III# distributed under the License is distributed on an "AS IS" BASIS,
111285115cSWilliam A. Kennington III# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
121285115cSWilliam A. Kennington III# See the License for the specific language governing permissions and
131285115cSWilliam A. Kennington III# limitations under the License.
141285115cSWilliam A. Kennington III
151285115cSWilliam A. Kennington IIIproject(
161285115cSWilliam A. Kennington III  'metrics-ipmi-blobs',
17*7f49370dSWilliam A. Kennington III  ['cpp', 'c'],
181285115cSWilliam A. Kennington III  version: '0.1',
191285115cSWilliam A. Kennington III  default_options: [
201285115cSWilliam A. Kennington III    'warning_level=3',
211285115cSWilliam A. Kennington III    'werror=true',
221dfe24eaSPatrick Williams    'cpp_std=c++23',
23*7f49370dSWilliam A. Kennington III    'c_std=c18',
241285115cSWilliam A. Kennington III    'tests=' + (meson.is_subproject() ? 'disabled' : 'auto'),
251285115cSWilliam A. Kennington III  ],
261285115cSWilliam A. Kennington III)
271285115cSWilliam A. Kennington III
28*7f49370dSWilliam A. Kennington IIInanopb = find_program('nanopb_generator.py', native: true, required: false)
29*7f49370dSWilliam A. Kennington IIIif not nanopb.found()
30*7f49370dSWilliam A. Kennington III  nanopb_opts = import('cmake').subproject_options()
31*7f49370dSWilliam A. Kennington III  nanopb_opts.add_cmake_defines({'BUILD_SHARED_LIBS': 'ON'})
32*7f49370dSWilliam A. Kennington III  nanopb_proj = import('cmake').subproject('nanopb', options: nanopb_opts)
33*7f49370dSWilliam A. Kennington III  nanopb = find_program(meson.global_source_root() + '/subprojects/nanopb/generator/nanopb_generator.py', native: true)
34*7f49370dSWilliam A. Kennington III  nanopb_dep = nanopb_proj.dependency('protobuf_nanopb')
35*7f49370dSWilliam A. Kennington IIIelse
36*7f49370dSWilliam A. Kennington III  nanopb_dep = meson.get_compiler('cpp').find_library('protobuf-nanopb')
37*7f49370dSWilliam A. Kennington IIIendif
381285115cSWilliam A. Kennington III
39*7f49370dSWilliam A. Kennington IIInanopb_kwargs = {
40*7f49370dSWilliam A. Kennington III  'output': [
41*7f49370dSWilliam A. Kennington III    '@BASENAME@.pb.n.h',
42*7f49370dSWilliam A. Kennington III    '@BASENAME@.pb.n.c',
43*7f49370dSWilliam A. Kennington III  ],
44*7f49370dSWilliam A. Kennington III  'command': [
45*7f49370dSWilliam A. Kennington III    nanopb,
46*7f49370dSWilliam A. Kennington III    '-q',
47*7f49370dSWilliam A. Kennington III    '-s', 'packed_struct:0',
48*7f49370dSWilliam A. Kennington III    '-H.n.h',
49*7f49370dSWilliam A. Kennington III    '-S.n.c',
50*7f49370dSWilliam A. Kennington III    '-I' + import('fs').relative_to(meson.current_source_dir(), meson.global_build_root()),
51*7f49370dSWilliam A. Kennington III    '-D' + import('fs').relative_to(meson.current_build_dir(), meson.global_build_root()),
52*7f49370dSWilliam A. Kennington III    '@INPUT@',
53*7f49370dSWilliam A. Kennington III  ],
54*7f49370dSWilliam A. Kennington III}
55*7f49370dSWilliam A. Kennington III
56*7f49370dSWilliam A. Kennington IIItgt = custom_target(
57*7f49370dSWilliam A. Kennington III  'metricblob.pb.n.hc',
58*7f49370dSWilliam A. Kennington III  input: 'metricblob.proto',
59*7f49370dSWilliam A. Kennington III  kwargs: nanopb_kwargs)
60*7f49370dSWilliam A. Kennington IIImetrics_nanopb_hdr = tgt[0]
61*7f49370dSWilliam A. Kennington IIImetrics_nanopb_src = tgt[1]
62*7f49370dSWilliam A. Kennington III
63*7f49370dSWilliam A. Kennington IIImetrics_nanopb_pre = declare_dependency(
64*7f49370dSWilliam A. Kennington III  include_directories: include_directories('.'),
65*7f49370dSWilliam A. Kennington III  sources: metrics_nanopb_hdr,
66*7f49370dSWilliam A. Kennington III  dependencies: [
67*7f49370dSWilliam A. Kennington III    nanopb_dep,
68*7f49370dSWilliam A. Kennington III  ])
69*7f49370dSWilliam A. Kennington III
70*7f49370dSWilliam A. Kennington IIImetrics_nanopb_lib = static_library(
71*7f49370dSWilliam A. Kennington III  'metrics_nanopb',
72*7f49370dSWilliam A. Kennington III  metrics_nanopb_src,
73*7f49370dSWilliam A. Kennington III  implicit_include_directories: false,
74*7f49370dSWilliam A. Kennington III  dependencies: metrics_nanopb_pre)
75*7f49370dSWilliam A. Kennington III
76*7f49370dSWilliam A. Kennington IIImetrics_nanopb_dep = declare_dependency(
77*7f49370dSWilliam A. Kennington III  dependencies: metrics_nanopb_pre,
78*7f49370dSWilliam A. Kennington III  link_with: metrics_nanopb_lib)
79*7f49370dSWilliam A. Kennington III
80*7f49370dSWilliam A. Kennington IIIpre = declare_dependency(
81*7f49370dSWilliam A. Kennington III  include_directories: include_directories('.'),
82*7f49370dSWilliam A. Kennington III  dependencies: [
83*7f49370dSWilliam A. Kennington III    metrics_nanopb_dep,
841285115cSWilliam A. Kennington III    dependency('phosphor-logging'),
851285115cSWilliam A. Kennington III    dependency('phosphor-ipmi-blobs'),
86b63d6314SMichael Shen    dependency('sdbusplus'),
87*7f49370dSWilliam A. Kennington III  ])
88b056df69SWilliam A. Kennington III
89b056df69SWilliam A. Kennington IIIlib = static_library(
90b056df69SWilliam A. Kennington III  'metricsblob',
91b056df69SWilliam A. Kennington III  'util.cpp',
92b056df69SWilliam A. Kennington III  'handler.cpp',
93b056df69SWilliam A. Kennington III  'metric.cpp',
941285115cSWilliam A. Kennington III  implicit_include_directories: false,
95*7f49370dSWilliam A. Kennington III  dependencies: pre)
961285115cSWilliam A. Kennington III
971285115cSWilliam A. Kennington IIIdep = declare_dependency(
98*7f49370dSWilliam A. Kennington III  dependencies: pre,
991285115cSWilliam A. Kennington III  link_with: lib)
1001285115cSWilliam A. Kennington III
1011285115cSWilliam A. Kennington IIIshared_module(
1021285115cSWilliam A. Kennington III  'metricsblob',
1031285115cSWilliam A. Kennington III  'main.cpp',
1041285115cSWilliam A. Kennington III  dependencies: dep,
1051285115cSWilliam A. Kennington III  implicit_include_directories: false,
1061285115cSWilliam A. Kennington III  install: true,
107548f3ad1SWilliam A. Kennington III  install_dir: get_option('libdir') / 'blob-ipmid')
1081285115cSWilliam A. Kennington III
1091285115cSWilliam A. Kennington IIIif not get_option('tests').disabled()
1101285115cSWilliam A. Kennington III  subdir('test')
1111285115cSWilliam A. Kennington IIIendif
112