George Liu | a31da97 | 2022-04-14 14:07:18 +0800 | [diff] [blame] | 1 | project( |
| 2 | 'phosphor-inventory-manager', 'cpp', |
| 3 | version : '1.0.0', |
| 4 | meson_version: '>=0.58.0', |
| 5 | default_options: [ |
| 6 | 'warning_level=3', |
| 7 | 'werror=true', |
| 8 | 'cpp_std=c++20', |
| 9 | 'buildtype=debugoptimized', |
| 10 | ] |
| 11 | ) |
| 12 | |
| 13 | conf_data = configuration_data() |
| 14 | conf_data.set_quoted('BUSNAME', 'xyz.openbmc_project.Inventory.Manager') |
| 15 | conf_data.set_quoted('INVENTORY_ROOT', '/xyz/openbmc_project/inventory') |
| 16 | conf_data.set_quoted('IFACE', 'xyz.openbmc_project.Inventory.Manager') |
| 17 | conf_data.set_quoted('PIM_PERSIST_PATH', '/var/lib/phosphor-inventory-manager') |
| 18 | conf_data.set_quoted('ASSOCIATIONS_FILE_PATH', '/usr/share/phosphor-inventory-manager/associations.json') |
| 19 | conf_data.set('CLASS_VERSION', 2) |
| 20 | conf_data.set('CREATE_ASSOCIATIONS', get_option('associations').enabled()) |
| 21 | configure_file(output: 'config.h', |
| 22 | configuration: conf_data |
| 23 | ) |
| 24 | |
| 25 | cpp = meson.get_compiler('cpp') |
| 26 | # Get Cereal dependency. |
| 27 | cereal_dep = dependency('cereal', required: false) |
| 28 | has_cereal = cpp.has_header_symbol( |
| 29 | 'cereal/cereal.hpp', |
| 30 | 'cereal::specialize', |
| 31 | dependencies: cereal_dep, |
| 32 | required: false) |
| 33 | if not has_cereal |
| 34 | cereal_opts = import('cmake').subproject_options() |
| 35 | cereal_opts.add_cmake_defines({'BUILD_TESTS': 'OFF'}) |
| 36 | cereal_proj = import('cmake').subproject( |
| 37 | 'cereal', |
| 38 | options: cereal_opts, |
| 39 | required: false) |
| 40 | assert(cereal_proj.found(), 'cereal is required') |
| 41 | cereal_dep = cereal_proj.dependency('cereal') |
| 42 | endif |
| 43 | |
| 44 | sdbusplus_dep = dependency('sdbusplus') |
| 45 | phosphor_dbus_interfaces_dep = dependency('phosphor-dbus-interfaces') |
| 46 | phosphor_logging_dep = dependency('phosphor-logging') |
| 47 | |
| 48 | prog_python = find_program('python3', required: true) |
| 49 | |
| 50 | sources = [] |
| 51 | deps = [] |
| 52 | if get_option('associations').enabled() |
| 53 | cpp = meson.get_compiler('cpp') |
| 54 | if cpp.has_header('nlohmann/json.hpp') |
| 55 | nlohmann_json_dep = declare_dependency() |
| 56 | else |
| 57 | subproject('nlohmann', required: false) |
| 58 | nlohmann_json_dep = declare_dependency( |
| 59 | include_directories: [ |
| 60 | 'subprojects/nlohmann/single_include', |
| 61 | 'subprojects/nlohmann/single_include/nlohmann', |
| 62 | ] |
| 63 | ) |
| 64 | endif |
| 65 | sources += [ |
| 66 | 'association_manager.cpp', |
| 67 | ] |
| 68 | deps += [ |
| 69 | nlohmann_json_dep, |
| 70 | ] |
| 71 | endif |
| 72 | |
| 73 | ifacesdir = get_option('IFACES_PATH') |
| 74 | if ifacesdir == '' |
| 75 | ifacesdir = phosphor_dbus_interfaces_dep.get_variable(pkgconfig: 'yamldir', internal: 'yamldir') |
| 76 | endif |
| 77 | |
| 78 | generated_cpp = custom_target( |
| 79 | 'generated.cpp', |
| 80 | command : [ |
| 81 | prog_python, |
| 82 | meson.project_source_root() + '/pimgen.py', |
| 83 | '-i', ifacesdir, |
| 84 | '-d', get_option('YAML_PATH'), |
| 85 | '-o', meson.current_build_dir(), |
Santosh Puranik | c4c9482 | 2023-01-05 22:43:46 +0530 | [diff] [blame] | 86 | '-b', conf_data.get_unquoted('BUSNAME'), |
George Liu | a31da97 | 2022-04-14 14:07:18 +0800 | [diff] [blame] | 87 | 'generate-cpp' |
| 88 | ], |
| 89 | output : 'generated.cpp') |
| 90 | |
| 91 | gen_serialization_hpp = custom_target( |
| 92 | 'gen_serialization.hpp', |
| 93 | command : [ |
| 94 | prog_python, |
| 95 | meson.project_source_root() + '/pimgen.py', |
| 96 | '-i', ifacesdir, |
| 97 | '-d', get_option('YAML_PATH'), |
| 98 | '-o', meson.current_build_dir(), |
Santosh Puranik | c4c9482 | 2023-01-05 22:43:46 +0530 | [diff] [blame] | 99 | '-b', conf_data.get_unquoted('BUSNAME'), |
George Liu | a31da97 | 2022-04-14 14:07:18 +0800 | [diff] [blame] | 100 | 'generate-serialization' |
| 101 | ], |
| 102 | output : 'gen_serialization.hpp') |
| 103 | |
| 104 | sources += [ |
| 105 | generated_cpp, |
| 106 | gen_serialization_hpp, |
| 107 | 'app.cpp', |
| 108 | 'errors.cpp', |
| 109 | 'functor.cpp', |
| 110 | 'manager.cpp', |
| 111 | ] |
| 112 | |
| 113 | deps += [ |
| 114 | cereal_dep, |
| 115 | phosphor_dbus_interfaces_dep, |
| 116 | phosphor_logging_dep, |
| 117 | sdbusplus_dep, |
| 118 | ] |
| 119 | |
| 120 | executable( |
| 121 | 'phosphor-inventory', |
| 122 | sources, |
| 123 | implicit_include_directories: true, |
| 124 | dependencies: deps, |
| 125 | install: true, |
| 126 | install_dir: get_option('bindir'), |
| 127 | ) |
George Liu | 07f94f0 | 2022-04-14 14:09:44 +0800 | [diff] [blame] | 128 | |
| 129 | build_tests = get_option('tests') |
| 130 | if not build_tests.disabled() |
| 131 | subdir('test') |
| 132 | endif |