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