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