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'))
48if build_host_gpios.enabled()
49    conf.set_quoted(
50        'HOST_GPIOS_BUSNAME', get_option('host-gpios-busname'))
51    conf.set_quoted(
52        'HOST_GPIOS_OBJPATH', get_option('host-gpios-objpath'))
53endif
54
55# globals shared across applications
56conf.set_quoted(
57    'HOST_RUNNING_FILE', '/run/openbmc/host@%d-on')
58
59conf.set_quoted(
60    'CHASSIS_ON_FILE', '/run/openbmc/chassis@%d-on')
61
62configure_file(output: 'config.h', configuration: conf)
63
64if(get_option('warm-reboot').enabled())
65    add_project_arguments('-DENABLE_WARM_REBOOT',language:'cpp')
66endif
67
68sdbusplus = dependency('sdbusplus')
69sdeventplus = dependency('sdeventplus')
70phosphorlogging = dependency('phosphor-logging')
71phosphordbusinterfaces = dependency('phosphor-dbus-interfaces')
72libgpiod = dependency('libgpiod', version : '>=1.4.1')
73fmt = dependency('fmt')
74
75if cpp.has_header('nlohmann/json.hpp')
76    nlohmann_json = declare_dependency()
77else
78    subproject('nlohmann-json')
79    nlohmann_json = declare_dependency(
80        include_directories: [
81            'subprojects/nlohmann-json/single_include',
82            'subprojects/nlohmann-json/single_include/nlohmann',
83        ]
84    )
85endif
86
87if cpp.has_header('CLI/CLI.hpp')
88    CLI11 = declare_dependency()
89else
90    CLI11 = dependency('CLI11')
91endif
92
93# Get Cereal dependency.
94cereal = dependency('cereal', required: false)
95has_cereal = cpp.has_header_symbol(
96    'cereal/cereal.hpp',
97    'cereal::specialize',
98    dependencies: cereal,
99    required: false)
100if not has_cereal
101    cereal_opts = import('cmake').subproject_options()
102    cereal_opts.add_cmake_defines({'BUILD_TESTS': 'OFF'})
103    cereal_proj = import('cmake').subproject(
104        'cereal',
105        options: cereal_opts,
106        required: false)
107    assert(cereal_proj.found(), 'cereal is required')
108    cereal = cereal_proj.dependency('cereal')
109endif
110
111executable('phosphor-host-state-manager',
112            'host_state_manager.cpp',
113            'host_state_manager_main.cpp',
114            'settings.cpp',
115            'host_check.cpp',
116            'utils.cpp',
117            dependencies: [
118                cereal,
119                fmt,
120                libgpiod,
121                phosphordbusinterfaces,
122                phosphorlogging,
123                sdbusplus,
124                sdeventplus,
125            ],
126    implicit_include_directories: true,
127    install: true
128)
129
130executable('phosphor-hypervisor-state-manager',
131            'hypervisor_state_manager.cpp',
132            'hypervisor_state_manager_main.cpp',
133            'settings.cpp',
134            dependencies: [
135                phosphordbusinterfaces,
136                phosphorlogging,
137                sdbusplus,
138                sdeventplus,
139            ],
140    implicit_include_directories: true,
141    install: true
142)
143
144executable('phosphor-chassis-state-manager',
145            'chassis_state_manager.cpp',
146            'chassis_state_manager_main.cpp',
147            'utils.cpp',
148            dependencies: [
149                cereal,
150                fmt,
151                libgpiod,
152                nlohmann_json,
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            dependencies: [
210                CLI11,
211                nlohmann_json,
212                phosphorlogging,
213                sdbusplus,
214                sdeventplus,
215            ],
216    implicit_include_directories: true,
217    install: true
218)
219
220executable('phosphor-scheduled-host-transition',
221            'scheduled_host_transition_main.cpp',
222            'scheduled_host_transition.cpp',
223            'utils.cpp',
224            dependencies: [
225                cereal,
226                libgpiod,
227                phosphorlogging,
228                sdbusplus,
229                sdeventplus,
230            ],
231    implicit_include_directories: true,
232    install: true
233)
234
235executable('phosphor-host-reset-recovery',
236            'host_reset_recovery.cpp',
237            dependencies: [
238                phosphorlogging,
239                sdbusplus,
240            ],
241    implicit_include_directories: true,
242    install: true
243)
244
245install_data('obmcutil',
246        install_mode: 'rwxr-xr-x',
247        install_dir: get_option('bindir')
248)
249
250systemd = dependency('systemd')
251systemd_system_unit_dir = systemd.get_variable(
252    pkgconfig : 'systemdsystemunitdir')
253subdir('service_files')
254subdir('target_files')
255
256if build_host_gpios.enabled()
257    subdir('host_condition_gpio')
258endif
259
260datadir = join_paths(
261    get_option('sysconfdir'),
262    'phosphor-systemd-target-monitor'
263)
264subdir('data')
265
266build_tests = get_option('tests')
267
268# If test coverage of source files within the root directory are wanted,
269# need to define and build the tests from here
270if not build_tests.disabled()
271gtest = dependency('gtest', main: true, disabler: true, required: build_tests)
272gmock = dependency('gmock', disabler: true, required: build_tests)
273  test(
274      'test_systemd_parser',
275      executable('test_systemd_parser',
276          './test/systemd_parser.cpp',
277          'systemd_target_parser.cpp',
278          dependencies: [
279              gtest,
280              nlohmann_json,
281          ],
282          implicit_include_directories: true,
283          include_directories: '../'
284      )
285  )
286
287  test(
288      'test_systemd_signal',
289      executable('test_systemd_signal',
290          './test/systemd_signal.cpp',
291          'systemd_target_signal.cpp',
292          dependencies: [
293              gtest,
294              nlohmann_json,
295              phosphorlogging,
296              sdbusplus,
297              sdeventplus,
298          ],
299          implicit_include_directories: true,
300          include_directories: '../'
301      )
302  )
303
304  test(
305      'test_scheduled_host_transition',
306      executable('test_scheduled_host_transition',
307          './test/test_scheduled_host_transition.cpp',
308          'scheduled_host_transition.cpp',
309          'utils.cpp',
310          dependencies: [
311              cereal,
312              gmock,
313              gtest,
314              libgpiod,
315              phosphorlogging,
316              sdbusplus,
317              sdeventplus,
318          ],
319          implicit_include_directories: true,
320          include_directories: '../'
321      )
322  )
323
324  test(
325      'test_hypervisor_state',
326      executable('test_hypervisor_state',
327          './test/hypervisor_state.cpp',
328          'hypervisor_state_manager.cpp',
329          dependencies: [
330              gtest,
331              phosphorlogging,
332              sdbusplus,
333              sdeventplus,
334          ],
335          implicit_include_directories: true,
336          include_directories: '../'
337      )
338  )
339endif
340