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
266systemd = dependency('systemd')
267systemd_system_unit_dir = systemd.get_variable(
268    pkgconfig : 'systemdsystemunitdir')
269subdir('service_files')
270subdir('target_files')
271
272if build_host_gpios.enabled()
273    subdir('host_condition_gpio')
274endif
275
276datadir = join_paths(
277    get_option('sysconfdir'),
278    'phosphor-systemd-target-monitor'
279)
280subdir('data')
281
282build_tests = get_option('tests')
283
284# If test coverage of source files within the root directory are wanted,
285# need to define and build the tests from here
286if not build_tests.disabled()
287gtest = dependency('gtest', main: true, disabler: true, required: build_tests)
288gmock = dependency('gmock', disabler: true, required: build_tests)
289  test(
290      'test_systemd_parser',
291      executable('test_systemd_parser',
292          './test/systemd_parser.cpp',
293          'systemd_target_parser.cpp',
294          dependencies: [
295              gtest,
296              nlohmann_json,
297          ],
298          implicit_include_directories: true,
299          include_directories: '../'
300      )
301  )
302
303  test(
304      'test_systemd_signal',
305      executable('test_systemd_signal',
306          './test/systemd_signal.cpp',
307          'systemd_target_signal.cpp',
308          'utils.cpp',
309          dependencies: [
310              gtest,
311              libgpiod,
312              nlohmann_json,
313              phosphorlogging,
314              sdbusplus,
315              sdeventplus,
316          ],
317          implicit_include_directories: true,
318          include_directories: '../'
319      )
320  )
321
322  test(
323      'test_scheduled_host_transition',
324      executable('test_scheduled_host_transition',
325          './test/test_scheduled_host_transition.cpp',
326          'scheduled_host_transition.cpp',
327          'utils.cpp',
328          dependencies: [
329              cereal,
330              gmock,
331              gtest,
332              libgpiod,
333              phosphorlogging,
334              sdbusplus,
335              sdeventplus,
336          ],
337          implicit_include_directories: true,
338          include_directories: '../'
339      )
340  )
341
342  test(
343      'test_hypervisor_state',
344      executable('test_hypervisor_state',
345          './test/hypervisor_state.cpp',
346          'hypervisor_state_manager.cpp',
347          dependencies: [
348              gtest,
349              phosphorlogging,
350              sdbusplus,
351              sdeventplus,
352          ],
353          implicit_include_directories: true,
354          include_directories: '../'
355      )
356  )
357endif
358