1project(
2    'phosphor-state-manager',
3    'cpp',
4    default_options: [
5        'warning_level=3',
6        'werror=true',
7        'cpp_std=c++20'
8    ],
9    meson_version: '>= 0.57.0',
10    license: 'Apache-2.0',
11    version: '0.1',
12)
13cpp = meson.get_compiler('cpp')
14
15build_host_gpios = get_option('host-gpios')
16
17conf = configuration_data()
18conf.set_quoted(
19    'HOST_BUSNAME', get_option('host-busname'))
20conf.set_quoted(
21    'HOST_OBJPATH', get_option('host-objpath'))
22conf.set_quoted(
23    'HYPERVISOR_BUSNAME', get_option('hypervisor-busname'))
24conf.set_quoted(
25    'HYPERVISOR_OBJPATH', get_option('hypervisor-objpath'))
26conf.set_quoted(
27    'CHASSIS_BUSNAME', get_option('chassis-busname'))
28conf.set_quoted(
29    'CHASSIS_OBJPATH', get_option('chassis-objpath'))
30conf.set_quoted(
31    'BMC_BUSNAME', get_option('bmc-busname'))
32conf.set_quoted(
33    'BMC_OBJPATH', get_option('bmc-objpath'))
34conf.set_quoted(
35    'HOST_STATE_PERSIST_PATH', get_option('host-state-persist-path'))
36conf.set_quoted(
37    'POH_COUNTER_PERSIST_PATH', get_option('poh-counter-persist-path'))
38conf.set_quoted(
39    'CHASSIS_STATE_CHANGE_PERSIST_PATH', get_option('chassis-state-change-persist-path'))
40conf.set_quoted(
41    'SCHEDULED_HOST_TRANSITION_PERSIST_PATH', get_option('scheduled-host-transition-persist-path'))
42conf.set_quoted(
43    'SCHEDULED_HOST_TRANSITION_BUSNAME', get_option('scheduled-host-transition-busname'))
44conf.set(
45    'BOOT_COUNT_MAX_ALLOWED', get_option('boot-count-max-allowed'))
46conf.set(
47    'CLASS_VERSION', get_option('class-version'))
48conf.set_quoted(
49    'SYSFS_SECURE_BOOT_PATH', get_option('sysfs-secure-boot-path'))
50conf.set_quoted(
51    'SYSFS_ABR_IMAGE_PATH', get_option('sysfs-abr-image-path'))
52if build_host_gpios.enabled()
53    conf.set_quoted(
54        'HOST_GPIOS_BUSNAME', get_option('host-gpios-busname'))
55    conf.set_quoted(
56        'HOST_GPIOS_OBJPATH', get_option('host-gpios-objpath'))
57endif
58
59# globals shared across applications
60conf.set_quoted(
61    'HOST_RUNNING_FILE', '/run/openbmc/host@%d-on')
62
63conf.set_quoted(
64    'CHASSIS_ON_FILE', '/run/openbmc/chassis@%d-on')
65
66configure_file(output: 'config.h', configuration: conf)
67
68if(get_option('warm-reboot').enabled())
69    add_project_arguments('-DENABLE_WARM_REBOOT',language:'cpp')
70endif
71
72sdbusplus = dependency('sdbusplus')
73sdeventplus = dependency('sdeventplus')
74phosphorlogging = dependency('phosphor-logging')
75phosphordbusinterfaces = dependency('phosphor-dbus-interfaces')
76libgpiod = dependency('libgpiod', version : '>=1.4.1')
77fmt = dependency('fmt')
78
79if cpp.has_header('nlohmann/json.hpp')
80    nlohmann_json = declare_dependency()
81else
82    subproject('nlohmann-json')
83    nlohmann_json = declare_dependency(
84        include_directories: [
85            'subprojects/nlohmann-json/single_include',
86            'subprojects/nlohmann-json/single_include/nlohmann',
87        ]
88    )
89endif
90
91if cpp.has_header('CLI/CLI.hpp')
92    CLI11 = declare_dependency()
93else
94    CLI11 = dependency('CLI11')
95endif
96
97# Get Cereal dependency.
98cereal = dependency('cereal', required: false)
99has_cereal = cpp.has_header_symbol(
100    'cereal/cereal.hpp',
101    'cereal::specialize',
102    dependencies: cereal,
103    required: false)
104if not has_cereal
105    cereal_opts = import('cmake').subproject_options()
106    cereal_opts.add_cmake_defines({'BUILD_TESTS': 'OFF'})
107    cereal_proj = import('cmake').subproject(
108        'cereal',
109        options: cereal_opts,
110        required: false)
111    assert(cereal_proj.found(), 'cereal is required')
112    cereal = cereal_proj.dependency('cereal')
113endif
114
115executable('phosphor-host-state-manager',
116            'host_state_manager.cpp',
117            'host_state_manager_main.cpp',
118            'settings.cpp',
119            'host_check.cpp',
120            'utils.cpp',
121            dependencies: [
122                cereal,
123                fmt,
124                libgpiod,
125                phosphordbusinterfaces,
126                phosphorlogging,
127                sdbusplus,
128                sdeventplus,
129            ],
130    implicit_include_directories: true,
131    install: true
132)
133
134executable('phosphor-hypervisor-state-manager',
135            'hypervisor_state_manager.cpp',
136            'hypervisor_state_manager_main.cpp',
137            'settings.cpp',
138            dependencies: [
139                phosphordbusinterfaces,
140                phosphorlogging,
141                sdbusplus,
142                sdeventplus,
143            ],
144    implicit_include_directories: true,
145    install: true
146)
147
148executable('phosphor-chassis-state-manager',
149            'chassis_state_manager.cpp',
150            'chassis_state_manager_main.cpp',
151            'utils.cpp',
152            dependencies: [
153                cereal,
154                fmt,
155                libgpiod,
156                nlohmann_json,
157                phosphordbusinterfaces,
158                phosphorlogging,
159                sdbusplus,
160                sdeventplus,
161            ],
162    implicit_include_directories: true,
163    install: true
164)
165
166executable('phosphor-chassis-check-power-status',
167            'chassis_check_power_status.cpp',
168            'utils.cpp',
169            dependencies: [
170                libgpiod,
171                phosphordbusinterfaces,
172                phosphorlogging,
173                sdbusplus,
174            ],
175    implicit_include_directories: true,
176    install: true
177)
178
179executable('phosphor-bmc-state-manager',
180            'bmc_state_manager.cpp',
181            'bmc_state_manager_main.cpp',
182            'utils.cpp',
183            dependencies: [
184                libgpiod,
185                phosphordbusinterfaces,
186                phosphorlogging,
187                sdbusplus,
188                sdeventplus,
189            ],
190    implicit_include_directories: true,
191    install: true
192)
193
194executable('phosphor-discover-system-state',
195            'discover_system_state.cpp',
196            'settings.cpp',
197            'utils.cpp',
198            dependencies: [
199                cereal,
200                libgpiod,
201                phosphorlogging,
202                sdbusplus,
203            ],
204    implicit_include_directories: true,
205    install: true
206)
207
208executable('phosphor-systemd-target-monitor',
209            'systemd_service_parser.cpp',
210            'systemd_target_monitor.cpp',
211            'systemd_target_parser.cpp',
212            'systemd_target_signal.cpp',
213            'utils.cpp',
214            dependencies: [
215                CLI11,
216                libgpiod,
217                nlohmann_json,
218                phosphorlogging,
219                sdbusplus,
220                sdeventplus,
221            ],
222    implicit_include_directories: true,
223    install: true
224)
225
226executable('phosphor-scheduled-host-transition',
227            'scheduled_host_transition_main.cpp',
228            'scheduled_host_transition.cpp',
229            'utils.cpp',
230            dependencies: [
231                cereal,
232                libgpiod,
233                phosphorlogging,
234                sdbusplus,
235                sdeventplus,
236            ],
237    implicit_include_directories: true,
238    install: true
239)
240
241executable('phosphor-host-reset-recovery',
242            'host_reset_recovery.cpp',
243            dependencies: [
244                phosphorlogging,
245                sdbusplus,
246            ],
247    implicit_include_directories: true,
248    install: true
249)
250
251executable('phosphor-secure-boot-check',
252            'secure_boot_check.cpp',
253            'utils.cpp',
254            dependencies: [
255            sdbusplus, phosphorlogging, libgpiod
256            ],
257    implicit_include_directories: true,
258    install: true
259)
260
261install_data('obmcutil',
262        install_mode: 'rwxr-xr-x',
263        install_dir: get_option('bindir')
264)
265
266install_data('scripts/host-reboot',
267        install_mode: 'rwxr-xr-x',
268        install_dir: get_option('libexecdir')
269)
270
271systemd = dependency('systemd')
272systemd_system_unit_dir = systemd.get_variable(
273    pkgconfig : 'systemdsystemunitdir')
274subdir('service_files')
275subdir('target_files')
276
277if build_host_gpios.enabled()
278    subdir('host_condition_gpio')
279endif
280
281datadir = join_paths(
282    get_option('sysconfdir'),
283    'phosphor-systemd-target-monitor'
284)
285subdir('data')
286
287build_tests = get_option('tests')
288
289# If test coverage of source files within the root directory are wanted,
290# need to define and build the tests from here
291if not build_tests.disabled()
292gtest = dependency('gtest', main: true, disabler: true, required: build_tests)
293gmock = dependency('gmock', disabler: true, required: build_tests)
294  test(
295      'test_systemd_parser',
296      executable('test_systemd_parser',
297          './test/systemd_parser.cpp',
298          'systemd_target_parser.cpp',
299          dependencies: [
300              gtest,
301              nlohmann_json,
302          ],
303          implicit_include_directories: true,
304          include_directories: '../'
305      )
306  )
307
308  test(
309      'test_systemd_signal',
310      executable('test_systemd_signal',
311          './test/systemd_signal.cpp',
312          'systemd_target_signal.cpp',
313          'utils.cpp',
314          dependencies: [
315              gtest,
316              libgpiod,
317              nlohmann_json,
318              phosphorlogging,
319              sdbusplus,
320              sdeventplus,
321          ],
322          implicit_include_directories: true,
323          include_directories: '../'
324      )
325  )
326
327  test(
328      'test_scheduled_host_transition',
329      executable('test_scheduled_host_transition',
330          './test/test_scheduled_host_transition.cpp',
331          'scheduled_host_transition.cpp',
332          'utils.cpp',
333          dependencies: [
334              cereal,
335              gmock,
336              gtest,
337              libgpiod,
338              phosphorlogging,
339              sdbusplus,
340              sdeventplus,
341          ],
342          implicit_include_directories: true,
343          include_directories: '../'
344      )
345  )
346
347  test(
348      'test_hypervisor_state',
349      executable('test_hypervisor_state',
350          './test/hypervisor_state.cpp',
351          'hypervisor_state_manager.cpp',
352          dependencies: [
353              gtest,
354              phosphorlogging,
355              sdbusplus,
356              sdeventplus,
357          ],
358          implicit_include_directories: true,
359          include_directories: '../'
360      )
361  )
362endif
363