blob: 731d85fa0ca6c5eb14d7297f91dd50cd173df8df [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()
Konstantin Aladyshev31c3ab52024-04-02 18:26:33 +030040 cereal_opts.add_cmake_defines({'BUILD_TESTS': 'OFF', 'SKIP_PERFORMANCE_COMPARISON': 'ON'})
Patrick Williams1a56c2b2023-07-17 12:07:23 -050041 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
Patrick Williamsef17a252023-12-07 14:53:06 -060049nlohmann_json_dep = dependency('nlohmann_json', include_type: 'system')
Mike Cappsa0819562022-06-13 10:17:10 -040050phosphor_dbus_interfaces_dep = dependency('phosphor-dbus-interfaces')
51phosphor_logging_dep = dependency('phosphor-logging')
52sdbusplus_dep = dependency('sdbusplus')
53sdeventplus_dep = dependency('sdeventplus')
54stdplus_dep = dependency('stdplus')
55systemd_dep = dependency('systemd')
56
Patrick Williams388fc572023-11-29 06:43:49 -060057if(get_option('tests').allowed())
Matt Spinler023d2c72023-08-24 16:04:24 -050058 gmock_dep = dependency('gmock', disabler: true, required: false)
Mike Cappsa0819562022-06-13 10:17:10 -040059 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 Williams388fc572023-11-29 06:43:49 -060074 not get_option('tests').allowed(),
Mike Cappsa0819562022-06-13 10:17:10 -040075 'Googletest is required if tests are enabled'
76 )
77 endif
78 endif
79 subdir('test')
80endif
81
82
83servicedir = systemd_dep.get_variable('systemdsystemunitdir')
84usr_share_dir = '/usr/share/phosphor-fan-presence'
85
86conf = configuration_data()
87
88# Control
89conf.set_quoted(
90 'CONTROL_PERSIST_ROOT_PATH', get_option('control-persist-root-path'))
91conf.set_quoted(
Mike Cappsa0819562022-06-13 10:17:10 -040092 'CONTROL_PERSIST_ROOT_PATH', get_option('control-persist-root-path'))
Mike Cappsa0819562022-06-13 10:17:10 -040093conf.set_quoted(
94 'FAN_DEF_YAML_FILE', get_option('fan-def-yaml-file'))
95conf.set_quoted(
96 'FAN_ZONE_YAML_FILE', get_option('fan-zone-yaml-file'))
97conf.set_quoted(
98 'ZONE_EVENTS_YAML_FILE', get_option('zone-events-yaml-file'))
99conf.set_quoted(
100 'ZONE_CONDITIONS_YAML_FILE', get_option('zone-conditions-yaml-file'))
101
Mike Cappsa0819562022-06-13 10:17:10 -0400102# Fan control can be in YAML mode when everything else is in JSON mode
103control_conf_type = 'yaml'
Patrick Williams388fc572023-11-29 06:43:49 -0600104if get_option('json-config').allowed() and get_option('json-control').allowed()
Mike Cappsa0819562022-06-13 10:17:10 -0400105 control_conf_type = 'json'
106endif
107
Mike Cappsbf8e56f2022-06-29 14:23:07 -0400108# Monitor
109conf.set(
110 'NUM_MONITOR_LOG_ENTRIES', get_option('num-monitor-log-entries'))
111conf.set_quoted(
112 'FAN_MONITOR_YAML_FILE', get_option('fan-monitor-yaml-file'))
Chau Ly751c8be2023-01-13 08:21:03 +0000113conf.set('DELAY_HOST_CONTROL', get_option('delay-host-control'))
Patrick Williams388fc572023-11-29 06:43:49 -0600114if get_option('monitor-use-host-state').allowed()
Chau Lyfce14902023-01-13 08:52:33 +0000115 conf.set('MONITOR_USE_HOST_STATE', '')
116endif
Mike Cappsbf8e56f2022-06-29 14:23:07 -0400117
Mike Cappsa0819562022-06-13 10:17:10 -0400118# JSON-or-YAML (all programs)
Patrick Williams388fc572023-11-29 06:43:49 -0600119if get_option('json-config').allowed()
Mike Cappsa0819562022-06-13 10:17:10 -0400120 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 Cappsa0819562022-06-13 10:17:10 -0400126 conf_type = 'json'
127else
128 conf_type = 'yaml'
129endif
130
Mike Cappsbf8e56f2022-06-29 14:23:07 -0400131# Sensor Monitor
132conf.set_quoted('SENSOR_MONITOR_PERSIST_ROOT_PATH',
133 get_option('sensor-monitor-persist-root-path'))
Mike Cappsa0819562022-06-13 10:17:10 -0400134
Patrick Williams388fc572023-11-29 06:43:49 -0600135if get_option('use-host-power-state').allowed()
Mike Cappsa0819562022-06-13 10:17:10 -0400136 conf.set('ENABLE_HOST_STATE', '')
137endif
138
Jerry C Chen35fb3a02024-08-30 14:54:30 +0800139if get_option('skip-power-checking').allowed()
140 conf.set('SKIP_POWER_CHECKING', '')
141endif
142
Mike Cappsa0819562022-06-13 10:17:10 -0400143conf.set(
144 'SHUTDOWN_ALARM_HARD_SHUTDOWN_DELAY_MS', get_option('sensor-monitor-hard-shutdown-delay'))
145conf.set(
146 'SHUTDOWN_ALARM_SOFT_SHUTDOWN_DELAY_MS', get_option('sensor-monitor-soft-shutdown-delay'))
147
Mike Cappsbf8e56f2022-06-29 14:23:07 -0400148# Presence
149conf.set(
150 'NUM_PRESENCE_LOG_ENTRIES', get_option('num-presence-log-entries'))
151conf.set_quoted(
152 'PRESENCE_YAML_FILE', get_option('presence-config'))
153
Mike Cappsa0819562022-06-13 10:17:10 -0400154configure_file(output: 'config.h', configuration: conf)
155
156# Service: [name,[svcfiles]]
157services = []
158
Patrick Williams388fc572023-11-29 06:43:49 -0600159if get_option('control-service').allowed()
Mike Cappsa0819562022-06-13 10:17:10 -0400160 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]]
166endif
167
Patrick Williams388fc572023-11-29 06:43:49 -0600168if get_option('monitor-service').allowed()
Mike Cappsa0819562022-06-13 10:17:10 -0400169 subdir('monitor')
170 service_files = ['phosphor-fan-monitor@.service']
Patrick Williams388fc572023-11-29 06:43:49 -0600171 if not get_option('json-config').allowed()
Mike Cappsa0819562022-06-13 10:17:10 -0400172 service_files += 'phosphor-fan-monitor-init@.service'
173 endif
174 services += [['monitor', service_files]]
175endif
176
Patrick Williams388fc572023-11-29 06:43:49 -0600177if get_option('cooling-type-service').allowed()
Mike Cappsa0819562022-06-13 10:17:10 -0400178 libevdev_dep = dependency('libevdev')
179 subdir('cooling-type')
180endif
181
Patrick Williams388fc572023-11-29 06:43:49 -0600182if get_option('presence-service').allowed()
Mike Cappsa0819562022-06-13 10:17:10 -0400183 libevdev_dep = dependency('libevdev')
184 subdir('presence')
185 services += [['presence', ['phosphor-fan-presence-tach@.service']]]
186endif
187
Patrick Williams388fc572023-11-29 06:43:49 -0600188if get_option('sensor-monitor-service').allowed()
Mike Cappsa0819562022-06-13 10:17:10 -0400189 subdir('sensor-monitor')
190 install_data('sensor-monitor/service_files/sensor-monitor.service',
191 install_dir: servicedir)
192endif
193
194foreach 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
215endforeach
216