blob: 5d8e3fdc2b429aace4ed2aef86c261a8ac24dc0f [file] [log] [blame]
Mike Cappsa0819562022-06-13 10:17:10 -04001project(
2 'phosphor-fan-presence',
3 'cpp',
4 default_options: [
5 'warning_level=3',
6 'werror=true',
Patrick Williams2fbbae62023-07-12 11:15:09 -05007 'cpp_std=c++23',
Mike Cappsa0819562022-06-13 10:17:10 -04008 'buildtype=debugoptimized',
Patrick Williamsf5f87ca2025-02-01 08:36:20 -05009 'prefix=/usr',
Mike Cappsa0819562022-06-13 10:17:10 -040010 ],
11 license: 'Apache-2.0',
12 version: '1.0',
Patrick Williams2fbbae62023-07-12 11:15:09 -050013 meson_version: '>=1.1.1',
Mike Cappsa0819562022-06-13 10:17:10 -040014)
15
16python_prog = find_program('python3', native: true)
17
18cpp = meson.get_compiler('cpp')
19
20cli11_dep = dependency('cli11', required: false)
21
Patrick Williams1a56c2b2023-07-17 12:07:23 -050022if not cpp.has_header_symbol(
Mike Cappsa0819562022-06-13 10:17:10 -040023 'CLI/CLI.hpp',
24 'CLI::App',
25 dependencies: cli11_dep,
Patrick Williamsf5f87ca2025-02-01 08:36:20 -050026 required: false,
27)
28 cli11_proj = subproject('cli11', required: false)
Mike Cappsa0819562022-06-13 10:17:10 -040029 assert(cli11_proj.found(), 'CLI11 is required')
30 cli11_dep = cli11_proj.get_variable('CLI11_dep')
31endif
32
Patrick Williams1a56c2b2023-07-17 12:07:23 -050033cereal_dep = dependency('cereal', required: false)
34has_cereal = cpp.has_header_symbol(
35 'cereal/cereal.hpp',
36 'cereal::specialize',
37 dependencies: cereal_dep,
Patrick Williamsf5f87ca2025-02-01 08:36:20 -050038 required: false,
39)
Patrick Williams1a56c2b2023-07-17 12:07:23 -050040if not has_cereal
41 cereal_opts = import('cmake').subproject_options()
Patrick Williamsf5f87ca2025-02-01 08:36:20 -050042 cereal_opts.add_cmake_defines(
43 {'BUILD_TESTS': 'OFF', 'SKIP_PERFORMANCE_COMPARISON': 'ON'},
44 )
Patrick Williams1a56c2b2023-07-17 12:07:23 -050045 cereal_proj = import('cmake').subproject(
46 'cereal',
47 options: cereal_opts,
Patrick Williamsf5f87ca2025-02-01 08:36:20 -050048 required: false,
49 )
Patrick Williams1a56c2b2023-07-17 12:07:23 -050050 assert(cereal_proj.found(), 'cereal is required')
51 cereal_dep = cereal_proj.dependency('cereal')
52endif
53
Patrick Williamsef17a252023-12-07 14:53:06 -060054nlohmann_json_dep = dependency('nlohmann_json', include_type: 'system')
Mike Cappsa0819562022-06-13 10:17:10 -040055phosphor_dbus_interfaces_dep = dependency('phosphor-dbus-interfaces')
56phosphor_logging_dep = dependency('phosphor-logging')
57sdbusplus_dep = dependency('sdbusplus')
58sdeventplus_dep = dependency('sdeventplus')
59stdplus_dep = dependency('stdplus')
60systemd_dep = dependency('systemd')
61
Patrick Williamsf5f87ca2025-02-01 08:36:20 -050062if (get_option('tests').allowed())
Matt Spinler023d2c72023-08-24 16:04:24 -050063 gmock_dep = dependency('gmock', disabler: true, required: false)
Mike Cappsa0819562022-06-13 10:17:10 -040064 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 Williamsf5f87ca2025-02-01 08:36:20 -050074 ],
Mike Cappsa0819562022-06-13 10:17:10 -040075 )
76 gmock_dep = gtest_proj.dependency('gmock')
77 else
78 assert(
Patrick Williams388fc572023-11-29 06:43:49 -060079 not get_option('tests').allowed(),
Patrick Williamsf5f87ca2025-02-01 08:36:20 -050080 'Googletest is required if tests are enabled',
Mike Cappsa0819562022-06-13 10:17:10 -040081 )
82 endif
83 endif
84 subdir('test')
85endif
86
87
88servicedir = systemd_dep.get_variable('systemdsystemunitdir')
89usr_share_dir = '/usr/share/phosphor-fan-presence'
90
91conf = configuration_data()
92
93# Control
94conf.set_quoted(
Patrick Williamsf5f87ca2025-02-01 08:36:20 -050095 'CONTROL_PERSIST_ROOT_PATH',
96 get_option('control-persist-root-path'),
97)
Mike Cappsa0819562022-06-13 10:17:10 -040098conf.set_quoted(
Patrick Williamsf5f87ca2025-02-01 08:36:20 -050099 'CONTROL_PERSIST_ROOT_PATH',
100 get_option('control-persist-root-path'),
101)
102conf.set_quoted('FAN_DEF_YAML_FILE', get_option('fan-def-yaml-file'))
103conf.set_quoted('FAN_ZONE_YAML_FILE', get_option('fan-zone-yaml-file'))
104conf.set_quoted('ZONE_EVENTS_YAML_FILE', get_option('zone-events-yaml-file'))
Mike Cappsa0819562022-06-13 10:17:10 -0400105conf.set_quoted(
Patrick Williamsf5f87ca2025-02-01 08:36:20 -0500106 'ZONE_CONDITIONS_YAML_FILE',
107 get_option('zone-conditions-yaml-file'),
108)
Mike Cappsa0819562022-06-13 10:17:10 -0400109
Mike Cappsa0819562022-06-13 10:17:10 -0400110# Fan control can be in YAML mode when everything else is in JSON mode
111control_conf_type = 'yaml'
Patrick Williams388fc572023-11-29 06:43:49 -0600112if get_option('json-config').allowed() and get_option('json-control').allowed()
Mike Cappsa0819562022-06-13 10:17:10 -0400113 control_conf_type = 'json'
114endif
115
Mike Cappsbf8e56f2022-06-29 14:23:07 -0400116# Monitor
Patrick Williamsf5f87ca2025-02-01 08:36:20 -0500117conf.set('NUM_MONITOR_LOG_ENTRIES', get_option('num-monitor-log-entries'))
118conf.set_quoted('FAN_MONITOR_YAML_FILE', get_option('fan-monitor-yaml-file'))
Chau Ly751c8be2023-01-13 08:21:03 +0000119conf.set('DELAY_HOST_CONTROL', get_option('delay-host-control'))
Patrick Williams388fc572023-11-29 06:43:49 -0600120if get_option('monitor-use-host-state').allowed()
Chau Lyfce14902023-01-13 08:52:33 +0000121 conf.set('MONITOR_USE_HOST_STATE', '')
122endif
Mike Cappsbf8e56f2022-06-29 14:23:07 -0400123
Mike Cappsa0819562022-06-13 10:17:10 -0400124# JSON-or-YAML (all programs)
Patrick Williams388fc572023-11-29 06:43:49 -0600125if get_option('json-config').allowed()
Mike Cappsa0819562022-06-13 10:17:10 -0400126 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 Cappsa0819562022-06-13 10:17:10 -0400132 conf_type = 'json'
133else
134 conf_type = 'yaml'
135endif
136
Mike Cappsbf8e56f2022-06-29 14:23:07 -0400137# Sensor Monitor
Patrick Williamsf5f87ca2025-02-01 08:36:20 -0500138conf.set_quoted(
139 'SENSOR_MONITOR_PERSIST_ROOT_PATH',
140 get_option('sensor-monitor-persist-root-path'),
141)
Mike Cappsa0819562022-06-13 10:17:10 -0400142
Patrick Williams388fc572023-11-29 06:43:49 -0600143if get_option('use-host-power-state').allowed()
Mike Cappsa0819562022-06-13 10:17:10 -0400144 conf.set('ENABLE_HOST_STATE', '')
145endif
146
Jerry C Chen35fb3a02024-08-30 14:54:30 +0800147if get_option('skip-power-checking').allowed()
148 conf.set('SKIP_POWER_CHECKING', '')
149endif
150
Mike Cappsa0819562022-06-13 10:17:10 -0400151conf.set(
Patrick Williamsf5f87ca2025-02-01 08:36:20 -0500152 'SHUTDOWN_ALARM_HARD_SHUTDOWN_DELAY_MS',
153 get_option('sensor-monitor-hard-shutdown-delay'),
154)
Mike Cappsa0819562022-06-13 10:17:10 -0400155conf.set(
Patrick Williamsf5f87ca2025-02-01 08:36:20 -0500156 'SHUTDOWN_ALARM_SOFT_SHUTDOWN_DELAY_MS',
157 get_option('sensor-monitor-soft-shutdown-delay'),
158)
Mike Cappsa0819562022-06-13 10:17:10 -0400159
Patrick Rudolph235adf92025-02-17 08:11:30 +0100160log_sensor_name_on_error = get_option('log-sensor-name-on-error')
161if log_sensor_name_on_error
162 conf.set('LOG_SENSOR_NAME_ON_ERROR', '1')
163else
164 conf.set('LOG_SENSOR_NAME_ON_ERROR', '0')
165endif
166
Mike Cappsbf8e56f2022-06-29 14:23:07 -0400167# Presence
Patrick Williamsf5f87ca2025-02-01 08:36:20 -0500168conf.set('NUM_PRESENCE_LOG_ENTRIES', get_option('num-presence-log-entries'))
169conf.set_quoted('PRESENCE_YAML_FILE', get_option('presence-config'))
Mike Cappsbf8e56f2022-06-29 14:23:07 -0400170
Mike Cappsa0819562022-06-13 10:17:10 -0400171configure_file(output: 'config.h', configuration: conf)
172
173# Service: [name,[svcfiles]]
174services = []
175
Patrick Williams388fc572023-11-29 06:43:49 -0600176if get_option('control-service').allowed()
Mike Cappsa0819562022-06-13 10:17:10 -0400177 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]]
183endif
184
Patrick Williams388fc572023-11-29 06:43:49 -0600185if get_option('monitor-service').allowed()
Mike Cappsa0819562022-06-13 10:17:10 -0400186 subdir('monitor')
187 service_files = ['phosphor-fan-monitor@.service']
Patrick Williams388fc572023-11-29 06:43:49 -0600188 if not get_option('json-config').allowed()
Mike Cappsa0819562022-06-13 10:17:10 -0400189 service_files += 'phosphor-fan-monitor-init@.service'
190 endif
191 services += [['monitor', service_files]]
192endif
193
Patrick Williams388fc572023-11-29 06:43:49 -0600194if get_option('cooling-type-service').allowed()
Mike Cappsa0819562022-06-13 10:17:10 -0400195 libevdev_dep = dependency('libevdev')
196 subdir('cooling-type')
197endif
198
Patrick Williams388fc572023-11-29 06:43:49 -0600199if get_option('presence-service').allowed()
Mike Cappsa0819562022-06-13 10:17:10 -0400200 libevdev_dep = dependency('libevdev')
201 subdir('presence')
202 services += [['presence', ['phosphor-fan-presence-tach@.service']]]
203endif
204
Patrick Williams388fc572023-11-29 06:43:49 -0600205if get_option('sensor-monitor-service').allowed()
Mike Cappsa0819562022-06-13 10:17:10 -0400206 subdir('sensor-monitor')
Patrick Williamsf5f87ca2025-02-01 08:36:20 -0500207 install_data(
208 'sensor-monitor/service_files/sensor-monitor.service',
209 install_dir: servicedir,
210 )
Mike Cappsa0819562022-06-13 10:17:10 -0400211endif
212
213foreach 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 Williamsf5f87ca2025-02-01 08:36:20 -0500221 install_data(
222 service[0] / 'service_files' / this_conf_type / service_file,
223 install_dir: servicedir,
224 )
Mike Cappsa0819562022-06-13 10:17:10 -0400225 endforeach
226
227 if this_conf_type == 'json'
228 fs = import('fs')
Patrick Williamsf5f87ca2025-02-01 08:36:20 -0500229 dir = meson.current_source_dir() / service[0] / 'config_files' / get_option(
230 'machine-name',
231 )
Mike Cappsa0819562022-06-13 10:17:10 -0400232 if fs.is_dir(dir)
Patrick Williamsf5f87ca2025-02-01 08:36:20 -0500233 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 Cappsa0819562022-06-13 10:17:10 -0400238 endif
239 endif
240endforeach
241