1project( 2 'phosphor-fan-presence', 3 'cpp', 4 default_options: [ 5 'warning_level=3', 6 'werror=true', 7 'cpp_std=c++23', 8 'buildtype=debugoptimized', 9 'prefix=/usr' 10 ], 11 license: 'Apache-2.0', 12 version: '1.0', 13 meson_version: '>=1.1.1', 14) 15 16python_prog = find_program('python3', native: true) 17 18cpp = meson.get_compiler('cpp') 19 20cli11_dep = dependency('cli11', required: false) 21 22if not cpp.has_header_symbol( 23 'CLI/CLI.hpp', 24 'CLI::App', 25 dependencies: cli11_dep, 26 required: false) 27 cli11_proj = subproject('cli11', required:false) 28 assert(cli11_proj.found(), 'CLI11 is required') 29 cli11_dep = cli11_proj.get_variable('CLI11_dep') 30endif 31 32cereal_dep = dependency('cereal', required: false) 33has_cereal = cpp.has_header_symbol( 34 'cereal/cereal.hpp', 35 'cereal::specialize', 36 dependencies: cereal_dep, 37 required: false) 38if not has_cereal 39 cereal_opts = import('cmake').subproject_options() 40 cereal_opts.add_cmake_defines({'BUILD_TESTS': 'OFF', 'SKIP_PERFORMANCE_COMPARISON': 'ON'}) 41 cereal_proj = import('cmake').subproject( 42 'cereal', 43 options: cereal_opts, 44 required: false) 45 assert(cereal_proj.found(), 'cereal is required') 46 cereal_dep = cereal_proj.dependency('cereal') 47endif 48 49nlohmann_json_dep = dependency('nlohmann_json', include_type: 'system') 50phosphor_dbus_interfaces_dep = dependency('phosphor-dbus-interfaces') 51phosphor_logging_dep = dependency('phosphor-logging') 52sdbusplus_dep = dependency('sdbusplus') 53sdeventplus_dep = dependency('sdeventplus') 54stdplus_dep = dependency('stdplus') 55systemd_dep = dependency('systemd') 56 57if(get_option('tests').allowed()) 58 gmock_dep = dependency('gmock', disabler: true, required: false) 59 gtest_dep = dependency('gtest', main: true, disabler: true, required: false) 60 61 if not gtest_dep.found() or not gmock_dep.found() 62 gtest_proj = import('cmake').subproject('googletest', required: false) 63 if gtest_proj.found() 64 gtest_dep = declare_dependency( 65 dependencies: [ 66 dependency('threads'), 67 gtest_proj.dependency('gtest'), 68 gtest_proj.dependency('gtest_main'), 69 ] 70 ) 71 gmock_dep = gtest_proj.dependency('gmock') 72 else 73 assert( 74 not get_option('tests').allowed(), 75 'Googletest is required if tests are enabled' 76 ) 77 endif 78 endif 79 subdir('test') 80endif 81 82 83servicedir = systemd_dep.get_variable('systemdsystemunitdir') 84usr_share_dir = '/usr/share/phosphor-fan-presence' 85 86conf = configuration_data() 87 88# Control 89conf.set_quoted( 90 'CONTROL_PERSIST_ROOT_PATH', get_option('control-persist-root-path')) 91conf.set_quoted( 92 'CONTROL_PERSIST_ROOT_PATH', get_option('control-persist-root-path')) 93conf.set_quoted( 94 'FAN_DEF_YAML_FILE', get_option('fan-def-yaml-file')) 95conf.set_quoted( 96 'FAN_ZONE_YAML_FILE', get_option('fan-zone-yaml-file')) 97conf.set_quoted( 98 'ZONE_EVENTS_YAML_FILE', get_option('zone-events-yaml-file')) 99conf.set_quoted( 100 'ZONE_CONDITIONS_YAML_FILE', get_option('zone-conditions-yaml-file')) 101 102# Fan control can be in YAML mode when everything else is in JSON mode 103control_conf_type = 'yaml' 104if get_option('json-config').allowed() and get_option('json-control').allowed() 105 control_conf_type = 'json' 106endif 107 108# Monitor 109conf.set( 110 'NUM_MONITOR_LOG_ENTRIES', get_option('num-monitor-log-entries')) 111conf.set_quoted( 112 'FAN_MONITOR_YAML_FILE', get_option('fan-monitor-yaml-file')) 113conf.set('DELAY_HOST_CONTROL', get_option('delay-host-control')) 114if get_option('monitor-use-host-state').allowed() 115 conf.set('MONITOR_USE_HOST_STATE', '') 116endif 117 118# JSON-or-YAML (all programs) 119if get_option('json-config').allowed() 120 conf.set('PRESENCE_USE_JSON', '') 121 if control_conf_type == 'json' 122 conf.set('CONTROL_USE_JSON', '') 123 endif 124 conf.set('MONITOR_USE_JSON', '') 125 126 conf_type = 'json' 127else 128 conf_type = 'yaml' 129endif 130 131# Sensor Monitor 132conf.set_quoted('SENSOR_MONITOR_PERSIST_ROOT_PATH', 133 get_option('sensor-monitor-persist-root-path')) 134 135if get_option('use-host-power-state').allowed() 136 conf.set('ENABLE_HOST_STATE', '') 137endif 138 139if get_option('skip-power-checking').allowed() 140 conf.set('SKIP_POWER_CHECKING', '') 141endif 142 143conf.set( 144 'SHUTDOWN_ALARM_HARD_SHUTDOWN_DELAY_MS', get_option('sensor-monitor-hard-shutdown-delay')) 145conf.set( 146 'SHUTDOWN_ALARM_SOFT_SHUTDOWN_DELAY_MS', get_option('sensor-monitor-soft-shutdown-delay')) 147 148# Presence 149conf.set( 150 'NUM_PRESENCE_LOG_ENTRIES', get_option('num-presence-log-entries')) 151conf.set_quoted( 152 'PRESENCE_YAML_FILE', get_option('presence-config')) 153 154configure_file(output: 'config.h', configuration: conf) 155 156# Service: [name,[svcfiles]] 157services = [] 158 159if get_option('control-service').allowed() 160 subdir('control') 161 service_files = ['phosphor-fan-control@.service'] 162 if control_conf_type == 'yaml' 163 service_files += 'phosphor-fan-control-init@.service' 164 endif 165 services += [['control', service_files]] 166endif 167 168if get_option('monitor-service').allowed() 169 subdir('monitor') 170 service_files = ['phosphor-fan-monitor@.service'] 171 if not get_option('json-config').allowed() 172 service_files += 'phosphor-fan-monitor-init@.service' 173 endif 174 services += [['monitor', service_files]] 175endif 176 177if get_option('cooling-type-service').allowed() 178 libevdev_dep = dependency('libevdev') 179 subdir('cooling-type') 180endif 181 182if get_option('presence-service').allowed() 183 libevdev_dep = dependency('libevdev') 184 subdir('presence') 185 services += [['presence', ['phosphor-fan-presence-tach@.service']]] 186endif 187 188if get_option('sensor-monitor-service').allowed() 189 subdir('sensor-monitor') 190 install_data('sensor-monitor/service_files/sensor-monitor.service', 191 install_dir: servicedir) 192endif 193 194foreach service : services 195 this_conf_type = conf_type 196 197 if service[0] == 'control' 198 this_conf_type = control_conf_type 199 endif 200 201 foreach service_file : service[1] 202 install_data(service[0] / 'service_files' / this_conf_type / service_file, 203 install_dir: servicedir) 204 endforeach 205 206 if this_conf_type == 'json' 207 fs = import('fs') 208 dir = meson.current_source_dir() / service[0] / 'config_files' / get_option('machine-name') 209 if fs.is_dir(dir) 210 install_subdir(service[0] / 'config_files' / get_option('machine-name'), 211 install_dir: usr_share_dir / service[0], 212 strip_directory: true) 213 endif 214 endif 215endforeach 216 217