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