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