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