1# Copyright 2021 Google LLC 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15project( 16 'metrics-ipmi-blobs', 17 ['cpp', 'c'], 18 version: '0.1', 19 default_options: [ 20 'warning_level=3', 21 'werror=true', 22 'cpp_std=c++23', 23 'c_std=c18', 24 'tests=' + (meson.is_subproject() ? 'disabled' : 'auto'), 25 ], 26) 27 28nanopb = find_program('nanopb_generator.py', native: true, required: false) 29if not nanopb.found() 30 nanopb_opts = import('cmake').subproject_options() 31 nanopb_opts.add_cmake_defines({'BUILD_SHARED_LIBS': 'ON'}) 32 nanopb_proj = import('cmake').subproject('nanopb', options: nanopb_opts) 33 nanopb = find_program(meson.global_source_root() + '/subprojects/nanopb/generator/nanopb_generator.py', native: true) 34 nanopb_dep = nanopb_proj.dependency('protobuf_nanopb') 35else 36 nanopb_dep = meson.get_compiler('cpp').find_library('protobuf-nanopb') 37endif 38 39nanopb_kwargs = { 40 'output': [ 41 '@BASENAME@.pb.n.h', 42 '@BASENAME@.pb.n.c', 43 ], 44 'command': [ 45 nanopb, 46 '-q', 47 '-s', 'packed_struct:0', 48 '-H.n.h', 49 '-S.n.c', 50 '-I' + import('fs').relative_to(meson.current_source_dir(), meson.global_build_root()), 51 '-D' + import('fs').relative_to(meson.current_build_dir(), meson.global_build_root()), 52 '@INPUT@', 53 ], 54} 55 56tgt = custom_target( 57 'metricblob.pb.n.hc', 58 input: 'metricblob.proto', 59 kwargs: nanopb_kwargs) 60metrics_nanopb_hdr = tgt[0] 61metrics_nanopb_src = tgt[1] 62 63metrics_nanopb_pre = declare_dependency( 64 include_directories: include_directories('.'), 65 sources: metrics_nanopb_hdr, 66 dependencies: [ 67 nanopb_dep, 68 ]) 69 70metrics_nanopb_lib = static_library( 71 'metrics_nanopb', 72 metrics_nanopb_src, 73 implicit_include_directories: false, 74 dependencies: metrics_nanopb_pre) 75 76metrics_nanopb_dep = declare_dependency( 77 dependencies: metrics_nanopb_pre, 78 link_with: metrics_nanopb_lib) 79 80pre = declare_dependency( 81 include_directories: include_directories('.'), 82 dependencies: [ 83 metrics_nanopb_dep, 84 dependency('phosphor-logging'), 85 dependency('phosphor-ipmi-blobs'), 86 dependency('sdbusplus'), 87 ]) 88 89lib = static_library( 90 'metricsblob', 91 'util.cpp', 92 'handler.cpp', 93 'metric.cpp', 94 implicit_include_directories: false, 95 dependencies: pre) 96 97dep = declare_dependency( 98 dependencies: pre, 99 link_with: lib) 100 101shared_module( 102 'metricsblob', 103 'main.cpp', 104 dependencies: dep, 105 implicit_include_directories: false, 106 install: true, 107 install_dir: get_option('libdir') / 'blob-ipmid') 108 109if not get_option('tests').disabled() 110 subdir('test') 111endif 112