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