1project( 2 'phosphor-state-manager', 3 'cpp', 4 default_options: [ 5 'warning_level=3', 6 'werror=true', 7 'cpp_std=c++23' 8 ], 9 meson_version: '>=1.1.1', 10 license: 'Apache-2.0', 11 version: '0.1', 12) 13cpp = meson.get_compiler('cpp') 14 15build_host_gpios = get_option('host-gpios') 16 17conf = configuration_data() 18conf.set_quoted( 19 'HOST_BUSNAME', get_option('host-busname')) 20conf.set_quoted( 21 'HOST_OBJPATH', get_option('host-objpath')) 22conf.set_quoted( 23 'HOST_SCHED_OBJPATH', get_option('host-sched-objpath')) 24conf.set_quoted( 25 'HYPERVISOR_BUSNAME', get_option('hypervisor-busname')) 26conf.set_quoted( 27 'HYPERVISOR_OBJPATH', get_option('hypervisor-objpath')) 28conf.set_quoted( 29 'CHASSIS_BUSNAME', get_option('chassis-busname')) 30conf.set_quoted( 31 'CHASSIS_OBJPATH', get_option('chassis-objpath')) 32conf.set_quoted( 33 'BMC_BUSNAME', get_option('bmc-busname')) 34conf.set_quoted( 35 'BMC_OBJPATH', get_option('bmc-objpath')) 36conf.set_quoted( 37 'HOST_STATE_PERSIST_PATH', get_option('host-state-persist-path')) 38conf.set_quoted( 39 'POH_COUNTER_PERSIST_PATH', get_option('poh-counter-persist-path')) 40conf.set_quoted( 41 'CHASSIS_STATE_CHANGE_PERSIST_PATH', get_option('chassis-state-change-persist-path')) 42conf.set_quoted( 43 'SCHEDULED_HOST_TRANSITION_PERSIST_PATH', get_option('scheduled-host-transition-persist-path')) 44conf.set_quoted( 45 'SCHEDULED_HOST_TRANSITION_BUSNAME', get_option('scheduled-host-transition-busname')) 46conf.set( 47 'BOOT_COUNT_MAX_ALLOWED', get_option('boot-count-max-allowed')) 48conf.set( 49 'CLASS_VERSION', get_option('class-version')) 50conf.set_quoted( 51 'SYSFS_SECURE_BOOT_PATH', get_option('sysfs-secure-boot-path')) 52conf.set_quoted( 53 'SYSFS_ABR_IMAGE_PATH', get_option('sysfs-abr-image-path')) 54if build_host_gpios.allowed() 55 conf.set_quoted( 56 'HOST_GPIOS_BUSNAME', get_option('host-gpios-busname')) 57 conf.set_quoted( 58 'HOST_GPIOS_OBJPATH', get_option('host-gpios-objpath')) 59endif 60 61conf.set10( 62 'ONLY_RUN_APR_ON_POWER_LOSS', get_option('only-run-apr-on-power-loss')) 63 64conf.set_quoted( 65 'SYSFS_TPM_DEVICE_PATH', get_option('sysfs-tpm-device-path')) 66 67conf.set_quoted( 68 'SYSFS_TPM_MEASUREMENT_PATH', get_option('sysfs-tpm-measurement-path')) 69 70conf.set10( 71 'ONLY_ALLOW_BOOT_WHEN_BMC_READY', get_option('only-allow-boot-when-bmc-ready')) 72 73# globals shared across applications 74conf.set_quoted( 75 'BASE_FILE_DIR', '/run/openbmc/') 76 77conf.set_quoted( 78 'CHASSIS_LOST_POWER_FILE', '/run/openbmc/chassis@{}-lost-power') 79 80conf.set_quoted( 81 'HOST_RUNNING_FILE', '/run/openbmc/host@{}-on') 82 83conf.set_quoted( 84 'CHASSIS_ON_FILE', '/run/openbmc/chassis@{}-on') 85 86configure_file(output: 'config.h', configuration: conf) 87 88if(get_option('warm-reboot').allowed()) 89 add_project_arguments('-DENABLE_WARM_REBOOT',language:'cpp') 90endif 91 92if(get_option('force-warm-reboot').allowed()) 93 add_project_arguments('-DENABLE_FORCE_WARM_REBOOT',language:'cpp') 94endif 95 96nlohmann_json_dep = dependency('nlohmann_json', include_type: 'system') 97sdbusplus = dependency('sdbusplus') 98sdeventplus = dependency('sdeventplus') 99phosphorlogging = dependency('phosphor-logging') 100phosphordbusinterfaces = dependency('phosphor-dbus-interfaces') 101libgpiod = dependency('libgpiod', version : '>=1.4.1') 102 103if cpp.has_header('CLI/CLI.hpp') 104 CLI11 = declare_dependency() 105else 106 CLI11 = dependency('CLI11') 107endif 108 109# Get Cereal dependency. 110cereal = dependency('cereal', required: false) 111has_cereal = cpp.has_header_symbol( 112 'cereal/cereal.hpp', 113 'cereal::specialize', 114 dependencies: cereal, 115 required: false) 116if not has_cereal 117 cereal_opts = import('cmake').subproject_options() 118 cereal_opts.add_cmake_defines({'BUILD_TESTS': 'OFF'}) 119 cereal_proj = import('cmake').subproject( 120 'cereal', 121 options: cereal_opts, 122 required: false) 123 assert(cereal_proj.found(), 'cereal is required') 124 cereal = cereal_proj.dependency('cereal') 125endif 126 127executable('phosphor-host-state-manager', 128 'host_state_manager.cpp', 129 'host_state_manager_main.cpp', 130 'settings.cpp', 131 'host_check.cpp', 132 'utils.cpp', 133 dependencies: [ 134 cereal, 135 libgpiod, 136 phosphordbusinterfaces, 137 phosphorlogging, 138 sdbusplus, 139 sdeventplus, 140 ], 141 implicit_include_directories: true, 142 install: true 143) 144 145executable('phosphor-hypervisor-state-manager', 146 'hypervisor_state_manager.cpp', 147 'hypervisor_state_manager_main.cpp', 148 'settings.cpp', 149 dependencies: [ 150 phosphordbusinterfaces, 151 phosphorlogging, 152 sdbusplus, 153 sdeventplus, 154 ], 155 implicit_include_directories: true, 156 install: true 157) 158 159executable('phosphor-chassis-state-manager', 160 'chassis_state_manager.cpp', 161 'chassis_state_manager_main.cpp', 162 'utils.cpp', 163 dependencies: [ 164 cereal, 165 libgpiod, 166 nlohmann_json_dep, 167 phosphordbusinterfaces, 168 phosphorlogging, 169 sdbusplus, 170 sdeventplus, 171 ], 172 implicit_include_directories: true, 173 install: true 174) 175 176executable('phosphor-chassis-check-power-status', 177 'chassis_check_power_status.cpp', 178 'utils.cpp', 179 dependencies: [ 180 libgpiod, 181 phosphordbusinterfaces, 182 phosphorlogging, 183 sdbusplus, 184 ], 185 implicit_include_directories: true, 186 install: true 187) 188 189executable('phosphor-bmc-state-manager', 190 'bmc_state_manager.cpp', 191 'bmc_state_manager_main.cpp', 192 'utils.cpp', 193 dependencies: [ 194 libgpiod, 195 phosphordbusinterfaces, 196 phosphorlogging, 197 sdbusplus, 198 sdeventplus, 199 ], 200 implicit_include_directories: true, 201 install: true 202) 203 204executable('phosphor-discover-system-state', 205 'discover_system_state.cpp', 206 'settings.cpp', 207 'utils.cpp', 208 dependencies: [ 209 cereal, 210 libgpiod, 211 phosphorlogging, 212 sdbusplus, 213 ], 214 implicit_include_directories: true, 215 install: true 216) 217 218executable('phosphor-systemd-target-monitor', 219 'systemd_service_parser.cpp', 220 'systemd_target_monitor.cpp', 221 'systemd_target_parser.cpp', 222 'systemd_target_signal.cpp', 223 'utils.cpp', 224 dependencies: [ 225 CLI11, 226 libgpiod, 227 nlohmann_json_dep, 228 phosphorlogging, 229 sdbusplus, 230 sdeventplus, 231 ], 232 implicit_include_directories: true, 233 install: true 234) 235 236executable('phosphor-scheduled-host-transition', 237 'scheduled_host_transition_main.cpp', 238 'scheduled_host_transition.cpp', 239 'utils.cpp', 240 dependencies: [ 241 cereal, 242 libgpiod, 243 phosphorlogging, 244 sdbusplus, 245 sdeventplus, 246 ], 247 implicit_include_directories: true, 248 install: true 249) 250 251executable('phosphor-host-reset-recovery', 252 'host_reset_recovery.cpp', 253 dependencies: [ 254 phosphorlogging, 255 sdbusplus, 256 ], 257 implicit_include_directories: true, 258 install: true 259) 260 261executable('phosphor-secure-boot-check', 262 'secure_boot_check.cpp', 263 'utils.cpp', 264 dependencies: [ 265 sdbusplus, 266 phosphorlogging, libgpiod 267 ], 268 implicit_include_directories: true, 269 install: true 270) 271 272install_data('obmcutil', 273 install_mode: 'rwxr-xr-x', 274 install_dir: get_option('bindir') 275) 276 277install_data('scripts/host-reboot', 278 install_mode: 'rwxr-xr-x', 279 install_dir: get_option('libexecdir') 280) 281 282systemd = dependency('systemd') 283systemd_system_unit_dir = systemd.get_variable( 284 'systemdsystemunitdir') 285subdir('service_files') 286subdir('target_files') 287 288if build_host_gpios.allowed() 289 subdir('host_condition_gpio') 290endif 291 292datadir = join_paths( 293 get_option('sysconfdir'), 294 'phosphor-systemd-target-monitor' 295) 296subdir('data') 297 298build_tests = get_option('tests') 299 300# If test coverage of source files within the root directory are wanted, 301# need to define and build the tests from here 302if not build_tests.disabled() 303gtest = dependency('gtest', main: true, disabler: true, required: build_tests) 304gmock = dependency('gmock', disabler: true, required: build_tests) 305 test( 306 'test_systemd_parser', 307 executable('test_systemd_parser', 308 './test/systemd_parser.cpp', 309 'systemd_target_parser.cpp', 310 dependencies: [ 311 gtest, 312 nlohmann_json_dep, 313 ], 314 implicit_include_directories: true, 315 include_directories: '../' 316 ) 317 ) 318 319 test( 320 'test_systemd_signal', 321 executable('test_systemd_signal', 322 './test/systemd_signal.cpp', 323 'systemd_target_signal.cpp', 324 'utils.cpp', 325 dependencies: [ 326 gtest, 327 libgpiod, 328 nlohmann_json_dep, 329 phosphorlogging, 330 sdbusplus, 331 sdeventplus, 332 ], 333 implicit_include_directories: true, 334 include_directories: '../' 335 ) 336 ) 337 338 test( 339 'test_scheduled_host_transition', 340 executable('test_scheduled_host_transition', 341 './test/test_scheduled_host_transition.cpp', 342 'scheduled_host_transition.cpp', 343 'utils.cpp', 344 dependencies: [ 345 cereal, 346 gmock, 347 gtest, 348 libgpiod, 349 phosphorlogging, 350 sdbusplus, 351 sdeventplus, 352 ], 353 implicit_include_directories: true, 354 include_directories: '../' 355 ) 356 ) 357 358 test( 359 'test_hypervisor_state', 360 executable('test_hypervisor_state', 361 './test/hypervisor_state.cpp', 362 'hypervisor_state_manager.cpp', 363 dependencies: [ 364 gtest, 365 phosphorlogging, 366 sdbusplus, 367 sdeventplus, 368 ], 369 implicit_include_directories: true, 370 include_directories: '../' 371 ) 372 ) 373endif 374