Mike Capps | a081956 | 2022-06-13 10:17:10 -0400 | [diff] [blame] | 1 | project( |
| 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 | |
| 16 | python_prog = find_program('python3', native: true) |
| 17 | |
| 18 | cpp = meson.get_compiler('cpp') |
| 19 | |
| 20 | cli11_dep = dependency('cli11', required: false) |
| 21 | |
| 22 | if 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') |
| 30 | endif |
| 31 | |
| 32 | fmt_dep = dependency('fmt') |
| 33 | json_dep = declare_dependency() |
| 34 | |
| 35 | phosphor_dbus_interfaces_dep = dependency('phosphor-dbus-interfaces') |
| 36 | phosphor_logging_dep = dependency('phosphor-logging') |
| 37 | sdbusplus_dep = dependency('sdbusplus') |
| 38 | sdeventplus_dep = dependency('sdeventplus') |
| 39 | stdplus_dep = dependency('stdplus') |
| 40 | systemd_dep = dependency('systemd') |
| 41 | |
| 42 | if(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') |
| 65 | endif |
| 66 | |
| 67 | |
| 68 | servicedir = systemd_dep.get_variable('systemdsystemunitdir') |
| 69 | usr_share_dir = '/usr/share/phosphor-fan-presence' |
| 70 | |
| 71 | conf = configuration_data() |
| 72 | |
| 73 | # Control |
| 74 | conf.set_quoted( |
| 75 | 'CONTROL_PERSIST_ROOT_PATH', get_option('control-persist-root-path')) |
| 76 | conf.set_quoted( |
Mike Capps | a081956 | 2022-06-13 10:17:10 -0400 | [diff] [blame] | 77 | 'CONTROL_PERSIST_ROOT_PATH', get_option('control-persist-root-path')) |
Mike Capps | a081956 | 2022-06-13 10:17:10 -0400 | [diff] [blame] | 78 | conf.set_quoted( |
| 79 | 'FAN_DEF_YAML_FILE', get_option('fan-def-yaml-file')) |
| 80 | conf.set_quoted( |
| 81 | 'FAN_ZONE_YAML_FILE', get_option('fan-zone-yaml-file')) |
| 82 | conf.set_quoted( |
| 83 | 'ZONE_EVENTS_YAML_FILE', get_option('zone-events-yaml-file')) |
| 84 | conf.set_quoted( |
| 85 | 'ZONE_CONDITIONS_YAML_FILE', get_option('zone-conditions-yaml-file')) |
| 86 | |
Mike Capps | a081956 | 2022-06-13 10:17:10 -0400 | [diff] [blame] | 87 | # Fan control can be in YAML mode when everything else is in JSON mode |
| 88 | control_conf_type = 'yaml' |
| 89 | if get_option('json-config').enabled() and get_option('json-control').enabled() |
| 90 | control_conf_type = 'json' |
| 91 | endif |
| 92 | |
Mike Capps | bf8e56f | 2022-06-29 14:23:07 -0400 | [diff] [blame] | 93 | # Monitor |
| 94 | conf.set( |
| 95 | 'NUM_MONITOR_LOG_ENTRIES', get_option('num-monitor-log-entries')) |
| 96 | conf.set_quoted( |
| 97 | 'FAN_MONITOR_YAML_FILE', get_option('fan-monitor-yaml-file')) |
| 98 | |
Mike Capps | a081956 | 2022-06-13 10:17:10 -0400 | [diff] [blame] | 99 | # JSON-or-YAML (all programs) |
| 100 | if 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' |
| 111 | else |
| 112 | conf_type = 'yaml' |
| 113 | endif |
| 114 | |
Mike Capps | bf8e56f | 2022-06-29 14:23:07 -0400 | [diff] [blame] | 115 | # Sensor Monitor |
| 116 | conf.set_quoted('SENSOR_MONITOR_PERSIST_ROOT_PATH', |
| 117 | get_option('sensor-monitor-persist-root-path')) |
Mike Capps | a081956 | 2022-06-13 10:17:10 -0400 | [diff] [blame] | 118 | |
Matt Spinler | b7dd3e2 | 2022-08-19 11:33:02 -0500 | [diff] [blame] | 119 | if get_option('use-host-power-state').enabled() |
Mike Capps | a081956 | 2022-06-13 10:17:10 -0400 | [diff] [blame] | 120 | conf.set('ENABLE_HOST_STATE', '') |
| 121 | endif |
| 122 | |
Mike Capps | a081956 | 2022-06-13 10:17:10 -0400 | [diff] [blame] | 123 | conf.set( |
| 124 | 'SHUTDOWN_ALARM_HARD_SHUTDOWN_DELAY_MS', get_option('sensor-monitor-hard-shutdown-delay')) |
| 125 | conf.set( |
| 126 | 'SHUTDOWN_ALARM_SOFT_SHUTDOWN_DELAY_MS', get_option('sensor-monitor-soft-shutdown-delay')) |
| 127 | |
Mike Capps | bf8e56f | 2022-06-29 14:23:07 -0400 | [diff] [blame] | 128 | # Presence |
| 129 | conf.set( |
| 130 | 'NUM_PRESENCE_LOG_ENTRIES', get_option('num-presence-log-entries')) |
| 131 | conf.set_quoted( |
| 132 | 'PRESENCE_YAML_FILE', get_option('presence-config')) |
| 133 | |
Mike Capps | a081956 | 2022-06-13 10:17:10 -0400 | [diff] [blame] | 134 | configure_file(output: 'config.h', configuration: conf) |
| 135 | |
| 136 | # Service: [name,[svcfiles]] |
| 137 | services = [] |
| 138 | |
| 139 | if 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]] |
| 146 | endif |
| 147 | |
| 148 | if 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]] |
| 155 | endif |
| 156 | |
| 157 | if get_option('cooling-type-service').enabled() |
| 158 | libevdev_dep = dependency('libevdev') |
| 159 | subdir('cooling-type') |
| 160 | endif |
| 161 | |
| 162 | if get_option('presence-service').enabled() |
| 163 | libevdev_dep = dependency('libevdev') |
| 164 | subdir('presence') |
| 165 | services += [['presence', ['phosphor-fan-presence-tach@.service']]] |
| 166 | endif |
| 167 | |
| 168 | if get_option('sensor-monitor-service').enabled() |
| 169 | subdir('sensor-monitor') |
| 170 | install_data('sensor-monitor/service_files/sensor-monitor.service', |
| 171 | install_dir: servicedir) |
| 172 | endif |
| 173 | |
| 174 | foreach 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 |
| 195 | endforeach |
| 196 | |