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