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'}) 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 139conf.set( 140 'SHUTDOWN_ALARM_HARD_SHUTDOWN_DELAY_MS', get_option('sensor-monitor-hard-shutdown-delay')) 141conf.set( 142 'SHUTDOWN_ALARM_SOFT_SHUTDOWN_DELAY_MS', get_option('sensor-monitor-soft-shutdown-delay')) 143 144# Presence 145conf.set( 146 'NUM_PRESENCE_LOG_ENTRIES', get_option('num-presence-log-entries')) 147conf.set_quoted( 148 'PRESENCE_YAML_FILE', get_option('presence-config')) 149 150configure_file(output: 'config.h', configuration: conf) 151 152# Service: [name,[svcfiles]] 153services = [] 154 155if get_option('control-service').allowed() 156 subdir('control') 157 service_files = ['phosphor-fan-control@.service'] 158 if control_conf_type == 'yaml' 159 service_files += 'phosphor-fan-control-init@.service' 160 endif 161 services += [['control', service_files]] 162endif 163 164if get_option('monitor-service').allowed() 165 subdir('monitor') 166 service_files = ['phosphor-fan-monitor@.service'] 167 if not get_option('json-config').allowed() 168 service_files += 'phosphor-fan-monitor-init@.service' 169 endif 170 services += [['monitor', service_files]] 171endif 172 173if get_option('cooling-type-service').allowed() 174 libevdev_dep = dependency('libevdev') 175 subdir('cooling-type') 176endif 177 178if get_option('presence-service').allowed() 179 libevdev_dep = dependency('libevdev') 180 subdir('presence') 181 services += [['presence', ['phosphor-fan-presence-tach@.service']]] 182endif 183 184if get_option('sensor-monitor-service').allowed() 185 subdir('sensor-monitor') 186 install_data('sensor-monitor/service_files/sensor-monitor.service', 187 install_dir: servicedir) 188endif 189 190foreach service : services 191 this_conf_type = conf_type 192 193 if service[0] == 'control' 194 this_conf_type = control_conf_type 195 endif 196 197 foreach service_file : service[1] 198 install_data(service[0] / 'service_files' / this_conf_type / service_file, 199 install_dir: servicedir) 200 endforeach 201 202 if this_conf_type == 'json' 203 fs = import('fs') 204 dir = meson.current_source_dir() / service[0] / 'config_files' / get_option('machine-name') 205 if fs.is_dir(dir) 206 install_subdir(service[0] / 'config_files' / get_option('machine-name'), 207 install_dir: usr_share_dir / service[0], 208 strip_directory: true) 209 endif 210 endif 211endforeach 212 213