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 129settings_lib = static_library( 130 'settings', 131 'settings.cpp', 132 dependencies: [sdbusplus, phosphorlogging, phosphordbusinterfaces], 133) 134 135utils_lib = static_library( 136 'utils', 137 'utils.cpp', 138 dependencies: [sdbusplus, phosphorlogging, phosphordbusinterfaces, libgpiod], 139) 140 141executable( 142 'phosphor-host-state-manager', 143 'host_state_manager.cpp', 144 'host_state_manager_main.cpp', 145 'host_check.cpp', 146 dependencies: [ 147 cereal, 148 libgpiod, 149 phosphordbusinterfaces, 150 phosphorlogging, 151 sdbusplus, 152 sdeventplus, 153 ], 154 link_with: [settings_lib, utils_lib], 155 implicit_include_directories: true, 156 install: true, 157) 158 159executable( 160 'phosphor-hypervisor-state-manager', 161 'hypervisor_state_manager.cpp', 162 'hypervisor_state_manager_main.cpp', 163 dependencies: [ 164 phosphordbusinterfaces, 165 phosphorlogging, 166 sdbusplus, 167 sdeventplus, 168 ], 169 link_with: [settings_lib], 170 implicit_include_directories: true, 171 install: true, 172) 173 174executable( 175 'phosphor-chassis-state-manager', 176 'chassis_state_manager.cpp', 177 'chassis_state_manager_main.cpp', 178 dependencies: [ 179 cereal, 180 libgpiod, 181 nlohmann_json_dep, 182 phosphordbusinterfaces, 183 phosphorlogging, 184 sdbusplus, 185 sdeventplus, 186 ], 187 link_with: [utils_lib], 188 implicit_include_directories: true, 189 install: true, 190) 191 192executable( 193 'phosphor-chassis-check-power-status', 194 'chassis_check_power_status.cpp', 195 dependencies: [libgpiod, phosphordbusinterfaces, phosphorlogging, sdbusplus], 196 link_with: [utils_lib], 197 implicit_include_directories: true, 198 install: true, 199) 200 201executable( 202 'phosphor-bmc-state-manager', 203 'bmc_state_manager.cpp', 204 'bmc_state_manager_main.cpp', 205 dependencies: [ 206 libgpiod, 207 phosphordbusinterfaces, 208 phosphorlogging, 209 sdbusplus, 210 sdeventplus, 211 ], 212 link_with: [utils_lib], 213 implicit_include_directories: true, 214 install: true, 215) 216 217executable( 218 'phosphor-discover-system-state', 219 'discover_system_state.cpp', 220 dependencies: [cereal, libgpiod, phosphorlogging, sdbusplus], 221 link_with: [settings_lib, utils_lib], 222 implicit_include_directories: true, 223 install: true, 224) 225 226executable( 227 'phosphor-systemd-target-monitor', 228 'systemd_service_parser.cpp', 229 'systemd_target_monitor.cpp', 230 'systemd_target_parser.cpp', 231 'systemd_target_signal.cpp', 232 dependencies: [ 233 CLI11, 234 libgpiod, 235 nlohmann_json_dep, 236 phosphorlogging, 237 sdbusplus, 238 sdeventplus, 239 ], 240 link_with: [utils_lib], 241 implicit_include_directories: true, 242 install: true, 243) 244 245executable( 246 'phosphor-scheduled-host-transition', 247 'scheduled_host_transition_main.cpp', 248 'scheduled_host_transition.cpp', 249 dependencies: [cereal, libgpiod, phosphorlogging, sdbusplus, sdeventplus], 250 link_with: [utils_lib], 251 implicit_include_directories: true, 252 install: true, 253) 254 255executable( 256 'phosphor-host-reset-recovery', 257 'host_reset_recovery.cpp', 258 dependencies: [phosphorlogging, sdbusplus], 259 implicit_include_directories: true, 260 install: true, 261) 262 263executable( 264 'phosphor-secure-boot-check', 265 'secure_boot_check.cpp', 266 dependencies: [sdbusplus, phosphorlogging, libgpiod], 267 link_with: [utils_lib], 268 implicit_include_directories: true, 269 install: true, 270) 271 272if get_option('install-utils').allowed() 273 install_data( 274 'obmcutil', 275 install_mode: 'rwxr-xr-x', 276 install_dir: get_option('bindir'), 277 ) 278endif 279 280install_data( 281 'scripts/host-reboot', 282 install_mode: 'rwxr-xr-x', 283 install_dir: get_option('libexecdir') / 'phosphor-state-manager', 284) 285 286systemd = dependency('systemd') 287systemd_system_unit_dir = systemd.get_variable('systemd_system_unit_dir') 288subdir('service_files') 289subdir('target_files') 290 291if build_host_gpios.allowed() 292 subdir('host_condition_gpio') 293endif 294 295datadir = join_paths(get_option('sysconfdir'), 'phosphor-systemd-target-monitor') 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 build_tests.allowed() 303 gtest = dependency('gtest', main: true, disabler: true, required: false) 304 gmock = dependency('gmock', disabler: true, required: false) 305 306 if not gtest.found() or not gmock.found() 307 gtest_proj = import('cmake').subproject('googletest', required: false) 308 if gtest_proj.found() 309 gtest = declare_dependency( 310 dependencies: [ 311 dependency('threads'), 312 gtest_proj.dependency('gtest'), 313 gtest_proj.dependency('gtest_main'), 314 ], 315 ) 316 gmock = gtest_proj.dependency('gmock') 317 else 318 assert( 319 not get_option('tests').enabled(), 320 'Googletest is required if tests are enabled', 321 ) 322 endif 323 endif 324 325 subdir('test') 326endif 327