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() |
Konstantin Aladyshev | 31c3ab5 | 2024-04-02 18:26:33 +0300 | [diff] [blame] | 40 | cereal_opts.add_cmake_defines({'BUILD_TESTS': 'OFF', 'SKIP_PERFORMANCE_COMPARISON': 'ON'}) |
Patrick Williams | 1a56c2b | 2023-07-17 12:07:23 -0500 | [diff] [blame] | 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 | |
Patrick Williams | 388fc57 | 2023-11-29 06:43:49 -0600 | [diff] [blame] | 57 | if(get_option('tests').allowed()) |
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( |
Patrick Williams | 388fc57 | 2023-11-29 06:43:49 -0600 | [diff] [blame] | 74 | not get_option('tests').allowed(), |
Mike Capps | a081956 | 2022-06-13 10:17:10 -0400 | [diff] [blame] | 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' |
Patrick Williams | 388fc57 | 2023-11-29 06:43:49 -0600 | [diff] [blame] | 104 | if get_option('json-config').allowed() and get_option('json-control').allowed() |
Mike Capps | a081956 | 2022-06-13 10:17:10 -0400 | [diff] [blame] | 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')) |
Patrick Williams | 388fc57 | 2023-11-29 06:43:49 -0600 | [diff] [blame] | 114 | if get_option('monitor-use-host-state').allowed() |
Chau Ly | fce1490 | 2023-01-13 08:52:33 +0000 | [diff] [blame] | 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) |
Patrick Williams | 388fc57 | 2023-11-29 06:43:49 -0600 | [diff] [blame] | 119 | if get_option('json-config').allowed() |
Mike Capps | a081956 | 2022-06-13 10:17:10 -0400 | [diff] [blame] | 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 | |
Patrick Williams | 388fc57 | 2023-11-29 06:43:49 -0600 | [diff] [blame] | 135 | if get_option('use-host-power-state').allowed() |
Mike Capps | a081956 | 2022-06-13 10:17:10 -0400 | [diff] [blame] | 136 | conf.set('ENABLE_HOST_STATE', '') |
| 137 | endif |
| 138 | |
Jerry C Chen | 35fb3a0 | 2024-08-30 14:54:30 +0800 | [diff] [blame] | 139 | if get_option('skip-power-checking').allowed() |
| 140 | conf.set('SKIP_POWER_CHECKING', '') |
| 141 | endif |
| 142 | |
Mike Capps | a081956 | 2022-06-13 10:17:10 -0400 | [diff] [blame] | 143 | conf.set( |
| 144 | 'SHUTDOWN_ALARM_HARD_SHUTDOWN_DELAY_MS', get_option('sensor-monitor-hard-shutdown-delay')) |
| 145 | conf.set( |
| 146 | 'SHUTDOWN_ALARM_SOFT_SHUTDOWN_DELAY_MS', get_option('sensor-monitor-soft-shutdown-delay')) |
| 147 | |
Mike Capps | bf8e56f | 2022-06-29 14:23:07 -0400 | [diff] [blame] | 148 | # Presence |
| 149 | conf.set( |
| 150 | 'NUM_PRESENCE_LOG_ENTRIES', get_option('num-presence-log-entries')) |
| 151 | conf.set_quoted( |
| 152 | 'PRESENCE_YAML_FILE', get_option('presence-config')) |
| 153 | |
Mike Capps | a081956 | 2022-06-13 10:17:10 -0400 | [diff] [blame] | 154 | configure_file(output: 'config.h', configuration: conf) |
| 155 | |
| 156 | # Service: [name,[svcfiles]] |
| 157 | services = [] |
| 158 | |
Patrick Williams | 388fc57 | 2023-11-29 06:43:49 -0600 | [diff] [blame] | 159 | if get_option('control-service').allowed() |
Mike Capps | a081956 | 2022-06-13 10:17:10 -0400 | [diff] [blame] | 160 | subdir('control') |
| 161 | service_files = ['phosphor-fan-control@.service'] |
| 162 | if control_conf_type == 'yaml' |
| 163 | service_files += 'phosphor-fan-control-init@.service' |
| 164 | endif |
| 165 | services += [['control', service_files]] |
| 166 | endif |
| 167 | |
Patrick Williams | 388fc57 | 2023-11-29 06:43:49 -0600 | [diff] [blame] | 168 | if get_option('monitor-service').allowed() |
Mike Capps | a081956 | 2022-06-13 10:17:10 -0400 | [diff] [blame] | 169 | subdir('monitor') |
| 170 | service_files = ['phosphor-fan-monitor@.service'] |
Patrick Williams | 388fc57 | 2023-11-29 06:43:49 -0600 | [diff] [blame] | 171 | if not get_option('json-config').allowed() |
Mike Capps | a081956 | 2022-06-13 10:17:10 -0400 | [diff] [blame] | 172 | service_files += 'phosphor-fan-monitor-init@.service' |
| 173 | endif |
| 174 | services += [['monitor', service_files]] |
| 175 | endif |
| 176 | |
Patrick Williams | 388fc57 | 2023-11-29 06:43:49 -0600 | [diff] [blame] | 177 | if get_option('cooling-type-service').allowed() |
Mike Capps | a081956 | 2022-06-13 10:17:10 -0400 | [diff] [blame] | 178 | libevdev_dep = dependency('libevdev') |
| 179 | subdir('cooling-type') |
| 180 | endif |
| 181 | |
Patrick Williams | 388fc57 | 2023-11-29 06:43:49 -0600 | [diff] [blame] | 182 | if get_option('presence-service').allowed() |
Mike Capps | a081956 | 2022-06-13 10:17:10 -0400 | [diff] [blame] | 183 | libevdev_dep = dependency('libevdev') |
| 184 | subdir('presence') |
| 185 | services += [['presence', ['phosphor-fan-presence-tach@.service']]] |
| 186 | endif |
| 187 | |
Patrick Williams | 388fc57 | 2023-11-29 06:43:49 -0600 | [diff] [blame] | 188 | if get_option('sensor-monitor-service').allowed() |
Mike Capps | a081956 | 2022-06-13 10:17:10 -0400 | [diff] [blame] | 189 | subdir('sensor-monitor') |
| 190 | install_data('sensor-monitor/service_files/sensor-monitor.service', |
| 191 | install_dir: servicedir) |
| 192 | endif |
| 193 | |
| 194 | foreach service : services |
| 195 | this_conf_type = conf_type |
| 196 | |
| 197 | if service[0] == 'control' |
| 198 | this_conf_type = control_conf_type |
| 199 | endif |
| 200 | |
| 201 | foreach service_file : service[1] |
| 202 | install_data(service[0] / 'service_files' / this_conf_type / service_file, |
| 203 | install_dir: servicedir) |
| 204 | endforeach |
| 205 | |
| 206 | if this_conf_type == 'json' |
| 207 | fs = import('fs') |
| 208 | dir = meson.current_source_dir() / service[0] / 'config_files' / get_option('machine-name') |
| 209 | if fs.is_dir(dir) |
| 210 | install_subdir(service[0] / 'config_files' / get_option('machine-name'), |
| 211 | install_dir: usr_share_dir / service[0], |
| 212 | strip_directory: true) |
| 213 | endif |
| 214 | endif |
| 215 | endforeach |
| 216 | |