blob: 02c13dd6c9911b68fa6911397066d85f799dd5e7 [file] [log] [blame]
Andrew Geisslerf2454102019-12-06 15:14:08 -06001project(
2 'phosphor-state-manager',
3 'cpp',
Patrick Williams71e399d2025-02-01 08:36:54 -05004 default_options: ['warning_level=3', 'werror=true', 'cpp_std=c++23'],
Patrick Williams9beba5a2023-07-12 11:15:24 -05005 meson_version: '>=1.1.1',
Andrew Geisslerf2454102019-12-06 15:14:08 -06006 license: 'Apache-2.0',
7 version: '0.1',
8)
Patrick Williamsf8d5f3e2022-04-05 15:51:15 -05009cpp = meson.get_compiler('cpp')
Andrew Geisslerf2454102019-12-06 15:14:08 -060010
Thang Tranba2241c2021-10-26 17:47:09 +070011build_host_gpios = get_option('host-gpios')
12
Andrew Geisslerf2454102019-12-06 15:14:08 -060013conf = configuration_data()
Patrick Williams71e399d2025-02-01 08:36:54 -050014conf.set_quoted('HOST_SCHED_OBJPATH', get_option('host-sched-objpath'))
15conf.set_quoted('HYPERVISOR_BUSNAME', get_option('hypervisor-busname'))
16conf.set_quoted('HYPERVISOR_OBJPATH', get_option('hypervisor-objpath'))
17conf.set_quoted('HOST_STATE_PERSIST_PATH', get_option('host-state-persist-path'))
Andrew Geisslerf2454102019-12-06 15:14:08 -060018conf.set_quoted(
Patrick Williams71e399d2025-02-01 08:36:54 -050019 'POH_COUNTER_PERSIST_PATH',
20 get_option('poh-counter-persist-path'),
21)
Andrew Geisslera0d7bb82023-03-01 12:50:14 -060022conf.set_quoted(
Patrick Williams71e399d2025-02-01 08:36:54 -050023 'CHASSIS_STATE_CHANGE_PERSIST_PATH',
24 get_option('chassis-state-change-persist-path'),
25)
Andrew Geisslerfe270d32021-01-27 14:06:46 -060026conf.set_quoted(
Patrick Williams71e399d2025-02-01 08:36:54 -050027 'SCHEDULED_HOST_TRANSITION_PERSIST_PATH',
28 get_option('scheduled-host-transition-persist-path'),
29)
30conf.set('BOOT_COUNT_MAX_ALLOWED', get_option('boot-count-max-allowed'))
31conf.set('CLASS_VERSION', get_option('class-version'))
32conf.set_quoted('SYSFS_SECURE_BOOT_PATH', get_option('sysfs-secure-boot-path'))
33conf.set_quoted('SYSFS_ABR_IMAGE_PATH', get_option('sysfs-abr-image-path'))
Patrick Williams5cd49f72023-11-29 06:44:17 -060034if build_host_gpios.allowed()
Patrick Williams71e399d2025-02-01 08:36:54 -050035 conf.set_quoted('HOST_GPIOS_BUSNAME', get_option('host-gpios-busname'))
36 conf.set_quoted('HOST_GPIOS_OBJPATH', get_option('host-gpios-objpath'))
Thang Tranba2241c2021-10-26 17:47:09 +070037endif
Andrew Geisslerf2454102019-12-06 15:14:08 -060038
NodeMan97bcbee4a2022-05-27 15:28:45 -050039conf.set10(
Patrick Williams71e399d2025-02-01 08:36:54 -050040 'ONLY_RUN_APR_ON_POWER_LOSS',
41 get_option('only-run-apr-on-power-loss'),
42)
43
44conf.set_quoted('SYSFS_TPM_DEVICE_PATH', get_option('sysfs-tpm-device-path'))
NodeMan97bcbee4a2022-05-27 15:28:45 -050045
Lakshmi Yadlapatib454d8b2023-03-27 16:11:41 -050046conf.set_quoted(
Patrick Williams71e399d2025-02-01 08:36:54 -050047 'SYSFS_TPM_MEASUREMENT_PATH',
48 get_option('sysfs-tpm-measurement-path'),
49)
Lakshmi Yadlapatib454d8b2023-03-27 16:11:41 -050050
Andrew Geissler629e3c42023-05-25 10:31:13 -040051conf.set10(
Patrick Williams71e399d2025-02-01 08:36:54 -050052 'ONLY_ALLOW_BOOT_WHEN_BMC_READY',
53 get_option('only-allow-boot-when-bmc-ready'),
54)
Andrew Geissler629e3c42023-05-25 10:31:13 -040055
Andrew Geissler343dbf82021-03-16 16:56:09 -050056# globals shared across applications
Patrick Williams71e399d2025-02-01 08:36:54 -050057conf.set_quoted('BASE_FILE_DIR', '/run/openbmc/')
NodeMan97bcbee4a2022-05-27 15:28:45 -050058
Patrick Williams71e399d2025-02-01 08:36:54 -050059conf.set_quoted('CHASSIS_LOST_POWER_FILE', '/run/openbmc/chassis@{}-lost-power')
NodeMan97bcbee4a2022-05-27 15:28:45 -050060
Patrick Williams71e399d2025-02-01 08:36:54 -050061conf.set_quoted('HOST_RUNNING_FILE', '/run/openbmc/host@{}-on')
Andrew Geissler343dbf82021-03-16 16:56:09 -050062
Patrick Williams71e399d2025-02-01 08:36:54 -050063conf.set_quoted('CHASSIS_ON_FILE', '/run/openbmc/chassis@{}-on')
Andrew Geissler5259f972021-08-30 15:46:55 -050064
Thang Tran9f381522024-10-18 10:11:01 +070065conf.set(
Patrick Williams71e399d2025-02-01 08:36:54 -050066 'CHECK_FWUPDATE_BEFORE_DO_TRANSITION',
67 get_option('check-fwupdate-before-do-transition').allowed(),
68)
Thang Tran9f381522024-10-18 10:11:01 +070069
Andrew Geisslerf2454102019-12-06 15:14:08 -060070configure_file(output: 'config.h', configuration: conf)
71
Patrick Williams71e399d2025-02-01 08:36:54 -050072if (get_option('warm-reboot').allowed())
73 add_project_arguments('-DENABLE_WARM_REBOOT', language: 'cpp')
Andrew Geissler7fdad602020-06-22 13:46:16 -050074endif
75
Patrick Williams71e399d2025-02-01 08:36:54 -050076if (get_option('force-warm-reboot').allowed())
77 add_project_arguments('-DENABLE_FORCE_WARM_REBOOT', language: 'cpp')
Andrew Geissler31cddb72024-02-27 14:20:26 -060078endif
79
Prithvi Pai3d506282025-02-01 12:31:01 +053080if (get_option('apply-power-policy-bmc-ready').allowed())
81 add_project_arguments('-DAPPLY_POWER_POLICY_WHEN_BMC_READY', language: 'cpp')
82endif
83
Patrick Williamsf0865de2023-12-07 17:16:26 -060084nlohmann_json_dep = dependency('nlohmann_json', include_type: 'system')
Andrew Geisslerf2454102019-12-06 15:14:08 -060085sdbusplus = dependency('sdbusplus')
86sdeventplus = dependency('sdeventplus')
87phosphorlogging = dependency('phosphor-logging')
88phosphordbusinterfaces = dependency('phosphor-dbus-interfaces')
Patrick Williams71e399d2025-02-01 08:36:54 -050089libgpiod = dependency(
90 'libgpiod',
91 version: '>=1.4.1',
92 default_options: ['bindings=cxx'],
93)
Andrew Geisslerf2454102019-12-06 15:14:08 -060094
Patrick Williamsf8d5f3e2022-04-05 15:51:15 -050095if cpp.has_header('CLI/CLI.hpp')
96 CLI11 = declare_dependency()
97else
98 CLI11 = dependency('CLI11')
99endif
100
101# Get Cereal dependency.
102cereal = dependency('cereal', required: false)
103has_cereal = cpp.has_header_symbol(
104 'cereal/cereal.hpp',
105 'cereal::specialize',
106 dependencies: cereal,
Patrick Williams71e399d2025-02-01 08:36:54 -0500107 required: false,
108)
Patrick Williamsf8d5f3e2022-04-05 15:51:15 -0500109if not has_cereal
110 cereal_opts = import('cmake').subproject_options()
Patrick Williams71e399d2025-02-01 08:36:54 -0500111 cereal_opts.add_cmake_defines(
112 {'BUILD_TESTS': 'OFF', 'SKIP_PERFORMANCE_COMPARISON': 'ON'},
113 )
Patrick Williamsf8d5f3e2022-04-05 15:51:15 -0500114 cereal_proj = import('cmake').subproject(
115 'cereal',
116 options: cereal_opts,
Patrick Williams71e399d2025-02-01 08:36:54 -0500117 required: false,
118 )
Patrick Williamsf8d5f3e2022-04-05 15:51:15 -0500119 assert(cereal_proj.found(), 'cereal is required')
120 cereal = cereal_proj.dependency('cereal')
121endif
122
Patrick Williams71e399d2025-02-01 08:36:54 -0500123executable(
124 'phosphor-host-state-manager',
125 'host_state_manager.cpp',
126 'host_state_manager_main.cpp',
127 'settings.cpp',
128 'host_check.cpp',
129 'utils.cpp',
130 dependencies: [
131 cereal,
132 libgpiod,
133 phosphordbusinterfaces,
134 phosphorlogging,
135 sdbusplus,
136 sdeventplus,
137 ],
Andrew Geisslerf2454102019-12-06 15:14:08 -0600138 implicit_include_directories: true,
Patrick Williams71e399d2025-02-01 08:36:54 -0500139 install: true,
Andrew Geisslerf2454102019-12-06 15:14:08 -0600140)
141
Patrick Williams71e399d2025-02-01 08:36:54 -0500142executable(
143 'phosphor-hypervisor-state-manager',
144 'hypervisor_state_manager.cpp',
145 'hypervisor_state_manager_main.cpp',
146 'settings.cpp',
147 dependencies: [
148 phosphordbusinterfaces,
149 phosphorlogging,
150 sdbusplus,
151 sdeventplus,
152 ],
Andrew Geisslerfe270d32021-01-27 14:06:46 -0600153 implicit_include_directories: true,
Patrick Williams71e399d2025-02-01 08:36:54 -0500154 install: true,
Andrew Geisslerfe270d32021-01-27 14:06:46 -0600155)
156
Patrick Williams71e399d2025-02-01 08:36:54 -0500157executable(
158 'phosphor-chassis-state-manager',
159 'chassis_state_manager.cpp',
160 'chassis_state_manager_main.cpp',
161 'utils.cpp',
162 dependencies: [
163 cereal,
164 libgpiod,
165 nlohmann_json_dep,
166 phosphordbusinterfaces,
167 phosphorlogging,
168 sdbusplus,
169 sdeventplus,
170 ],
Andrew Geisslerf2454102019-12-06 15:14:08 -0600171 implicit_include_directories: true,
Patrick Williams71e399d2025-02-01 08:36:54 -0500172 install: true,
Andrew Geisslerf2454102019-12-06 15:14:08 -0600173)
174
Patrick Williams71e399d2025-02-01 08:36:54 -0500175executable(
176 'phosphor-chassis-check-power-status',
177 'chassis_check_power_status.cpp',
178 'utils.cpp',
179 dependencies: [libgpiod, phosphordbusinterfaces, phosphorlogging, sdbusplus],
Andrew Geissler378fe112022-02-03 16:39:44 -0600180 implicit_include_directories: true,
Patrick Williams71e399d2025-02-01 08:36:54 -0500181 install: true,
Andrew Geissler378fe112022-02-03 16:39:44 -0600182)
183
Patrick Williams71e399d2025-02-01 08:36:54 -0500184executable(
185 'phosphor-bmc-state-manager',
186 'bmc_state_manager.cpp',
187 'bmc_state_manager_main.cpp',
188 'utils.cpp',
189 dependencies: [
190 libgpiod,
191 phosphordbusinterfaces,
192 phosphorlogging,
193 sdbusplus,
194 sdeventplus,
195 ],
Andrew Geisslerf2454102019-12-06 15:14:08 -0600196 implicit_include_directories: true,
Patrick Williams71e399d2025-02-01 08:36:54 -0500197 install: true,
Andrew Geisslerf2454102019-12-06 15:14:08 -0600198)
199
Patrick Williams71e399d2025-02-01 08:36:54 -0500200executable(
201 'phosphor-discover-system-state',
202 'discover_system_state.cpp',
203 'settings.cpp',
204 'utils.cpp',
205 dependencies: [cereal, libgpiod, phosphorlogging, sdbusplus],
Andrew Geisslerf2454102019-12-06 15:14:08 -0600206 implicit_include_directories: true,
Patrick Williams71e399d2025-02-01 08:36:54 -0500207 install: true,
Andrew Geisslerf2454102019-12-06 15:14:08 -0600208)
209
Patrick Williams71e399d2025-02-01 08:36:54 -0500210executable(
211 'phosphor-systemd-target-monitor',
212 'systemd_service_parser.cpp',
213 'systemd_target_monitor.cpp',
214 'systemd_target_parser.cpp',
215 'systemd_target_signal.cpp',
216 'utils.cpp',
217 dependencies: [
218 CLI11,
219 libgpiod,
220 nlohmann_json_dep,
221 phosphorlogging,
222 sdbusplus,
223 sdeventplus,
224 ],
Andrew Geisslerf2454102019-12-06 15:14:08 -0600225 implicit_include_directories: true,
Patrick Williams71e399d2025-02-01 08:36:54 -0500226 install: true,
Andrew Geisslerf2454102019-12-06 15:14:08 -0600227)
Andrew Geissler3f125632019-12-11 17:08:19 -0600228
Patrick Williams71e399d2025-02-01 08:36:54 -0500229executable(
230 'phosphor-scheduled-host-transition',
231 'scheduled_host_transition_main.cpp',
232 'scheduled_host_transition.cpp',
233 'utils.cpp',
234 dependencies: [cereal, libgpiod, phosphorlogging, sdbusplus, sdeventplus],
Carol Wang71230ef2020-02-18 17:39:49 +0800235 implicit_include_directories: true,
Patrick Williams71e399d2025-02-01 08:36:54 -0500236 install: true,
Carol Wang71230ef2020-02-18 17:39:49 +0800237)
238
Patrick Williams71e399d2025-02-01 08:36:54 -0500239executable(
240 'phosphor-host-reset-recovery',
241 'host_reset_recovery.cpp',
242 dependencies: [phosphorlogging, sdbusplus],
Andrew Geisslerba0163a2021-08-11 15:09:50 -0400243 implicit_include_directories: true,
Patrick Williams71e399d2025-02-01 08:36:54 -0500244 install: true,
Andrew Geisslerba0163a2021-08-11 15:09:50 -0400245)
246
Patrick Williams71e399d2025-02-01 08:36:54 -0500247executable(
248 'phosphor-secure-boot-check',
249 'secure_boot_check.cpp',
250 'utils.cpp',
251 dependencies: [sdbusplus, phosphorlogging, libgpiod],
Andrew Geissler6b9421b2022-02-24 17:01:55 -0600252 implicit_include_directories: true,
Patrick Williams71e399d2025-02-01 08:36:54 -0500253 install: true,
Andrew Geissler6b9421b2022-02-24 17:01:55 -0600254)
255
Patrick Williams (aider)ee7bb9e2025-04-19 14:13:12 -0400256if get_option('install-utils').allowed()
257 install_data(
258 'obmcutil',
259 install_mode: 'rwxr-xr-x',
260 install_dir: get_option('bindir'),
261 )
262endif
Andrew Geisslerdfa75fc2019-12-11 17:26:42 -0600263
Patrick Williams71e399d2025-02-01 08:36:54 -0500264install_data(
265 'scripts/host-reboot',
266 install_mode: 'rwxr-xr-x',
267 install_dir: get_option('libexecdir') / 'phosphor-state-manager',
Andrew Geissler128ea8e2022-06-22 12:28:15 -0400268)
269
Andrew Geissler179d38c2019-12-10 15:05:23 -0600270systemd = dependency('systemd')
Patrick Williams71e399d2025-02-01 08:36:54 -0500271systemd_system_unit_dir = systemd.get_variable('systemdsystemunitdir')
Andrew Geissler179d38c2019-12-10 15:05:23 -0600272subdir('service_files')
Andrew Geisslerc1011572020-01-27 15:09:50 -0600273subdir('target_files')
Andrew Geissler179d38c2019-12-10 15:05:23 -0600274
Patrick Williams5cd49f72023-11-29 06:44:17 -0600275if build_host_gpios.allowed()
Thang Tranba2241c2021-10-26 17:47:09 +0700276 subdir('host_condition_gpio')
277endif
278
Patrick Williams71e399d2025-02-01 08:36:54 -0500279datadir = join_paths(get_option('sysconfdir'), 'phosphor-systemd-target-monitor')
Andrew Geisslerefef9702019-12-10 16:56:57 -0600280subdir('data')
281
Andrew Geissler3f125632019-12-11 17:08:19 -0600282build_tests = get_option('tests')
283
284# If test coverage of source files within the root directory are wanted,
285# need to define and build the tests from here
Patrick Williamsf88281d2025-01-30 17:47:36 -0500286if build_tests.allowed()
Matt Spinlera279f872025-03-05 14:59:42 -0600287 gtest = dependency('gtest', main: true, disabler: true, required: false)
288 gmock = dependency('gmock', disabler: true, required: false)
289
290 if not gtest.found() or not gmock.found()
291 gtest_proj = import('cmake').subproject('googletest', required: false)
292 if gtest_proj.found()
293 gtest = declare_dependency(
294 dependencies: [
295 dependency('threads'),
296 gtest_proj.dependency('gtest'),
297 gtest_proj.dependency('gtest_main'),
298 ],
299 )
300 gmock = gtest_proj.dependency('gmock')
301 else
302 assert(
303 not get_option('tests').enabled(),
304 'Googletest is required if tests are enabled',
305 )
306 endif
307 endif
308
Patrick Williams71e399d2025-02-01 08:36:54 -0500309 test(
310 'test_systemd_parser',
311 executable(
312 'test_systemd_parser',
313 './test/systemd_parser.cpp',
314 'systemd_target_parser.cpp',
315 dependencies: [gtest, nlohmann_json_dep],
316 implicit_include_directories: true,
317 include_directories: '../',
318 ),
319 )
Andrew Geissler3f125632019-12-11 17:08:19 -0600320
Patrick Williams71e399d2025-02-01 08:36:54 -0500321 test(
322 'test_systemd_signal',
323 executable(
324 'test_systemd_signal',
325 './test/systemd_signal.cpp',
326 'systemd_target_signal.cpp',
327 'utils.cpp',
328 dependencies: [
329 gtest,
330 libgpiod,
331 nlohmann_json_dep,
332 phosphorlogging,
333 sdbusplus,
334 sdeventplus,
335 ],
336 implicit_include_directories: true,
337 include_directories: '../',
338 ),
339 )
Carol Wang4ca6f3f2020-02-19 16:28:59 +0800340
Patrick Williams71e399d2025-02-01 08:36:54 -0500341 test(
342 'test_scheduled_host_transition',
343 executable(
344 'test_scheduled_host_transition',
345 './test/test_scheduled_host_transition.cpp',
346 'scheduled_host_transition.cpp',
347 'utils.cpp',
348 dependencies: [
349 cereal,
350 gmock,
351 gtest,
352 libgpiod,
353 phosphorlogging,
354 sdbusplus,
355 sdeventplus,
356 ],
357 implicit_include_directories: true,
358 include_directories: '../',
359 ),
360 )
Andrew Geisslerc74716e2021-02-09 15:11:10 -0600361
Patrick Williams71e399d2025-02-01 08:36:54 -0500362 test(
363 'test_hypervisor_state',
364 executable(
365 'test_hypervisor_state',
366 './test/hypervisor_state.cpp',
367 'hypervisor_state_manager.cpp',
368 dependencies: [gtest, phosphorlogging, sdbusplus, sdeventplus],
369 implicit_include_directories: true,
370 include_directories: '../',
371 ),
372 )
Andrew Geissler3f125632019-12-11 17:08:19 -0600373endif