blob: d51a86f50fe601023b3b83b13a1fee4eb87793f9 [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
Patrick Williamsf0865de2023-12-07 17:16:26 -060080nlohmann_json_dep = dependency('nlohmann_json', include_type: 'system')
Andrew Geisslerf2454102019-12-06 15:14:08 -060081sdbusplus = dependency('sdbusplus')
82sdeventplus = dependency('sdeventplus')
83phosphorlogging = dependency('phosphor-logging')
84phosphordbusinterfaces = dependency('phosphor-dbus-interfaces')
Patrick Williams71e399d2025-02-01 08:36:54 -050085libgpiod = dependency(
86 'libgpiod',
87 version: '>=1.4.1',
88 default_options: ['bindings=cxx'],
89)
Andrew Geisslerf2454102019-12-06 15:14:08 -060090
Patrick Williamsf8d5f3e2022-04-05 15:51:15 -050091if cpp.has_header('CLI/CLI.hpp')
92 CLI11 = declare_dependency()
93else
94 CLI11 = dependency('CLI11')
95endif
96
97# Get Cereal dependency.
98cereal = dependency('cereal', required: false)
99has_cereal = cpp.has_header_symbol(
100 'cereal/cereal.hpp',
101 'cereal::specialize',
102 dependencies: cereal,
Patrick Williams71e399d2025-02-01 08:36:54 -0500103 required: false,
104)
Patrick Williamsf8d5f3e2022-04-05 15:51:15 -0500105if not has_cereal
106 cereal_opts = import('cmake').subproject_options()
Patrick Williams71e399d2025-02-01 08:36:54 -0500107 cereal_opts.add_cmake_defines(
108 {'BUILD_TESTS': 'OFF', 'SKIP_PERFORMANCE_COMPARISON': 'ON'},
109 )
Patrick Williamsf8d5f3e2022-04-05 15:51:15 -0500110 cereal_proj = import('cmake').subproject(
111 'cereal',
112 options: cereal_opts,
Patrick Williams71e399d2025-02-01 08:36:54 -0500113 required: false,
114 )
Patrick Williamsf8d5f3e2022-04-05 15:51:15 -0500115 assert(cereal_proj.found(), 'cereal is required')
116 cereal = cereal_proj.dependency('cereal')
117endif
118
Patrick Williams71e399d2025-02-01 08:36:54 -0500119executable(
120 'phosphor-host-state-manager',
121 'host_state_manager.cpp',
122 'host_state_manager_main.cpp',
123 'settings.cpp',
124 'host_check.cpp',
125 'utils.cpp',
126 dependencies: [
127 cereal,
128 libgpiod,
129 phosphordbusinterfaces,
130 phosphorlogging,
131 sdbusplus,
132 sdeventplus,
133 ],
Andrew Geisslerf2454102019-12-06 15:14:08 -0600134 implicit_include_directories: true,
Patrick Williams71e399d2025-02-01 08:36:54 -0500135 install: true,
Andrew Geisslerf2454102019-12-06 15:14:08 -0600136)
137
Patrick Williams71e399d2025-02-01 08:36:54 -0500138executable(
139 'phosphor-hypervisor-state-manager',
140 'hypervisor_state_manager.cpp',
141 'hypervisor_state_manager_main.cpp',
142 'settings.cpp',
143 dependencies: [
144 phosphordbusinterfaces,
145 phosphorlogging,
146 sdbusplus,
147 sdeventplus,
148 ],
Andrew Geisslerfe270d32021-01-27 14:06:46 -0600149 implicit_include_directories: true,
Patrick Williams71e399d2025-02-01 08:36:54 -0500150 install: true,
Andrew Geisslerfe270d32021-01-27 14:06:46 -0600151)
152
Patrick Williams71e399d2025-02-01 08:36:54 -0500153executable(
154 'phosphor-chassis-state-manager',
155 'chassis_state_manager.cpp',
156 'chassis_state_manager_main.cpp',
157 'utils.cpp',
158 dependencies: [
159 cereal,
160 libgpiod,
161 nlohmann_json_dep,
162 phosphordbusinterfaces,
163 phosphorlogging,
164 sdbusplus,
165 sdeventplus,
166 ],
Andrew Geisslerf2454102019-12-06 15:14:08 -0600167 implicit_include_directories: true,
Patrick Williams71e399d2025-02-01 08:36:54 -0500168 install: true,
Andrew Geisslerf2454102019-12-06 15:14:08 -0600169)
170
Patrick Williams71e399d2025-02-01 08:36:54 -0500171executable(
172 'phosphor-chassis-check-power-status',
173 'chassis_check_power_status.cpp',
174 'utils.cpp',
175 dependencies: [libgpiod, phosphordbusinterfaces, phosphorlogging, sdbusplus],
Andrew Geissler378fe112022-02-03 16:39:44 -0600176 implicit_include_directories: true,
Patrick Williams71e399d2025-02-01 08:36:54 -0500177 install: true,
Andrew Geissler378fe112022-02-03 16:39:44 -0600178)
179
Patrick Williams71e399d2025-02-01 08:36:54 -0500180executable(
181 'phosphor-bmc-state-manager',
182 'bmc_state_manager.cpp',
183 'bmc_state_manager_main.cpp',
184 'utils.cpp',
185 dependencies: [
186 libgpiod,
187 phosphordbusinterfaces,
188 phosphorlogging,
189 sdbusplus,
190 sdeventplus,
191 ],
Andrew Geisslerf2454102019-12-06 15:14:08 -0600192 implicit_include_directories: true,
Patrick Williams71e399d2025-02-01 08:36:54 -0500193 install: true,
Andrew Geisslerf2454102019-12-06 15:14:08 -0600194)
195
Patrick Williams71e399d2025-02-01 08:36:54 -0500196executable(
197 'phosphor-discover-system-state',
198 'discover_system_state.cpp',
199 'settings.cpp',
200 'utils.cpp',
201 dependencies: [cereal, libgpiod, phosphorlogging, sdbusplus],
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-systemd-target-monitor',
208 'systemd_service_parser.cpp',
209 'systemd_target_monitor.cpp',
210 'systemd_target_parser.cpp',
211 'systemd_target_signal.cpp',
212 'utils.cpp',
213 dependencies: [
214 CLI11,
215 libgpiod,
216 nlohmann_json_dep,
217 phosphorlogging,
218 sdbusplus,
219 sdeventplus,
220 ],
Andrew Geisslerf2454102019-12-06 15:14:08 -0600221 implicit_include_directories: true,
Patrick Williams71e399d2025-02-01 08:36:54 -0500222 install: true,
Andrew Geisslerf2454102019-12-06 15:14:08 -0600223)
Andrew Geissler3f125632019-12-11 17:08:19 -0600224
Patrick Williams71e399d2025-02-01 08:36:54 -0500225executable(
226 'phosphor-scheduled-host-transition',
227 'scheduled_host_transition_main.cpp',
228 'scheduled_host_transition.cpp',
229 'utils.cpp',
230 dependencies: [cereal, libgpiod, phosphorlogging, sdbusplus, sdeventplus],
Carol Wang71230ef2020-02-18 17:39:49 +0800231 implicit_include_directories: true,
Patrick Williams71e399d2025-02-01 08:36:54 -0500232 install: true,
Carol Wang71230ef2020-02-18 17:39:49 +0800233)
234
Patrick Williams71e399d2025-02-01 08:36:54 -0500235executable(
236 'phosphor-host-reset-recovery',
237 'host_reset_recovery.cpp',
238 dependencies: [phosphorlogging, sdbusplus],
Andrew Geisslerba0163a2021-08-11 15:09:50 -0400239 implicit_include_directories: true,
Patrick Williams71e399d2025-02-01 08:36:54 -0500240 install: true,
Andrew Geisslerba0163a2021-08-11 15:09:50 -0400241)
242
Patrick Williams71e399d2025-02-01 08:36:54 -0500243executable(
244 'phosphor-secure-boot-check',
245 'secure_boot_check.cpp',
246 'utils.cpp',
247 dependencies: [sdbusplus, phosphorlogging, libgpiod],
Andrew Geissler6b9421b2022-02-24 17:01:55 -0600248 implicit_include_directories: true,
Patrick Williams71e399d2025-02-01 08:36:54 -0500249 install: true,
Andrew Geissler6b9421b2022-02-24 17:01:55 -0600250)
251
Patrick Williams71e399d2025-02-01 08:36:54 -0500252install_data(
253 'obmcutil',
254 install_mode: 'rwxr-xr-x',
255 install_dir: get_option('bindir'),
Andrew Geisslerdfa75fc2019-12-11 17:26:42 -0600256)
257
Patrick Williams71e399d2025-02-01 08:36:54 -0500258install_data(
259 'scripts/host-reboot',
260 install_mode: 'rwxr-xr-x',
261 install_dir: get_option('libexecdir') / 'phosphor-state-manager',
Andrew Geissler128ea8e2022-06-22 12:28:15 -0400262)
263
Andrew Geissler179d38c2019-12-10 15:05:23 -0600264systemd = dependency('systemd')
Patrick Williams71e399d2025-02-01 08:36:54 -0500265systemd_system_unit_dir = systemd.get_variable('systemdsystemunitdir')
Andrew Geissler179d38c2019-12-10 15:05:23 -0600266subdir('service_files')
Andrew Geisslerc1011572020-01-27 15:09:50 -0600267subdir('target_files')
Andrew Geissler179d38c2019-12-10 15:05:23 -0600268
Patrick Williams5cd49f72023-11-29 06:44:17 -0600269if build_host_gpios.allowed()
Thang Tranba2241c2021-10-26 17:47:09 +0700270 subdir('host_condition_gpio')
271endif
272
Patrick Williams71e399d2025-02-01 08:36:54 -0500273datadir = join_paths(get_option('sysconfdir'), 'phosphor-systemd-target-monitor')
Andrew Geisslerefef9702019-12-10 16:56:57 -0600274subdir('data')
275
Andrew Geissler3f125632019-12-11 17:08:19 -0600276build_tests = get_option('tests')
277
278# If test coverage of source files within the root directory are wanted,
279# need to define and build the tests from here
Patrick Williamsf88281d2025-01-30 17:47:36 -0500280if build_tests.allowed()
Matt Spinlera279f872025-03-05 14:59:42 -0600281 gtest = dependency('gtest', main: true, disabler: true, required: false)
282 gmock = dependency('gmock', disabler: true, required: false)
283
284 if not gtest.found() or not gmock.found()
285 gtest_proj = import('cmake').subproject('googletest', required: false)
286 if gtest_proj.found()
287 gtest = declare_dependency(
288 dependencies: [
289 dependency('threads'),
290 gtest_proj.dependency('gtest'),
291 gtest_proj.dependency('gtest_main'),
292 ],
293 )
294 gmock = gtest_proj.dependency('gmock')
295 else
296 assert(
297 not get_option('tests').enabled(),
298 'Googletest is required if tests are enabled',
299 )
300 endif
301 endif
302
Patrick Williams71e399d2025-02-01 08:36:54 -0500303 test(
304 'test_systemd_parser',
305 executable(
306 'test_systemd_parser',
307 './test/systemd_parser.cpp',
308 'systemd_target_parser.cpp',
309 dependencies: [gtest, nlohmann_json_dep],
310 implicit_include_directories: true,
311 include_directories: '../',
312 ),
313 )
Andrew Geissler3f125632019-12-11 17:08:19 -0600314
Patrick Williams71e399d2025-02-01 08:36:54 -0500315 test(
316 'test_systemd_signal',
317 executable(
318 'test_systemd_signal',
319 './test/systemd_signal.cpp',
320 'systemd_target_signal.cpp',
321 'utils.cpp',
322 dependencies: [
323 gtest,
324 libgpiod,
325 nlohmann_json_dep,
326 phosphorlogging,
327 sdbusplus,
328 sdeventplus,
329 ],
330 implicit_include_directories: true,
331 include_directories: '../',
332 ),
333 )
Carol Wang4ca6f3f2020-02-19 16:28:59 +0800334
Patrick Williams71e399d2025-02-01 08:36:54 -0500335 test(
336 'test_scheduled_host_transition',
337 executable(
338 'test_scheduled_host_transition',
339 './test/test_scheduled_host_transition.cpp',
340 'scheduled_host_transition.cpp',
341 'utils.cpp',
342 dependencies: [
343 cereal,
344 gmock,
345 gtest,
346 libgpiod,
347 phosphorlogging,
348 sdbusplus,
349 sdeventplus,
350 ],
351 implicit_include_directories: true,
352 include_directories: '../',
353 ),
354 )
Andrew Geisslerc74716e2021-02-09 15:11:10 -0600355
Patrick Williams71e399d2025-02-01 08:36:54 -0500356 test(
357 'test_hypervisor_state',
358 executable(
359 'test_hypervisor_state',
360 './test/hypervisor_state.cpp',
361 'hypervisor_state_manager.cpp',
362 dependencies: [gtest, phosphorlogging, sdbusplus, sdeventplus],
363 implicit_include_directories: true,
364 include_directories: '../',
365 ),
366 )
Andrew Geissler3f125632019-12-11 17:08:19 -0600367endif