1project('phosphor-bmc-code-mgmt', 'cpp',
2    default_options: [
3        'buildtype=debugoptimized',
4        'cpp_std=c++23',
5        'warning_level=3',
6        'werror=true'
7    ],
8    meson_version: '>=1.1.1',
9    license: 'Apache-2.0',
10    version: '1.0')
11
12add_project_arguments(
13    '-DBOOST_SYSTEM_NO_DEPRECATED',
14    '-DBOOST_ERROR_CODE_HEADER_ONLY',
15    '-DBOOST_NO_RTTI',
16    '-DBOOST_NO_TYPEID',
17    '-DBOOST_ALL_NO_LIB',
18    '-DBOOST_ASIO_DISABLE_THREADS',
19    '-DBOOST_ASIO_NO_DEPRECATED',
20    language: 'cpp',
21)
22
23cpp = meson.get_compiler('cpp')
24
25conf = configuration_data()
26
27# DBus information
28conf.set_quoted('BMC_INVENTORY_INTERFACE', 'xyz.openbmc_project.Inventory.Item.Bmc')
29conf.set_quoted('BUSNAME_UPDATER', 'xyz.openbmc_project.Software.BMC.Updater')
30conf.set_quoted('DOWNLOAD_BUSNAME', 'xyz.openbmc_project.Software.Download')
31conf.set_quoted('FILEPATH_IFACE', 'xyz.openbmc_project.Common.FilePath')
32conf.set_quoted('INVENTORY_PATH', '/xyz/openbmc_project/inventory/')
33conf.set_quoted('MAPPER_BUSNAME', 'xyz.openbmc_project.ObjectMapper')
34conf.set_quoted('MAPPER_INTERFACE', 'xyz.openbmc_project.ObjectMapper')
35conf.set_quoted('MAPPER_PATH', '/xyz/openbmc_project/object_mapper')
36conf.set_quoted('SOFTWARE_OBJPATH', '/xyz/openbmc_project/software')
37conf.set_quoted('SYSTEMD_BUSNAME', 'org.freedesktop.systemd1')
38conf.set_quoted('SYSTEMD_PATH', '/org/freedesktop/systemd1')
39conf.set_quoted('SYSTEMD_INTERFACE', 'org.freedesktop.systemd1.Manager')
40conf.set_quoted('VERSION_BUSNAME', 'xyz.openbmc_project.Software.Version')
41conf.set_quoted('VERSION_IFACE', 'xyz.openbmc_project.Software.Version')
42conf.set_quoted('EXTENDED_VERSION_IFACE', 'xyz.openbmc_project.Software.ExtendedVersion')
43conf.set_quoted('COMPATIBLE_IFACE', 'xyz.openbmc_project.Inventory.Decorator.Compatible')
44
45# Names of the forward and reverse associations
46conf.set_quoted('ACTIVATION_FWD_ASSOCIATION', 'inventory')
47conf.set_quoted('ACTIVATION_REV_ASSOCIATION', 'activation')
48conf.set_quoted('ACTIVE_FWD_ASSOCIATION', 'active')
49conf.set_quoted('ACTIVE_REV_ASSOCIATION', 'software_version')
50conf.set_quoted('FUNCTIONAL_FWD_ASSOCIATION', 'functional')
51conf.set_quoted('FUNCTIONAL_REV_ASSOCIATION', 'software_version')
52conf.set_quoted('UPDATEABLE_FWD_ASSOCIATION', 'updateable')
53conf.set_quoted('UPDATEABLE_REV_ASSOCIATION', 'software_version')
54
55# Filesystem files and directories
56# The prefix path for the versioned read-only bmc partitions
57conf.set_quoted('BMC_ROFS_PREFIX', get_option('media-dir') + '/rofs-')
58# The name of the BMC table of contents file
59conf.set_quoted('OS_RELEASE_FILE', '/etc/os-release')
60# The dir where activation data is stored in files
61conf.set_quoted('PERSIST_DIR', '/var/lib/phosphor-bmc-code-mgmt/')
62
63# Supported BMC layout types
64conf.set('STATIC_LAYOUT', get_option('bmc-layout').contains('static'))
65conf.set('UBIFS_LAYOUT', get_option('bmc-layout').contains('ubi'))
66conf.set('MMC_LAYOUT', get_option('bmc-layout').contains('mmc'))
67
68# Configurable features
69conf.set('HOST_BIOS_UPGRADE', get_option('host-bios-upgrade').allowed())
70conf.set('WANT_SIGNATURE_VERIFY', get_option('verify-signature').allowed())
71
72# Configurable variables
73conf.set('ACTIVE_BMC_MAX_ALLOWED', get_option('active-bmc-max-allowed'))
74conf.set_quoted('HASH_FILE_NAME', get_option('hash-file-name'))
75conf.set_quoted('IMG_UPLOAD_DIR', get_option('img-upload-dir'))
76conf.set_quoted('MANIFEST_FILE_NAME', get_option('manifest-file-name'))
77conf.set_quoted('MEDIA_DIR', get_option('media-dir'))
78optional_array = get_option('optional-images')
79optional_images = ''
80foreach optiona_image : optional_array
81    optional_images = ' '.join([optional_images, optiona_image])
82endforeach
83conf.set_quoted('OPTIONAL_IMAGES', optional_images)
84conf.set_quoted('PUBLICKEY_FILE_NAME', get_option('publickey-file-name'))
85conf.set_quoted('SIGNATURE_FILE_EXT', get_option('signature-file-ext'))
86conf.set_quoted('SIGNED_IMAGE_CONF_PATH', get_option('signed-image-conf-path'))
87conf.set_quoted('SYNC_LIST_DIR_PATH', get_option('sync-list-dir-path'))
88conf.set_quoted('SYNC_LIST_FILE_NAME', get_option('sync-list-file-name'))
89conf.set_quoted('BMC_MSL', get_option('bmc-msl'))
90conf.set_quoted('REGEX_BMC_MSL', get_option('regex-bmc-msl'))
91
92if get_option('host-bios-upgrade').allowed()
93    conf.set_quoted('BIOS_OBJPATH', get_option('bios-object-path'))
94endif
95
96if get_option('bmc-static-dual-image').allowed()
97  conf.set('BMC_STATIC_DUAL_IMAGE', get_option('bmc-static-dual-image').allowed())
98  conf.set_quoted('ALT_ROFS_DIR', get_option('alt-rofs-dir'))
99  conf.set_quoted('ALT_RWFS', get_option('alt-rwfs-dir'))
100else
101  conf.set_quoted('ALT_RWFS', '/media/alt/var/persist')
102endif
103
104configure_file(output: 'config.h', configuration: conf)
105
106boost_dep = dependency('boost')
107
108sdbusplus_dep = dependency('sdbusplus')
109sdbusplusplus_prog = find_program('sdbus++', native: true)
110sdbuspp_gen_meson_prog = find_program('sdbus++-gen-meson', native: true)
111
112pdi_dep = dependency('phosphor-dbus-interfaces')
113phosphor_logging_dep = dependency('phosphor-logging')
114
115cereal_dep = dependency('cereal', required: false)
116has_cereal = cpp.has_header_symbol(
117    'cereal/cereal.hpp',
118    'cereal::specialize',
119    dependencies: cereal_dep,
120    required: false)
121if not has_cereal
122    cereal_opts = import('cmake').subproject_options()
123    cereal_opts.add_cmake_defines({'BUILD_TESTS': 'OFF', 'SKIP_PERFORMANCE_COMPARISON': 'ON'})
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_dep = cereal_proj.dependency('cereal')
130endif
131
132deps = [
133    cereal_dep,
134    pdi_dep,
135    phosphor_logging_dep,
136    sdbusplus_dep,
137]
138
139ssl = dependency('openssl')
140
141systemd = dependency('systemd')
142systemd_system_unit_dir = systemd.get_variable('systemdsystemunitdir')
143
144unit_files = [
145    'obmc-flash-bmc-setenv@.service.in',
146    'reboot-guard-disable.service.in',
147    'reboot-guard-enable.service.in',
148    'force-reboot.service.in',
149    'usr-local.mount.in',
150    'xyz.openbmc_project.Software.BMC.Updater.service.in',
151    'xyz.openbmc_project.Software.Download.service.in',
152    'xyz.openbmc_project.Software.Sync.service.in',
153    'xyz.openbmc_project.Software.Version.service.in'
154]
155
156image_updater_sources = files(
157    'activation.cpp',
158    'images.cpp',
159    'item_updater.cpp',
160    'serialize.cpp',
161    'version.cpp',
162    'utils.cpp',
163    'msl_verify.cpp'
164)
165
166if get_option('bmc-layout').contains('static')
167    image_updater_sources += files(
168        'static/flash.cpp',
169        'static/item_updater_helper.cpp'
170    )
171elif get_option('bmc-layout').contains('ubi')
172    image_updater_sources += files(
173        'ubi/flash.cpp',
174        'ubi/item_updater_helper.cpp'
175    )
176
177    unit_files += [
178        'ubi/obmc-flash-bmc-cleanup.service.in',
179        'ubi/obmc-flash-bmc-mirroruboot.service.in',
180        'ubi/obmc-flash-bmc-ubiremount.service.in',
181        'ubi/obmc-flash-bmc-ubiro@.service.in',
182        'ubi/obmc-flash-bmc-ubiro-remove@.service.in',
183        'ubi/obmc-flash-bmc-ubirw.service.in',
184        'ubi/obmc-flash-bmc-ubirw-remove.service.in',
185        'ubi/obmc-flash-bmc-updateubootvars@.service.in'
186    ]
187elif get_option('bmc-layout').contains('mmc')
188    image_updater_sources += files(
189        'mmc/flash.cpp',
190        'mmc/item_updater_helper.cpp'
191    )
192
193    unit_files += [
194        'mmc/obmc-flash-mmc@.service.in',
195        'mmc/obmc-flash-mmc-mount.service.in',
196        'mmc/obmc-flash-mmc-remove@.service.in',
197        'mmc/obmc-flash-mmc-setprimary@.service.in',
198        'mmc/obmc-flash-mmc-umount.service.in',
199        'mmc/obmc-flash-mmc-mirroruboot.service.in',
200    ]
201endif
202
203if get_option('host-bios-upgrade').allowed()
204    unit_files += 'obmc-flash-host-bios@.service.in'
205endif
206
207if get_option('bmc-static-dual-image').allowed()
208    unit_files += [
209        'static/obmc-flash-bmc-alt@.service.in',
210        'static/obmc-flash-bmc-static-mount-alt.service.in',
211        'static/obmc-flash-bmc-prepare-for-sync.service.in',
212    ]
213endif
214
215if get_option('sync-bmc-files').allowed()
216    executable(
217        'phosphor-sync-software-manager',
218        'sync_manager.cpp',
219        'sync_manager_main.cpp',
220        'sync_watch.cpp',
221        dependencies: deps,
222        install: true
223    )
224
225    install_data('synclist',
226        install_dir:  get_option('sysconfdir')
227    )
228
229    install_data('sync-once.sh',
230        install_mode: 'rwxr-xr-x',
231        install_dir: get_option('bindir')
232    )
233endif
234
235if (get_option('verify-signature').allowed())
236    image_updater_sources += files(
237        'utils.cpp',
238        'image_verify.cpp',
239        'openssl_alloc.cpp'
240    )
241endif
242
243executable(
244    'phosphor-download-manager',
245    'download_manager.cpp',
246    'download_manager_main.cpp',
247    dependencies: deps,
248    install: true
249)
250
251software_common_sources = files(
252    'software_utils.cpp'
253)
254
255executable(
256    'phosphor-image-updater',
257    image_updater_sources,
258    software_common_sources,
259    'item_updater_main.cpp',
260    dependencies: [deps, ssl, boost_dep],
261    install: true
262)
263
264if get_option('software-update-dbus-interface').allowed()
265    executable(
266        'phosphor-software-manager',
267        'software_manager.cpp',
268        image_updater_sources,
269        software_common_sources,
270        dependencies: [deps, ssl],
271        install: true
272    )
273    unit_files += [
274        'xyz.openbmc_project.Software.Manager.service.in'
275    ]
276endif
277
278executable(
279    'phosphor-version-software-manager',
280    'image_manager.cpp',
281    'image_manager_main.cpp',
282    'version.cpp',
283    'watch.cpp',
284    software_common_sources,
285    dependencies: [deps, ssl],
286    install: true
287)
288
289install_data('obmc-flash-bmc',
290    install_mode: 'rwxr-xr-x',
291    install_dir: get_option('bindir')
292)
293
294install_data('detect-slot-aspeed',
295    install_mode: 'rwxr-xr-x',
296    install_dir: get_option('bindir')
297)
298
299install_data('reset-cs0-aspeed',
300    install_mode: 'rwxr-xr-x',
301    install_dir: get_option('bindir')
302)
303
304install_data('software.conf',
305    install_dir: '/usr/lib/tmpfiles.d/'
306)
307
308foreach u : unit_files
309    configure_file(
310        input: u,
311        output: '@BASENAME@',
312        configuration: conf,
313        install: true,
314        install_dir: systemd_system_unit_dir,
315    )
316endforeach
317
318# If test coverage of source files within the root directory are wanted,
319# need to define and build the tests from here
320build_tests = get_option('tests')
321if not build_tests.disabled()
322    gtest = dependency('gtest', main: true, disabler: true, required: build_tests)
323    include_srcs = declare_dependency(sources: [
324        'utils.cpp',
325        'image_verify.cpp',
326        'images.cpp',
327        'version.cpp']
328    )
329
330    test('utest',
331        executable(
332            'utest',
333            './test/utest.cpp',
334            dependencies: [deps, gtest, include_srcs, ssl]
335        )
336)
337endif
338
339if get_option('usb-code-update').allowed()
340    subdir('usb')
341endif
342
343if get_option('side-switch-on-boot').allowed()
344    subdir('side-switch')
345endif
346