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