blob: acb5dbb7045f92a0d26b5244fd9b90ad66eaf2ae [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 Williamsc8a670e2025-07-08 07:07:28 -040080 input: [meson.project_source_root() / 'pimgen.py'],
Patrick Williamsaf2d2a12025-02-01 08:36:41 -050081 command: [
George Liua31da972022-04-14 14:07:18 +080082 prog_python,
Patrick Williamsc8a670e2025-07-08 07:07:28 -040083 '@INPUT0@',
Patrick Williamsaf2d2a12025-02-01 08:36:41 -050084 '-i',
85 ifacesdir,
86 '-d',
87 get_option('YAML_PATH'),
88 '-o',
89 meson.current_build_dir(),
90 '-b',
91 conf_data.get_unquoted('BUSNAME'),
92 'generate-cpp',
George Liua31da972022-04-14 14:07:18 +080093 ],
Konstantin Aladysheva927ffe2024-04-22 16:47:37 +030094 env: sdbusplus_python_env,
Patrick Williamsaf2d2a12025-02-01 08:36:41 -050095 output: 'generated.cpp',
96)
George Liua31da972022-04-14 14:07:18 +080097
98gen_serialization_hpp = custom_target(
99 'gen_serialization.hpp',
Patrick Williamsc8a670e2025-07-08 07:07:28 -0400100 input: [meson.project_source_root() / 'pimgen.py'],
Patrick Williamsaf2d2a12025-02-01 08:36:41 -0500101 command: [
George Liua31da972022-04-14 14:07:18 +0800102 prog_python,
Patrick Williamsc8a670e2025-07-08 07:07:28 -0400103 '@INPUT0@',
Patrick Williamsaf2d2a12025-02-01 08:36:41 -0500104 '-i',
105 ifacesdir,
106 '-d',
107 get_option('YAML_PATH'),
108 '-o',
109 meson.current_build_dir(),
110 '-b',
111 conf_data.get_unquoted('BUSNAME'),
112 'generate-serialization',
George Liua31da972022-04-14 14:07:18 +0800113 ],
Konstantin Aladysheva927ffe2024-04-22 16:47:37 +0300114 env: sdbusplus_python_env,
Patrick Williamsaf2d2a12025-02-01 08:36:41 -0500115 output: 'gen_serialization.hpp',
116)
George Liua31da972022-04-14 14:07:18 +0800117
118sources += [
119 generated_cpp,
120 gen_serialization_hpp,
121 'app.cpp',
122 'errors.cpp',
123 'functor.cpp',
124 'manager.cpp',
125]
126
127deps += [
128 cereal_dep,
129 phosphor_dbus_interfaces_dep,
130 phosphor_logging_dep,
131 sdbusplus_dep,
132]
133
134executable(
135 'phosphor-inventory',
136 sources,
137 implicit_include_directories: true,
138 dependencies: deps,
139 install: true,
140 install_dir: get_option('bindir'),
141)
George Liu07f94f02022-04-14 14:09:44 +0800142
143build_tests = get_option('tests')
Patrick Williamsfb3ceac2025-01-30 17:47:28 -0500144if build_tests.allowed()
George Liu07f94f02022-04-14 14:09:44 +0800145 subdir('test')
146endif