1a081956fSMike Cappsproject( 2a081956fSMike Capps 'phosphor-fan-presence', 3a081956fSMike Capps 'cpp', 4a081956fSMike Capps default_options: [ 5a081956fSMike Capps 'warning_level=3', 6a081956fSMike Capps 'werror=true', 7a081956fSMike Capps 'cpp_std=c++20', 8a081956fSMike Capps 'buildtype=debugoptimized', 9a081956fSMike Capps 'prefix=/usr' 10a081956fSMike Capps ], 11a081956fSMike Capps license: 'Apache-2.0', 12a081956fSMike Capps version: '1.0', 13a081956fSMike Capps meson_version: '>=0.57.0', 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 22a081956fSMike Cappsif not meson.get_compiler('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 32a081956fSMike Cappsfmt_dep = dependency('fmt') 33a081956fSMike Cappsjson_dep = declare_dependency() 34a081956fSMike Capps 35a081956fSMike Cappsphosphor_dbus_interfaces_dep = dependency('phosphor-dbus-interfaces') 36a081956fSMike Cappsphosphor_logging_dep = dependency('phosphor-logging') 37a081956fSMike Cappssdbusplus_dep = dependency('sdbusplus') 38a081956fSMike Cappssdeventplus_dep = dependency('sdeventplus') 39a081956fSMike Cappsstdplus_dep = dependency('stdplus') 40a081956fSMike Cappssystemd_dep = dependency('systemd') 41a081956fSMike Capps 42a081956fSMike Cappsif(get_option('tests').enabled()) 43a081956fSMike Capps gmock_dep = dependency('gmock', disabler: true) 44a081956fSMike Capps gtest_dep = dependency('gtest', main: true, disabler: true, required: false) 45a081956fSMike Capps 46a081956fSMike Capps if not gtest_dep.found() or not gmock_dep.found() 47a081956fSMike Capps gtest_proj = import('cmake').subproject('googletest', required: false) 48a081956fSMike Capps if gtest_proj.found() 49a081956fSMike Capps gtest_dep = declare_dependency( 50a081956fSMike Capps dependencies: [ 51a081956fSMike Capps dependency('threads'), 52a081956fSMike Capps gtest_proj.dependency('gtest'), 53a081956fSMike Capps gtest_proj.dependency('gtest_main'), 54a081956fSMike Capps ] 55a081956fSMike Capps ) 56a081956fSMike Capps gmock_dep = gtest_proj.dependency('gmock') 57a081956fSMike Capps else 58a081956fSMike Capps assert( 59a081956fSMike Capps not get_option('tests').enabled(), 60a081956fSMike Capps 'Googletest is required if tests are enabled' 61a081956fSMike Capps ) 62a081956fSMike Capps endif 63a081956fSMike Capps endif 64a081956fSMike Capps subdir('test') 65a081956fSMike Cappsendif 66a081956fSMike Capps 67a081956fSMike Capps 68a081956fSMike Cappsservicedir = systemd_dep.get_variable('systemdsystemunitdir') 69a081956fSMike Cappsusr_share_dir = '/usr/share/phosphor-fan-presence' 70a081956fSMike Capps 71a081956fSMike Cappsconf = configuration_data() 72a081956fSMike Capps 73a081956fSMike Capps# Control 74a081956fSMike Cappsconf.set_quoted( 75a081956fSMike Capps 'CONTROL_PERSIST_ROOT_PATH', get_option('control-persist-root-path')) 76a081956fSMike Cappsconf.set_quoted( 77a081956fSMike Capps 'CONTROL_PERSIST_ROOT_PATH', get_option('control-persist-root-path')) 78a081956fSMike Cappsconf.set_quoted( 79a081956fSMike Capps 'FAN_DEF_YAML_FILE', get_option('fan-def-yaml-file')) 80a081956fSMike Cappsconf.set_quoted( 81a081956fSMike Capps 'FAN_ZONE_YAML_FILE', get_option('fan-zone-yaml-file')) 82a081956fSMike Cappsconf.set_quoted( 83a081956fSMike Capps 'ZONE_EVENTS_YAML_FILE', get_option('zone-events-yaml-file')) 84a081956fSMike Cappsconf.set_quoted( 85a081956fSMike Capps 'ZONE_CONDITIONS_YAML_FILE', get_option('zone-conditions-yaml-file')) 86a081956fSMike Capps 87a081956fSMike Capps# Fan control can be in YAML mode when everything else is in JSON mode 88a081956fSMike Cappscontrol_conf_type = 'yaml' 89a081956fSMike Cappsif get_option('json-config').enabled() and get_option('json-control').enabled() 90a081956fSMike Capps control_conf_type = 'json' 91a081956fSMike Cappsendif 92a081956fSMike Capps 93bf8e56f6SMike Capps# Monitor 94bf8e56f6SMike Cappsconf.set( 95bf8e56f6SMike Capps 'NUM_MONITOR_LOG_ENTRIES', get_option('num-monitor-log-entries')) 96bf8e56f6SMike Cappsconf.set_quoted( 97bf8e56f6SMike Capps 'FAN_MONITOR_YAML_FILE', get_option('fan-monitor-yaml-file')) 98*751c8bebSChau Lyconf.set('DELAY_HOST_CONTROL', get_option('delay-host-control')) 99bf8e56f6SMike Capps 100a081956fSMike Capps# JSON-or-YAML (all programs) 101a081956fSMike Cappsif get_option('json-config').enabled() 102a081956fSMike Capps conf.set('PRESENCE_USE_JSON', '') 103a081956fSMike Capps if control_conf_type == 'json' 104a081956fSMike Capps conf.set('CONTROL_USE_JSON', '') 105a081956fSMike Capps endif 106a081956fSMike Capps conf.set('MONITOR_USE_JSON', '') 107a081956fSMike Capps 108a081956fSMike Capps if not cpp.has_header('nlohmann/json.hpp') 109a081956fSMike Capps json_dep = dependency('nlohmann_json') 110a081956fSMike Capps endif 111a081956fSMike Capps conf_type = 'json' 112a081956fSMike Cappselse 113a081956fSMike Capps conf_type = 'yaml' 114a081956fSMike Cappsendif 115a081956fSMike Capps 116bf8e56f6SMike Capps# Sensor Monitor 117bf8e56f6SMike Cappsconf.set_quoted('SENSOR_MONITOR_PERSIST_ROOT_PATH', 118bf8e56f6SMike Capps get_option('sensor-monitor-persist-root-path')) 119a081956fSMike Capps 120b7dd3e22SMatt Spinlerif get_option('use-host-power-state').enabled() 121a081956fSMike Capps conf.set('ENABLE_HOST_STATE', '') 122a081956fSMike Cappsendif 123a081956fSMike Capps 124a081956fSMike Cappsconf.set( 125a081956fSMike Capps 'SHUTDOWN_ALARM_HARD_SHUTDOWN_DELAY_MS', get_option('sensor-monitor-hard-shutdown-delay')) 126a081956fSMike Cappsconf.set( 127a081956fSMike Capps 'SHUTDOWN_ALARM_SOFT_SHUTDOWN_DELAY_MS', get_option('sensor-monitor-soft-shutdown-delay')) 128a081956fSMike Capps 129bf8e56f6SMike Capps# Presence 130bf8e56f6SMike Cappsconf.set( 131bf8e56f6SMike Capps 'NUM_PRESENCE_LOG_ENTRIES', get_option('num-presence-log-entries')) 132bf8e56f6SMike Cappsconf.set_quoted( 133bf8e56f6SMike Capps 'PRESENCE_YAML_FILE', get_option('presence-config')) 134bf8e56f6SMike Capps 135a081956fSMike Cappsconfigure_file(output: 'config.h', configuration: conf) 136a081956fSMike Capps 137a081956fSMike Capps# Service: [name,[svcfiles]] 138a081956fSMike Cappsservices = [] 139a081956fSMike Capps 140a081956fSMike Cappsif get_option('control-service').enabled() 141a081956fSMike Capps subdir('control') 142a081956fSMike Capps service_files = ['phosphor-fan-control@.service'] 143a081956fSMike Capps if control_conf_type == 'yaml' 144a081956fSMike Capps service_files += 'phosphor-fan-control-init@.service' 145a081956fSMike Capps endif 146a081956fSMike Capps services += [['control', service_files]] 147a081956fSMike Cappsendif 148a081956fSMike Capps 149a081956fSMike Cappsif get_option('monitor-service').enabled() 150a081956fSMike Capps subdir('monitor') 151a081956fSMike Capps service_files = ['phosphor-fan-monitor@.service'] 152a081956fSMike Capps if not get_option('json-config').enabled() 153a081956fSMike Capps service_files += 'phosphor-fan-monitor-init@.service' 154a081956fSMike Capps endif 155a081956fSMike Capps services += [['monitor', service_files]] 156a081956fSMike Cappsendif 157a081956fSMike Capps 158a081956fSMike Cappsif get_option('cooling-type-service').enabled() 159a081956fSMike Capps libevdev_dep = dependency('libevdev') 160a081956fSMike Capps subdir('cooling-type') 161a081956fSMike Cappsendif 162a081956fSMike Capps 163a081956fSMike Cappsif get_option('presence-service').enabled() 164a081956fSMike Capps libevdev_dep = dependency('libevdev') 165a081956fSMike Capps subdir('presence') 166a081956fSMike Capps services += [['presence', ['phosphor-fan-presence-tach@.service']]] 167a081956fSMike Cappsendif 168a081956fSMike Capps 169a081956fSMike Cappsif get_option('sensor-monitor-service').enabled() 170a081956fSMike Capps subdir('sensor-monitor') 171a081956fSMike Capps install_data('sensor-monitor/service_files/sensor-monitor.service', 172a081956fSMike Capps install_dir: servicedir) 173a081956fSMike Cappsendif 174a081956fSMike Capps 175a081956fSMike Cappsforeach service : services 176a081956fSMike Capps this_conf_type = conf_type 177a081956fSMike Capps 178a081956fSMike Capps if service[0] == 'control' 179a081956fSMike Capps this_conf_type = control_conf_type 180a081956fSMike Capps endif 181a081956fSMike Capps 182a081956fSMike Capps foreach service_file : service[1] 183a081956fSMike Capps install_data(service[0] / 'service_files' / this_conf_type / service_file, 184a081956fSMike Capps install_dir: servicedir) 185a081956fSMike Capps endforeach 186a081956fSMike Capps 187a081956fSMike Capps if this_conf_type == 'json' 188a081956fSMike Capps fs = import('fs') 189a081956fSMike Capps dir = meson.current_source_dir() / service[0] / 'config_files' / get_option('machine-name') 190a081956fSMike Capps if fs.is_dir(dir) 191a081956fSMike Capps install_subdir(service[0] / 'config_files' / get_option('machine-name'), 192a081956fSMike Capps install_dir: usr_share_dir / service[0], 193a081956fSMike Capps strip_directory: true) 194a081956fSMike Capps endif 195a081956fSMike Capps endif 196a081956fSMike Cappsendforeach 197a081956fSMike Capps 198