1project( 2 'phosphor-fan-presence', 3 'cpp', 4 default_options: [ 5 'warning_level=3', 6 'werror=true', 7 'cpp_std=c++20', 8 'buildtype=debugoptimized', 9 'prefix=/usr' 10 ], 11 license: 'Apache-2.0', 12 version: '1.0', 13 meson_version: '>=0.57.0', 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')) 98 99# JSON-or-YAML (all programs) 100if get_option('json-config').enabled() 101 conf.set('PRESENCE_USE_JSON', '') 102 if control_conf_type == 'json' 103 conf.set('CONTROL_USE_JSON', '') 104 endif 105 conf.set('MONITOR_USE_JSON', '') 106 107 if not cpp.has_header('nlohmann/json.hpp') 108 json_dep = dependency('nlohmann_json') 109 endif 110 conf_type = 'json' 111else 112 conf_type = 'yaml' 113endif 114 115# Sensor Monitor 116conf.set_quoted('SENSOR_MONITOR_PERSIST_ROOT_PATH', 117 get_option('sensor-monitor-persist-root-path')) 118 119if get_option('use-host-power-state').enabled() 120 conf.set('ENABLE_HOST_STATE', '') 121endif 122 123conf.set( 124 'SHUTDOWN_ALARM_HARD_SHUTDOWN_DELAY_MS', get_option('sensor-monitor-hard-shutdown-delay')) 125conf.set( 126 'SHUTDOWN_ALARM_SOFT_SHUTDOWN_DELAY_MS', get_option('sensor-monitor-soft-shutdown-delay')) 127 128# Presence 129conf.set( 130 'NUM_PRESENCE_LOG_ENTRIES', get_option('num-presence-log-entries')) 131conf.set_quoted( 132 'PRESENCE_YAML_FILE', get_option('presence-config')) 133 134configure_file(output: 'config.h', configuration: conf) 135 136# Service: [name,[svcfiles]] 137services = [] 138 139if get_option('control-service').enabled() 140 subdir('control') 141 service_files = ['phosphor-fan-control@.service'] 142 if control_conf_type == 'yaml' 143 service_files += 'phosphor-fan-control-init@.service' 144 endif 145 services += [['control', service_files]] 146endif 147 148if get_option('monitor-service').enabled() 149 subdir('monitor') 150 service_files = ['phosphor-fan-monitor@.service'] 151 if not get_option('json-config').enabled() 152 service_files += 'phosphor-fan-monitor-init@.service' 153 endif 154 services += [['monitor', service_files]] 155endif 156 157if get_option('cooling-type-service').enabled() 158 libevdev_dep = dependency('libevdev') 159 subdir('cooling-type') 160endif 161 162if get_option('presence-service').enabled() 163 libevdev_dep = dependency('libevdev') 164 subdir('presence') 165 services += [['presence', ['phosphor-fan-presence-tach@.service']]] 166endif 167 168if get_option('sensor-monitor-service').enabled() 169 subdir('sensor-monitor') 170 install_data('sensor-monitor/service_files/sensor-monitor.service', 171 install_dir: servicedir) 172endif 173 174foreach service : services 175 this_conf_type = conf_type 176 177 if service[0] == 'control' 178 this_conf_type = control_conf_type 179 endif 180 181 foreach service_file : service[1] 182 install_data(service[0] / 'service_files' / this_conf_type / service_file, 183 install_dir: servicedir) 184 endforeach 185 186 if this_conf_type == 'json' 187 fs = import('fs') 188 dir = meson.current_source_dir() / service[0] / 'config_files' / get_option('machine-name') 189 if fs.is_dir(dir) 190 install_subdir(service[0] / 'config_files' / get_option('machine-name'), 191 install_dir: usr_share_dir / service[0], 192 strip_directory: true) 193 endif 194 endif 195endforeach 196 197