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