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