1a081956fSMike Cappsproject( 2a081956fSMike Capps 'phosphor-fan-presence', 3a081956fSMike Capps 'cpp', 4a081956fSMike Capps default_options: [ 5a081956fSMike Capps 'warning_level=3', 6a081956fSMike Capps 'werror=true', 72fbbae69SPatrick Williams 'cpp_std=c++23', 8a081956fSMike Capps 'buildtype=debugoptimized', 9a081956fSMike Capps 'prefix=/usr' 10a081956fSMike Capps ], 11a081956fSMike Capps license: 'Apache-2.0', 12a081956fSMike Capps version: '1.0', 132fbbae69SPatrick Williams meson_version: '>=1.1.1', 14a081956fSMike Capps) 15a081956fSMike Capps 16a081956fSMike Cappspython_prog = find_program('python3', native: true) 17a081956fSMike Capps 18a081956fSMike Cappscpp = meson.get_compiler('cpp') 19a081956fSMike Capps 20a081956fSMike Cappscli11_dep = dependency('cli11', required: false) 21a081956fSMike Capps 221a56c2bcSPatrick Williamsif not cpp.has_header_symbol( 23a081956fSMike Capps 'CLI/CLI.hpp', 24a081956fSMike Capps 'CLI::App', 25a081956fSMike Capps dependencies: cli11_dep, 26a081956fSMike Capps required: false) 27a081956fSMike Capps cli11_proj = subproject('cli11', required:false) 28a081956fSMike Capps assert(cli11_proj.found(), 'CLI11 is required') 29a081956fSMike Capps cli11_dep = cli11_proj.get_variable('CLI11_dep') 30a081956fSMike Cappsendif 31a081956fSMike Capps 321a56c2bcSPatrick Williamscereal_dep = dependency('cereal', required: false) 331a56c2bcSPatrick Williamshas_cereal = cpp.has_header_symbol( 341a56c2bcSPatrick Williams 'cereal/cereal.hpp', 351a56c2bcSPatrick Williams 'cereal::specialize', 361a56c2bcSPatrick Williams dependencies: cereal_dep, 371a56c2bcSPatrick Williams required: false) 381a56c2bcSPatrick Williamsif not has_cereal 391a56c2bcSPatrick Williams cereal_opts = import('cmake').subproject_options() 401a56c2bcSPatrick Williams cereal_opts.add_cmake_defines({'BUILD_TESTS': 'OFF'}) 411a56c2bcSPatrick Williams cereal_proj = import('cmake').subproject( 421a56c2bcSPatrick Williams 'cereal', 431a56c2bcSPatrick Williams options: cereal_opts, 441a56c2bcSPatrick Williams required: false) 451a56c2bcSPatrick Williams assert(cereal_proj.found(), 'cereal is required') 461a56c2bcSPatrick Williams cereal_dep = cereal_proj.dependency('cereal') 471a56c2bcSPatrick Williamsendif 481a56c2bcSPatrick Williams 4916e512d4SPatrick Williamsif cpp.has_header('nlohmann/json.hpp') 50a081956fSMike Capps json_dep = declare_dependency() 5116e512d4SPatrick Williamselse 5216e512d4SPatrick Williams json_dep = dependency('nlohmann_json') 5316e512d4SPatrick Williamsendif 5416e512d4SPatrick Williams 5516e512d4SPatrick Williamsfmt_dep = dependency('fmt') 56a081956fSMike Capps 57a081956fSMike Cappsphosphor_dbus_interfaces_dep = dependency('phosphor-dbus-interfaces') 58a081956fSMike Cappsphosphor_logging_dep = dependency('phosphor-logging') 59a081956fSMike Cappssdbusplus_dep = dependency('sdbusplus') 60a081956fSMike Cappssdeventplus_dep = dependency('sdeventplus') 61a081956fSMike Cappsstdplus_dep = dependency('stdplus') 62a081956fSMike Cappssystemd_dep = dependency('systemd') 63a081956fSMike Capps 64a081956fSMike Cappsif(get_option('tests').enabled()) 65*023d2c70SMatt Spinler gmock_dep = dependency('gmock', disabler: true, required: false) 66a081956fSMike Capps gtest_dep = dependency('gtest', main: true, disabler: true, required: false) 67a081956fSMike Capps 68a081956fSMike Capps if not gtest_dep.found() or not gmock_dep.found() 69a081956fSMike Capps gtest_proj = import('cmake').subproject('googletest', required: false) 70a081956fSMike Capps if gtest_proj.found() 71a081956fSMike Capps gtest_dep = declare_dependency( 72a081956fSMike Capps dependencies: [ 73a081956fSMike Capps dependency('threads'), 74a081956fSMike Capps gtest_proj.dependency('gtest'), 75a081956fSMike Capps gtest_proj.dependency('gtest_main'), 76a081956fSMike Capps ] 77a081956fSMike Capps ) 78a081956fSMike Capps gmock_dep = gtest_proj.dependency('gmock') 79a081956fSMike Capps else 80a081956fSMike Capps assert( 81a081956fSMike Capps not get_option('tests').enabled(), 82a081956fSMike Capps 'Googletest is required if tests are enabled' 83a081956fSMike Capps ) 84a081956fSMike Capps endif 85a081956fSMike Capps endif 86a081956fSMike Capps subdir('test') 87a081956fSMike Cappsendif 88a081956fSMike Capps 89a081956fSMike Capps 90a081956fSMike Cappsservicedir = systemd_dep.get_variable('systemdsystemunitdir') 91a081956fSMike Cappsusr_share_dir = '/usr/share/phosphor-fan-presence' 92a081956fSMike Capps 93a081956fSMike Cappsconf = configuration_data() 94a081956fSMike Capps 95a081956fSMike Capps# Control 96a081956fSMike Cappsconf.set_quoted( 97a081956fSMike Capps 'CONTROL_PERSIST_ROOT_PATH', get_option('control-persist-root-path')) 98a081956fSMike Cappsconf.set_quoted( 99a081956fSMike Capps 'CONTROL_PERSIST_ROOT_PATH', get_option('control-persist-root-path')) 100a081956fSMike Cappsconf.set_quoted( 101a081956fSMike Capps 'FAN_DEF_YAML_FILE', get_option('fan-def-yaml-file')) 102a081956fSMike Cappsconf.set_quoted( 103a081956fSMike Capps 'FAN_ZONE_YAML_FILE', get_option('fan-zone-yaml-file')) 104a081956fSMike Cappsconf.set_quoted( 105a081956fSMike Capps 'ZONE_EVENTS_YAML_FILE', get_option('zone-events-yaml-file')) 106a081956fSMike Cappsconf.set_quoted( 107a081956fSMike Capps 'ZONE_CONDITIONS_YAML_FILE', get_option('zone-conditions-yaml-file')) 108a081956fSMike Capps 109a081956fSMike Capps# Fan control can be in YAML mode when everything else is in JSON mode 110a081956fSMike Cappscontrol_conf_type = 'yaml' 111a081956fSMike Cappsif get_option('json-config').enabled() and get_option('json-control').enabled() 112a081956fSMike Capps control_conf_type = 'json' 113a081956fSMike Cappsendif 114a081956fSMike Capps 115bf8e56f6SMike Capps# Monitor 116bf8e56f6SMike Cappsconf.set( 117bf8e56f6SMike Capps 'NUM_MONITOR_LOG_ENTRIES', get_option('num-monitor-log-entries')) 118bf8e56f6SMike Cappsconf.set_quoted( 119bf8e56f6SMike Capps 'FAN_MONITOR_YAML_FILE', get_option('fan-monitor-yaml-file')) 120751c8bebSChau Lyconf.set('DELAY_HOST_CONTROL', get_option('delay-host-control')) 121fce14908SChau Lyif get_option('monitor-use-host-state').enabled() 122fce14908SChau Ly conf.set('MONITOR_USE_HOST_STATE', '') 123fce14908SChau Lyendif 124bf8e56f6SMike Capps 125a081956fSMike Capps# JSON-or-YAML (all programs) 126a081956fSMike Cappsif get_option('json-config').enabled() 127a081956fSMike Capps conf.set('PRESENCE_USE_JSON', '') 128a081956fSMike Capps if control_conf_type == 'json' 129a081956fSMike Capps conf.set('CONTROL_USE_JSON', '') 130a081956fSMike Capps endif 131a081956fSMike Capps conf.set('MONITOR_USE_JSON', '') 132a081956fSMike Capps 133a081956fSMike Capps conf_type = 'json' 134a081956fSMike Cappselse 135a081956fSMike Capps conf_type = 'yaml' 136a081956fSMike Cappsendif 137a081956fSMike Capps 138bf8e56f6SMike Capps# Sensor Monitor 139bf8e56f6SMike Cappsconf.set_quoted('SENSOR_MONITOR_PERSIST_ROOT_PATH', 140bf8e56f6SMike Capps get_option('sensor-monitor-persist-root-path')) 141a081956fSMike Capps 142b7dd3e22SMatt Spinlerif get_option('use-host-power-state').enabled() 143a081956fSMike Capps conf.set('ENABLE_HOST_STATE', '') 144a081956fSMike Cappsendif 145a081956fSMike Capps 146a081956fSMike Cappsconf.set( 147a081956fSMike Capps 'SHUTDOWN_ALARM_HARD_SHUTDOWN_DELAY_MS', get_option('sensor-monitor-hard-shutdown-delay')) 148a081956fSMike Cappsconf.set( 149a081956fSMike Capps 'SHUTDOWN_ALARM_SOFT_SHUTDOWN_DELAY_MS', get_option('sensor-monitor-soft-shutdown-delay')) 150a081956fSMike Capps 151bf8e56f6SMike Capps# Presence 152bf8e56f6SMike Cappsconf.set( 153bf8e56f6SMike Capps 'NUM_PRESENCE_LOG_ENTRIES', get_option('num-presence-log-entries')) 154bf8e56f6SMike Cappsconf.set_quoted( 155bf8e56f6SMike Capps 'PRESENCE_YAML_FILE', get_option('presence-config')) 156bf8e56f6SMike Capps 157a081956fSMike Cappsconfigure_file(output: 'config.h', configuration: conf) 158a081956fSMike Capps 159a081956fSMike Capps# Service: [name,[svcfiles]] 160a081956fSMike Cappsservices = [] 161a081956fSMike Capps 162a081956fSMike Cappsif get_option('control-service').enabled() 163a081956fSMike Capps subdir('control') 164a081956fSMike Capps service_files = ['phosphor-fan-control@.service'] 165a081956fSMike Capps if control_conf_type == 'yaml' 166a081956fSMike Capps service_files += 'phosphor-fan-control-init@.service' 167a081956fSMike Capps endif 168a081956fSMike Capps services += [['control', service_files]] 169a081956fSMike Cappsendif 170a081956fSMike Capps 171a081956fSMike Cappsif get_option('monitor-service').enabled() 172a081956fSMike Capps subdir('monitor') 173a081956fSMike Capps service_files = ['phosphor-fan-monitor@.service'] 174a081956fSMike Capps if not get_option('json-config').enabled() 175a081956fSMike Capps service_files += 'phosphor-fan-monitor-init@.service' 176a081956fSMike Capps endif 177a081956fSMike Capps services += [['monitor', service_files]] 178a081956fSMike Cappsendif 179a081956fSMike Capps 180a081956fSMike Cappsif get_option('cooling-type-service').enabled() 181a081956fSMike Capps libevdev_dep = dependency('libevdev') 182a081956fSMike Capps subdir('cooling-type') 183a081956fSMike Cappsendif 184a081956fSMike Capps 185a081956fSMike Cappsif get_option('presence-service').enabled() 186a081956fSMike Capps libevdev_dep = dependency('libevdev') 187a081956fSMike Capps subdir('presence') 188a081956fSMike Capps services += [['presence', ['phosphor-fan-presence-tach@.service']]] 189a081956fSMike Cappsendif 190a081956fSMike Capps 191a081956fSMike Cappsif get_option('sensor-monitor-service').enabled() 192a081956fSMike Capps subdir('sensor-monitor') 193a081956fSMike Capps install_data('sensor-monitor/service_files/sensor-monitor.service', 194a081956fSMike Capps install_dir: servicedir) 195a081956fSMike Cappsendif 196a081956fSMike Capps 197a081956fSMike Cappsforeach service : services 198a081956fSMike Capps this_conf_type = conf_type 199a081956fSMike Capps 200a081956fSMike Capps if service[0] == 'control' 201a081956fSMike Capps this_conf_type = control_conf_type 202a081956fSMike Capps endif 203a081956fSMike Capps 204a081956fSMike Capps foreach service_file : service[1] 205a081956fSMike Capps install_data(service[0] / 'service_files' / this_conf_type / service_file, 206a081956fSMike Capps install_dir: servicedir) 207a081956fSMike Capps endforeach 208a081956fSMike Capps 209a081956fSMike Capps if this_conf_type == 'json' 210a081956fSMike Capps fs = import('fs') 211a081956fSMike Capps dir = meson.current_source_dir() / service[0] / 'config_files' / get_option('machine-name') 212a081956fSMike Capps if fs.is_dir(dir) 213a081956fSMike Capps install_subdir(service[0] / 'config_files' / get_option('machine-name'), 214a081956fSMike Capps install_dir: usr_share_dir / service[0], 215a081956fSMike Capps strip_directory: true) 216a081956fSMike Capps endif 217a081956fSMike Capps endif 218a081956fSMike Cappsendforeach 219a081956fSMike Capps 220