1project( 2 'phosphor-state-manager', 3 'cpp', 4 default_options: ['warning_level=3', 'werror=true', 'cpp_std=c++23'], 5 meson_version: '>=1.1.1', 6 license: 'Apache-2.0', 7 version: '0.1', 8) 9cpp = meson.get_compiler('cpp') 10 11build_host_gpios = get_option('host-gpios') 12 13conf = configuration_data() 14conf.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')) 18conf.set_quoted( 19 'POH_COUNTER_PERSIST_PATH', 20 get_option('poh-counter-persist-path'), 21) 22conf.set_quoted( 23 'CHASSIS_STATE_CHANGE_PERSIST_PATH', 24 get_option('chassis-state-change-persist-path'), 25) 26conf.set_quoted( 27 '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')) 34if build_host_gpios.allowed() 35 conf.set_quoted('HOST_GPIOS_BUSNAME', get_option('host-gpios-busname')) 36 conf.set_quoted('HOST_GPIOS_OBJPATH', get_option('host-gpios-objpath')) 37endif 38 39conf.set10( 40 'ONLY_RUN_APR_ON_POWER_LOSS', 41 get_option('only-run-apr-on-power-loss'), 42) 43 44conf.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 50conf.set_quoted('SYSFS_TPM_DEVICE_PATH', get_option('sysfs-tpm-device-path')) 51 52conf.set_quoted( 53 'SYSFS_TPM_MEASUREMENT_PATH', 54 get_option('sysfs-tpm-measurement-path'), 55) 56 57conf.set10( 58 'ONLY_ALLOW_BOOT_WHEN_BMC_READY', 59 get_option('only-allow-boot-when-bmc-ready'), 60) 61 62# globals shared across applications 63conf.set_quoted('BASE_FILE_DIR', '/run/openbmc/') 64 65conf.set_quoted('CHASSIS_LOST_POWER_FILE', '/run/openbmc/chassis@{}-lost-power') 66 67conf.set_quoted('HOST_RUNNING_FILE', '/run/openbmc/host@{}-on') 68 69conf.set_quoted('CHASSIS_ON_FILE', '/run/openbmc/chassis@{}-on') 70 71conf.set( 72 'CHECK_FWUPDATE_BEFORE_DO_TRANSITION', 73 get_option('check-fwupdate-before-do-transition').allowed(), 74) 75 76configure_file(output: 'config.h', configuration: conf) 77 78if (get_option('warm-reboot').allowed()) 79 add_project_arguments('-DENABLE_WARM_REBOOT', language: 'cpp') 80endif 81 82if (get_option('force-warm-reboot').allowed()) 83 add_project_arguments('-DENABLE_FORCE_WARM_REBOOT', language: 'cpp') 84endif 85 86if (get_option('apply-power-policy-bmc-ready').allowed()) 87 add_project_arguments('-DAPPLY_POWER_POLICY_WHEN_BMC_READY', language: 'cpp') 88endif 89 90nlohmann_json_dep = dependency('nlohmann_json', include_type: 'system') 91sdbusplus = dependency('sdbusplus') 92sdeventplus = dependency('sdeventplus') 93phosphorlogging = dependency('phosphor-logging') 94phosphordbusinterfaces = dependency('phosphor-dbus-interfaces') 95libgpiod = dependency( 96 'libgpiod', 97 version: '>=1.4.1', 98 default_options: ['bindings=cxx'], 99) 100 101if 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, 113 required: false, 114) 115if not has_cereal 116 cereal_opts = import('cmake').subproject_options() 117 cereal_opts.add_cmake_defines( 118 {'BUILD_TESTS': 'OFF', 'SKIP_PERFORMANCE_COMPARISON': 'ON'}, 119 ) 120 cereal_proj = import('cmake').subproject( 121 'cereal', 122 options: cereal_opts, 123 required: false, 124 ) 125 assert(cereal_proj.found(), 'cereal is required') 126 cereal = cereal_proj.dependency('cereal') 127endif 128 129executable( 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 ], 144 implicit_include_directories: true, 145 install: true, 146) 147 148executable( 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 ], 159 implicit_include_directories: true, 160 install: true, 161) 162 163executable( 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 ], 177 implicit_include_directories: true, 178 install: true, 179) 180 181executable( 182 'phosphor-chassis-check-power-status', 183 'chassis_check_power_status.cpp', 184 'utils.cpp', 185 dependencies: [libgpiod, phosphordbusinterfaces, phosphorlogging, sdbusplus], 186 implicit_include_directories: true, 187 install: true, 188) 189 190executable( 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 ], 202 implicit_include_directories: true, 203 install: true, 204) 205 206executable( 207 'phosphor-discover-system-state', 208 'discover_system_state.cpp', 209 'settings.cpp', 210 'utils.cpp', 211 dependencies: [cereal, libgpiod, phosphorlogging, sdbusplus], 212 implicit_include_directories: true, 213 install: true, 214) 215 216executable( 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 ], 231 implicit_include_directories: true, 232 install: true, 233) 234 235executable( 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], 241 implicit_include_directories: true, 242 install: true, 243) 244 245executable( 246 'phosphor-host-reset-recovery', 247 'host_reset_recovery.cpp', 248 dependencies: [phosphorlogging, sdbusplus], 249 implicit_include_directories: true, 250 install: true, 251) 252 253executable( 254 'phosphor-secure-boot-check', 255 'secure_boot_check.cpp', 256 'utils.cpp', 257 dependencies: [sdbusplus, phosphorlogging, libgpiod], 258 implicit_include_directories: true, 259 install: true, 260) 261 262if get_option('install-utils').allowed() 263 install_data( 264 'obmcutil', 265 install_mode: 'rwxr-xr-x', 266 install_dir: get_option('bindir'), 267 ) 268endif 269 270install_data( 271 'scripts/host-reboot', 272 install_mode: 'rwxr-xr-x', 273 install_dir: get_option('libexecdir') / 'phosphor-state-manager', 274) 275 276systemd = dependency('systemd') 277systemd_system_unit_dir = systemd.get_variable('systemd_system_unit_dir') 278subdir('service_files') 279subdir('target_files') 280 281if build_host_gpios.allowed() 282 subdir('host_condition_gpio') 283endif 284 285datadir = join_paths(get_option('sysconfdir'), 'phosphor-systemd-target-monitor') 286subdir('data') 287 288build_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 292if build_tests.allowed() 293 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 315 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 ) 326 327 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 ) 346 347 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 ) 367 368 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 ) 379endif 380