blob: 248ef7fbed119536da62f72f17f3178bd4163af5 [file] [log] [blame]
George Liua31da972022-04-14 14:07:18 +08001project(
Patrick Williamsaf2d2a12025-02-01 08:36:41 -05002 'phosphor-inventory-manager',
3 'cpp',
4 version: '1.0.0',
Patrick Williamsc3eb3872023-07-12 11:15:18 -05005 meson_version: '>=1.1.1',
George Liua31da972022-04-14 14:07:18 +08006 default_options: [
7 'warning_level=3',
8 'werror=true',
Patrick Williamsc3eb3872023-07-12 11:15:18 -05009 'cpp_std=c++23',
George Liua31da972022-04-14 14:07:18 +080010 'buildtype=debugoptimized',
Patrick Williamsaf2d2a12025-02-01 08:36:41 -050011 ],
George Liua31da972022-04-14 14:07:18 +080012)
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')
Patrick Williamsaf2d2a12025-02-01 08:36:41 -050019conf_data.set_quoted(
20 'ASSOCIATIONS_FILE_PATH',
21 '/usr/share/phosphor-inventory-manager/associations.json',
22)
George Liua31da972022-04-14 14:07:18 +080023conf_data.set('CLASS_VERSION', 2)
Patrick Williamsba493592023-11-29 06:44:07 -060024conf_data.set('CREATE_ASSOCIATIONS', get_option('associations').allowed())
Patrick Williamsaf2d2a12025-02-01 08:36:41 -050025configure_file(output: 'config.h', configuration: conf_data)
George Liua31da972022-04-14 14:07:18 +080026
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,
Patrick Williamsaf2d2a12025-02-01 08:36:41 -050034 required: false,
35)
George Liua31da972022-04-14 14:07:18 +080036if not has_cereal
37 cereal_opts = import('cmake').subproject_options()
Patrick Williamsaf2d2a12025-02-01 08:36:41 -050038 cereal_opts.add_cmake_defines(
39 {'BUILD_TESTS': 'OFF', 'SKIP_PERFORMANCE_COMPARISON': 'ON'},
40 )
George Liua31da972022-04-14 14:07:18 +080041 cereal_proj = import('cmake').subproject(
42 'cereal',
43 options: cereal_opts,
Patrick Williamsaf2d2a12025-02-01 08:36:41 -050044 required: false,
45 )
George Liua31da972022-04-14 14:07:18 +080046 assert(cereal_proj.found(), 'cereal is required')
47 cereal_dep = cereal_proj.dependency('cereal')
48endif
49
Patrick Williamsaf2d2a12025-02-01 08:36:41 -050050sdbusplus_dep = dependency('sdbusplus', required: false)
George Liua31da972022-04-14 14:07:18 +080051phosphor_dbus_interfaces_dep = dependency('phosphor-dbus-interfaces')
52phosphor_logging_dep = dependency('phosphor-logging')
53
54prog_python = find_program('python3', required: true)
55
56sources = []
57deps = []
Patrick Williamsba493592023-11-29 06:44:07 -060058if get_option('associations').allowed()
Patrick Williamsaf2d2a12025-02-01 08:36:41 -050059 sources += ['association_manager.cpp']
Konstantin Aladyshev58a0c352024-04-22 17:10:47 +030060 nlohmann_json_dep = dependency('nlohmann_json', include_type: 'system')
Patrick Williamsaf2d2a12025-02-01 08:36:41 -050061 deps += [nlohmann_json_dep]
George Liua31da972022-04-14 14:07:18 +080062endif
63
64ifacesdir = get_option('IFACES_PATH')
65if ifacesdir == ''
Patrick Williams8a1ccdc2023-04-12 08:01:04 -050066 ifacesdir = phosphor_dbus_interfaces_dep.get_variable('yamldir')
George Liua31da972022-04-14 14:07:18 +080067endif
68
Konstantin Aladysheva927ffe2024-04-22 16:47:37 +030069sdbusplus_python_env = {}
70if not sdbusplus_dep.found()
71 sdbusplus_proj = subproject('sdbusplus')
72 sdbusplus_dep = sdbusplus_proj.get_variable('sdbusplus_dep')
Patrick Williamsaf2d2a12025-02-01 08:36:41 -050073 sdbusplus_python_env = {
74 'PYTHONPATH': meson.current_source_dir() / 'subprojects' / 'sdbusplus' / 'tools',
75 }
Konstantin Aladysheva927ffe2024-04-22 16:47:37 +030076endif
77
George Liua31da972022-04-14 14:07:18 +080078generated_cpp = custom_target(
79 'generated.cpp',
Patrick Williamsaf2d2a12025-02-01 08:36:41 -050080 command: [
George Liua31da972022-04-14 14:07:18 +080081 prog_python,
82 meson.project_source_root() + '/pimgen.py',
Patrick Williamsaf2d2a12025-02-01 08:36:41 -050083 '-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',
George Liua31da972022-04-14 14:07:18 +080092 ],
Konstantin Aladysheva927ffe2024-04-22 16:47:37 +030093 env: sdbusplus_python_env,
Patrick Williamsaf2d2a12025-02-01 08:36:41 -050094 output: 'generated.cpp',
95)
George Liua31da972022-04-14 14:07:18 +080096
97gen_serialization_hpp = custom_target(
98 'gen_serialization.hpp',
Patrick Williamsaf2d2a12025-02-01 08:36:41 -050099 command: [
George Liua31da972022-04-14 14:07:18 +0800100 prog_python,
101 meson.project_source_root() + '/pimgen.py',
Patrick Williamsaf2d2a12025-02-01 08:36:41 -0500102 '-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',
George Liua31da972022-04-14 14:07:18 +0800111 ],
Konstantin Aladysheva927ffe2024-04-22 16:47:37 +0300112 env: sdbusplus_python_env,
Patrick Williamsaf2d2a12025-02-01 08:36:41 -0500113 output: 'gen_serialization.hpp',
114)
George Liua31da972022-04-14 14:07:18 +0800115
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)
George Liu07f94f02022-04-14 14:09:44 +0800140
141build_tests = get_option('tests')
Patrick Williamsfb3ceac2025-01-30 17:47:28 -0500142if build_tests.allowed()
George Liu07f94f02022-04-14 14:09:44 +0800143 subdir('test')
144endif