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