blob: d2cc75d2cf18c19ec99962453c7685d73d266dec [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
Mike Cappsbf8e56f2022-06-29 14:23:07 -0400160# Presence
Patrick Williamsf5f87ca2025-02-01 08:36:20 -0500161conf.set('NUM_PRESENCE_LOG_ENTRIES', get_option('num-presence-log-entries'))
162conf.set_quoted('PRESENCE_YAML_FILE', get_option('presence-config'))
Mike Cappsbf8e56f2022-06-29 14:23:07 -0400163
Mike Cappsa0819562022-06-13 10:17:10 -0400164configure_file(output: 'config.h', configuration: conf)
165
166# Service: [name,[svcfiles]]
167services = []
168
Patrick Williams388fc572023-11-29 06:43:49 -0600169if get_option('control-service').allowed()
Mike Cappsa0819562022-06-13 10:17:10 -0400170 subdir('control')
171 service_files = ['phosphor-fan-control@.service']
172 if control_conf_type == 'yaml'
173 service_files += 'phosphor-fan-control-init@.service'
174 endif
175 services += [['control', service_files]]
176endif
177
Patrick Williams388fc572023-11-29 06:43:49 -0600178if get_option('monitor-service').allowed()
Mike Cappsa0819562022-06-13 10:17:10 -0400179 subdir('monitor')
180 service_files = ['phosphor-fan-monitor@.service']
Patrick Williams388fc572023-11-29 06:43:49 -0600181 if not get_option('json-config').allowed()
Mike Cappsa0819562022-06-13 10:17:10 -0400182 service_files += 'phosphor-fan-monitor-init@.service'
183 endif
184 services += [['monitor', service_files]]
185endif
186
Patrick Williams388fc572023-11-29 06:43:49 -0600187if get_option('cooling-type-service').allowed()
Mike Cappsa0819562022-06-13 10:17:10 -0400188 libevdev_dep = dependency('libevdev')
189 subdir('cooling-type')
190endif
191
Patrick Williams388fc572023-11-29 06:43:49 -0600192if get_option('presence-service').allowed()
Mike Cappsa0819562022-06-13 10:17:10 -0400193 libevdev_dep = dependency('libevdev')
194 subdir('presence')
195 services += [['presence', ['phosphor-fan-presence-tach@.service']]]
196endif
197
Patrick Williams388fc572023-11-29 06:43:49 -0600198if get_option('sensor-monitor-service').allowed()
Mike Cappsa0819562022-06-13 10:17:10 -0400199 subdir('sensor-monitor')
Patrick Williamsf5f87ca2025-02-01 08:36:20 -0500200 install_data(
201 'sensor-monitor/service_files/sensor-monitor.service',
202 install_dir: servicedir,
203 )
Mike Cappsa0819562022-06-13 10:17:10 -0400204endif
205
206foreach service : services
207 this_conf_type = conf_type
208
209 if service[0] == 'control'
210 this_conf_type = control_conf_type
211 endif
212
213 foreach service_file : service[1]
Patrick Williamsf5f87ca2025-02-01 08:36:20 -0500214 install_data(
215 service[0] / 'service_files' / this_conf_type / service_file,
216 install_dir: servicedir,
217 )
Mike Cappsa0819562022-06-13 10:17:10 -0400218 endforeach
219
220 if this_conf_type == 'json'
221 fs = import('fs')
Patrick Williamsf5f87ca2025-02-01 08:36:20 -0500222 dir = meson.current_source_dir() / service[0] / 'config_files' / get_option(
223 'machine-name',
224 )
Mike Cappsa0819562022-06-13 10:17:10 -0400225 if fs.is_dir(dir)
Patrick Williamsf5f87ca2025-02-01 08:36:20 -0500226 install_subdir(
227 service[0] / 'config_files' / get_option('machine-name'),
228 install_dir: usr_share_dir / service[0],
229 strip_directory: true,
230 )
Mike Cappsa0819562022-06-13 10:17:10 -0400231 endif
232 endif
233endforeach
234