blob: fee30052d5e2180864871e234b88b3b7596e169a [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
Thang Tranff85df62025-05-07 13:40:43 +070044conf.set10('RUN_APR_ON_PINHOLE_RESET', get_option('run-apr-on-pinhole-reset'))
45
46conf.set10('RUN_APR_ON_WATCHDOG_RESET', get_option('run-apr-on-watchdog-reset'))
47
48conf.set10('RUN_APR_ON_SOFTWARE_RESET', get_option('run-apr-on-software-reset'))
49
Patrick Williams71e399d2025-02-01 08:36:54 -050050conf.set_quoted('SYSFS_TPM_DEVICE_PATH', get_option('sysfs-tpm-device-path'))
NodeMan97bcbee4a2022-05-27 15:28:45 -050051
Lakshmi Yadlapatib454d8b2023-03-27 16:11:41 -050052conf.set_quoted(
Patrick Williams71e399d2025-02-01 08:36:54 -050053 'SYSFS_TPM_MEASUREMENT_PATH',
54 get_option('sysfs-tpm-measurement-path'),
55)
Lakshmi Yadlapatib454d8b2023-03-27 16:11:41 -050056
Andrew Geissler629e3c42023-05-25 10:31:13 -040057conf.set10(
Patrick Williams71e399d2025-02-01 08:36:54 -050058 'ONLY_ALLOW_BOOT_WHEN_BMC_READY',
59 get_option('only-allow-boot-when-bmc-ready'),
60)
Andrew Geissler629e3c42023-05-25 10:31:13 -040061
Andrew Geissler343dbf82021-03-16 16:56:09 -050062# globals shared across applications
Patrick Williams71e399d2025-02-01 08:36:54 -050063conf.set_quoted('BASE_FILE_DIR', '/run/openbmc/')
NodeMan97bcbee4a2022-05-27 15:28:45 -050064
Patrick Williams71e399d2025-02-01 08:36:54 -050065conf.set_quoted('CHASSIS_LOST_POWER_FILE', '/run/openbmc/chassis@{}-lost-power')
NodeMan97bcbee4a2022-05-27 15:28:45 -050066
Patrick Williams71e399d2025-02-01 08:36:54 -050067conf.set_quoted('HOST_RUNNING_FILE', '/run/openbmc/host@{}-on')
Andrew Geissler343dbf82021-03-16 16:56:09 -050068
Patrick Williams71e399d2025-02-01 08:36:54 -050069conf.set_quoted('CHASSIS_ON_FILE', '/run/openbmc/chassis@{}-on')
Andrew Geissler5259f972021-08-30 15:46:55 -050070
Thang Tran9f381522024-10-18 10:11:01 +070071conf.set(
Patrick Williams71e399d2025-02-01 08:36:54 -050072 'CHECK_FWUPDATE_BEFORE_DO_TRANSITION',
73 get_option('check-fwupdate-before-do-transition').allowed(),
74)
Thang Tran9f381522024-10-18 10:11:01 +070075
Andrew Geisslerf2454102019-12-06 15:14:08 -060076configure_file(output: 'config.h', configuration: conf)
77
Patrick Williams71e399d2025-02-01 08:36:54 -050078if (get_option('warm-reboot').allowed())
79 add_project_arguments('-DENABLE_WARM_REBOOT', language: 'cpp')
Andrew Geissler7fdad602020-06-22 13:46:16 -050080endif
81
Patrick Williams71e399d2025-02-01 08:36:54 -050082if (get_option('force-warm-reboot').allowed())
83 add_project_arguments('-DENABLE_FORCE_WARM_REBOOT', language: 'cpp')
Andrew Geissler31cddb72024-02-27 14:20:26 -060084endif
85
Prithvi Pai3d506282025-02-01 12:31:01 +053086if (get_option('apply-power-policy-bmc-ready').allowed())
87 add_project_arguments('-DAPPLY_POWER_POLICY_WHEN_BMC_READY', language: 'cpp')
88endif
89
Patrick Williamsf0865de2023-12-07 17:16:26 -060090nlohmann_json_dep = dependency('nlohmann_json', include_type: 'system')
Andrew Geisslerf2454102019-12-06 15:14:08 -060091sdbusplus = dependency('sdbusplus')
92sdeventplus = dependency('sdeventplus')
93phosphorlogging = dependency('phosphor-logging')
94phosphordbusinterfaces = dependency('phosphor-dbus-interfaces')
Patrick Williams71e399d2025-02-01 08:36:54 -050095libgpiod = dependency(
96 'libgpiod',
97 version: '>=1.4.1',
98 default_options: ['bindings=cxx'],
99)
Andrew Geisslerf2454102019-12-06 15:14:08 -0600100
Patrick Williamsf8d5f3e2022-04-05 15:51:15 -0500101if cpp.has_header('CLI/CLI.hpp')
102 CLI11 = declare_dependency()
103else
104 CLI11 = dependency('CLI11')
105endif
106
107# Get Cereal dependency.
108cereal = dependency('cereal', required: false)
109has_cereal = cpp.has_header_symbol(
110 'cereal/cereal.hpp',
111 'cereal::specialize',
112 dependencies: cereal,
Patrick Williams71e399d2025-02-01 08:36:54 -0500113 required: false,
114)
Patrick Williamsf8d5f3e2022-04-05 15:51:15 -0500115if not has_cereal
116 cereal_opts = import('cmake').subproject_options()
Patrick Williams71e399d2025-02-01 08:36:54 -0500117 cereal_opts.add_cmake_defines(
118 {'BUILD_TESTS': 'OFF', 'SKIP_PERFORMANCE_COMPARISON': 'ON'},
119 )
Patrick Williamsf8d5f3e2022-04-05 15:51:15 -0500120 cereal_proj = import('cmake').subproject(
121 'cereal',
122 options: cereal_opts,
Patrick Williams71e399d2025-02-01 08:36:54 -0500123 required: false,
124 )
Patrick Williamsf8d5f3e2022-04-05 15:51:15 -0500125 assert(cereal_proj.found(), 'cereal is required')
126 cereal = cereal_proj.dependency('cereal')
127endif
128
Patrick Williams71e399d2025-02-01 08:36:54 -0500129executable(
130 'phosphor-host-state-manager',
131 'host_state_manager.cpp',
132 'host_state_manager_main.cpp',
133 'settings.cpp',
134 'host_check.cpp',
135 'utils.cpp',
136 dependencies: [
137 cereal,
138 libgpiod,
139 phosphordbusinterfaces,
140 phosphorlogging,
141 sdbusplus,
142 sdeventplus,
143 ],
Andrew Geisslerf2454102019-12-06 15:14:08 -0600144 implicit_include_directories: true,
Patrick Williams71e399d2025-02-01 08:36:54 -0500145 install: true,
Andrew Geisslerf2454102019-12-06 15:14:08 -0600146)
147
Patrick Williams71e399d2025-02-01 08:36:54 -0500148executable(
149 'phosphor-hypervisor-state-manager',
150 'hypervisor_state_manager.cpp',
151 'hypervisor_state_manager_main.cpp',
152 'settings.cpp',
153 dependencies: [
154 phosphordbusinterfaces,
155 phosphorlogging,
156 sdbusplus,
157 sdeventplus,
158 ],
Andrew Geisslerfe270d32021-01-27 14:06:46 -0600159 implicit_include_directories: true,
Patrick Williams71e399d2025-02-01 08:36:54 -0500160 install: true,
Andrew Geisslerfe270d32021-01-27 14:06:46 -0600161)
162
Patrick Williams71e399d2025-02-01 08:36:54 -0500163executable(
164 'phosphor-chassis-state-manager',
165 'chassis_state_manager.cpp',
166 'chassis_state_manager_main.cpp',
167 'utils.cpp',
168 dependencies: [
169 cereal,
170 libgpiod,
171 nlohmann_json_dep,
172 phosphordbusinterfaces,
173 phosphorlogging,
174 sdbusplus,
175 sdeventplus,
176 ],
Andrew Geisslerf2454102019-12-06 15:14:08 -0600177 implicit_include_directories: true,
Patrick Williams71e399d2025-02-01 08:36:54 -0500178 install: true,
Andrew Geisslerf2454102019-12-06 15:14:08 -0600179)
180
Patrick Williams71e399d2025-02-01 08:36:54 -0500181executable(
182 'phosphor-chassis-check-power-status',
183 'chassis_check_power_status.cpp',
184 'utils.cpp',
185 dependencies: [libgpiod, phosphordbusinterfaces, phosphorlogging, sdbusplus],
Andrew Geissler378fe112022-02-03 16:39:44 -0600186 implicit_include_directories: true,
Patrick Williams71e399d2025-02-01 08:36:54 -0500187 install: true,
Andrew Geissler378fe112022-02-03 16:39:44 -0600188)
189
Patrick Williams71e399d2025-02-01 08:36:54 -0500190executable(
191 'phosphor-bmc-state-manager',
192 'bmc_state_manager.cpp',
193 'bmc_state_manager_main.cpp',
194 'utils.cpp',
195 dependencies: [
196 libgpiod,
197 phosphordbusinterfaces,
198 phosphorlogging,
199 sdbusplus,
200 sdeventplus,
201 ],
Andrew Geisslerf2454102019-12-06 15:14:08 -0600202 implicit_include_directories: true,
Patrick Williams71e399d2025-02-01 08:36:54 -0500203 install: true,
Andrew Geisslerf2454102019-12-06 15:14:08 -0600204)
205
Patrick Williams71e399d2025-02-01 08:36:54 -0500206executable(
207 'phosphor-discover-system-state',
208 'discover_system_state.cpp',
209 'settings.cpp',
210 'utils.cpp',
211 dependencies: [cereal, libgpiod, phosphorlogging, sdbusplus],
Andrew Geisslerf2454102019-12-06 15:14:08 -0600212 implicit_include_directories: true,
Patrick Williams71e399d2025-02-01 08:36:54 -0500213 install: true,
Andrew Geisslerf2454102019-12-06 15:14:08 -0600214)
215
Patrick Williams71e399d2025-02-01 08:36:54 -0500216executable(
217 'phosphor-systemd-target-monitor',
218 'systemd_service_parser.cpp',
219 'systemd_target_monitor.cpp',
220 'systemd_target_parser.cpp',
221 'systemd_target_signal.cpp',
222 'utils.cpp',
223 dependencies: [
224 CLI11,
225 libgpiod,
226 nlohmann_json_dep,
227 phosphorlogging,
228 sdbusplus,
229 sdeventplus,
230 ],
Andrew Geisslerf2454102019-12-06 15:14:08 -0600231 implicit_include_directories: true,
Patrick Williams71e399d2025-02-01 08:36:54 -0500232 install: true,
Andrew Geisslerf2454102019-12-06 15:14:08 -0600233)
Andrew Geissler3f125632019-12-11 17:08:19 -0600234
Patrick Williams71e399d2025-02-01 08:36:54 -0500235executable(
236 'phosphor-scheduled-host-transition',
237 'scheduled_host_transition_main.cpp',
238 'scheduled_host_transition.cpp',
239 'utils.cpp',
240 dependencies: [cereal, libgpiod, phosphorlogging, sdbusplus, sdeventplus],
Carol Wang71230ef2020-02-18 17:39:49 +0800241 implicit_include_directories: true,
Patrick Williams71e399d2025-02-01 08:36:54 -0500242 install: true,
Carol Wang71230ef2020-02-18 17:39:49 +0800243)
244
Patrick Williams71e399d2025-02-01 08:36:54 -0500245executable(
246 'phosphor-host-reset-recovery',
247 'host_reset_recovery.cpp',
248 dependencies: [phosphorlogging, sdbusplus],
Andrew Geisslerba0163a2021-08-11 15:09:50 -0400249 implicit_include_directories: true,
Patrick Williams71e399d2025-02-01 08:36:54 -0500250 install: true,
Andrew Geisslerba0163a2021-08-11 15:09:50 -0400251)
252
Patrick Williams71e399d2025-02-01 08:36:54 -0500253executable(
254 'phosphor-secure-boot-check',
255 'secure_boot_check.cpp',
256 'utils.cpp',
257 dependencies: [sdbusplus, phosphorlogging, libgpiod],
Andrew Geissler6b9421b2022-02-24 17:01:55 -0600258 implicit_include_directories: true,
Patrick Williams71e399d2025-02-01 08:36:54 -0500259 install: true,
Andrew Geissler6b9421b2022-02-24 17:01:55 -0600260)
261
Patrick Williams (aider)ee7bb9e2025-04-19 14:13:12 -0400262if get_option('install-utils').allowed()
263 install_data(
264 'obmcutil',
265 install_mode: 'rwxr-xr-x',
266 install_dir: get_option('bindir'),
267 )
268endif
Andrew Geisslerdfa75fc2019-12-11 17:26:42 -0600269
Patrick Williams71e399d2025-02-01 08:36:54 -0500270install_data(
271 'scripts/host-reboot',
272 install_mode: 'rwxr-xr-x',
273 install_dir: get_option('libexecdir') / 'phosphor-state-manager',
Andrew Geissler128ea8e2022-06-22 12:28:15 -0400274)
275
Andrew Geissler179d38c2019-12-10 15:05:23 -0600276systemd = dependency('systemd')
Patrick Williams71e399d2025-02-01 08:36:54 -0500277systemd_system_unit_dir = systemd.get_variable('systemdsystemunitdir')
Andrew Geissler179d38c2019-12-10 15:05:23 -0600278subdir('service_files')
Andrew Geisslerc1011572020-01-27 15:09:50 -0600279subdir('target_files')
Andrew Geissler179d38c2019-12-10 15:05:23 -0600280
Patrick Williams5cd49f72023-11-29 06:44:17 -0600281if build_host_gpios.allowed()
Thang Tranba2241c2021-10-26 17:47:09 +0700282 subdir('host_condition_gpio')
283endif
284
Patrick Williams71e399d2025-02-01 08:36:54 -0500285datadir = join_paths(get_option('sysconfdir'), 'phosphor-systemd-target-monitor')
Andrew Geisslerefef9702019-12-10 16:56:57 -0600286subdir('data')
287
Andrew Geissler3f125632019-12-11 17:08:19 -0600288build_tests = get_option('tests')
289
290# If test coverage of source files within the root directory are wanted,
291# need to define and build the tests from here
Patrick Williamsf88281d2025-01-30 17:47:36 -0500292if build_tests.allowed()
Matt Spinlera279f872025-03-05 14:59:42 -0600293 gtest = dependency('gtest', main: true, disabler: true, required: false)
294 gmock = dependency('gmock', disabler: true, required: false)
295
296 if not gtest.found() or not gmock.found()
297 gtest_proj = import('cmake').subproject('googletest', required: false)
298 if gtest_proj.found()
299 gtest = declare_dependency(
300 dependencies: [
301 dependency('threads'),
302 gtest_proj.dependency('gtest'),
303 gtest_proj.dependency('gtest_main'),
304 ],
305 )
306 gmock = gtest_proj.dependency('gmock')
307 else
308 assert(
309 not get_option('tests').enabled(),
310 'Googletest is required if tests are enabled',
311 )
312 endif
313 endif
314
Patrick Williams71e399d2025-02-01 08:36:54 -0500315 test(
316 'test_systemd_parser',
317 executable(
318 'test_systemd_parser',
319 './test/systemd_parser.cpp',
320 'systemd_target_parser.cpp',
321 dependencies: [gtest, nlohmann_json_dep],
322 implicit_include_directories: true,
323 include_directories: '../',
324 ),
325 )
Andrew Geissler3f125632019-12-11 17:08:19 -0600326
Patrick Williams71e399d2025-02-01 08:36:54 -0500327 test(
328 'test_systemd_signal',
329 executable(
330 'test_systemd_signal',
331 './test/systemd_signal.cpp',
332 'systemd_target_signal.cpp',
333 'utils.cpp',
334 dependencies: [
335 gtest,
336 libgpiod,
337 nlohmann_json_dep,
338 phosphorlogging,
339 sdbusplus,
340 sdeventplus,
341 ],
342 implicit_include_directories: true,
343 include_directories: '../',
344 ),
345 )
Carol Wang4ca6f3f2020-02-19 16:28:59 +0800346
Patrick Williams71e399d2025-02-01 08:36:54 -0500347 test(
348 'test_scheduled_host_transition',
349 executable(
350 'test_scheduled_host_transition',
351 './test/test_scheduled_host_transition.cpp',
352 'scheduled_host_transition.cpp',
353 'utils.cpp',
354 dependencies: [
355 cereal,
356 gmock,
357 gtest,
358 libgpiod,
359 phosphorlogging,
360 sdbusplus,
361 sdeventplus,
362 ],
363 implicit_include_directories: true,
364 include_directories: '../',
365 ),
366 )
Andrew Geisslerc74716e2021-02-09 15:11:10 -0600367
Patrick Williams71e399d2025-02-01 08:36:54 -0500368 test(
369 'test_hypervisor_state',
370 executable(
371 'test_hypervisor_state',
372 './test/hypervisor_state.cpp',
373 'hypervisor_state_manager.cpp',
374 dependencies: [gtest, phosphorlogging, sdbusplus, sdeventplus],
375 implicit_include_directories: true,
376 include_directories: '../',
377 ),
378 )
Andrew Geissler3f125632019-12-11 17:08:19 -0600379endif