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