xref: /openbmc/phosphor-bmc-code-mgmt/meson.build (revision c026f6cdc3f7e305d98dc824fcba0f199a7aa157)
1project('phosphor-bmc-code-mgmt', 'cpp',
2    default_options: [
3        'buildtype=debugoptimized',
4        'cpp_std=c++20',
5        'warning_level=3',
6        'werror=true'
7    ],
8    meson_version: '>= 0.57.0',
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')
43
44# Names of the forward and reverse associations
45conf.set_quoted('ACTIVATION_FWD_ASSOCIATION', 'inventory')
46conf.set_quoted('ACTIVATION_REV_ASSOCIATION', 'activation')
47conf.set_quoted('ACTIVE_FWD_ASSOCIATION', 'active')
48conf.set_quoted('ACTIVE_REV_ASSOCIATION', 'software_version')
49conf.set_quoted('FUNCTIONAL_FWD_ASSOCIATION', 'functional')
50conf.set_quoted('FUNCTIONAL_REV_ASSOCIATION', 'software_version')
51conf.set_quoted('UPDATEABLE_FWD_ASSOCIATION', 'updateable')
52conf.set_quoted('UPDATEABLE_REV_ASSOCIATION', 'software_version')
53
54# Filesystem files and directories
55# The prefix path for the versioned read-only bmc partitions
56conf.set_quoted('BMC_ROFS_PREFIX', get_option('media-dir') + '/rofs-')
57# The name of the BMC table of contents file
58conf.set_quoted('OS_RELEASE_FILE', '/etc/os-release')
59# The dir where activation data is stored in files
60conf.set_quoted('PERSIST_DIR', '/var/lib/phosphor-bmc-code-mgmt/')
61
62# Supported BMC layout types
63conf.set('STATIC_LAYOUT', get_option('bmc-layout').contains('static'))
64conf.set('UBIFS_LAYOUT', get_option('bmc-layout').contains('ubi'))
65conf.set('MMC_LAYOUT', get_option('bmc-layout').contains('mmc'))
66
67# Configurable features
68conf.set('HOST_BIOS_UPGRADE', get_option('host-bios-upgrade').enabled())
69conf.set('WANT_SIGNATURE_VERIFY', \
70    get_option('verify-signature').enabled() or \
71    get_option('verify-full-signature').enabled())
72conf.set('WANT_SIGNATURE_FULL_VERIFY', get_option('verify-full-signature').enabled())
73
74# Configurable variables
75conf.set('ACTIVE_BMC_MAX_ALLOWED', get_option('active-bmc-max-allowed'))
76conf.set_quoted('HASH_FILE_NAME', get_option('hash-file-name'))
77conf.set_quoted('IMG_UPLOAD_DIR', get_option('img-upload-dir'))
78conf.set_quoted('MANIFEST_FILE_NAME', get_option('manifest-file-name'))
79conf.set_quoted('MEDIA_DIR', get_option('media-dir'))
80optional_array = get_option('optional-images')
81optional_images = ''
82foreach optiona_image : optional_array
83    optional_images = ' '.join([optional_images, optiona_image])
84endforeach
85conf.set_quoted('OPTIONAL_IMAGES', optional_images)
86conf.set_quoted('PUBLICKEY_FILE_NAME', get_option('publickey-file-name'))
87conf.set_quoted('SIGNATURE_FILE_EXT', get_option('signature-file-ext'))
88conf.set_quoted('SIGNED_IMAGE_CONF_PATH', get_option('signed-image-conf-path'))
89conf.set_quoted('SYNC_LIST_DIR_PATH', get_option('sync-list-dir-path'))
90conf.set_quoted('SYNC_LIST_FILE_NAME', get_option('sync-list-file-name'))
91conf.set_quoted('BMC_MSL', get_option('bmc-msl'))
92conf.set_quoted('REGEX_BMC_MSL', get_option('regex-bmc-msl'))
93
94if get_option('host-bios-upgrade').enabled()
95    conf.set_quoted('BIOS_OBJPATH', get_option('bios-object-path'))
96endif
97
98if get_option('bmc-static-dual-image').enabled()
99  conf.set('BMC_STATIC_DUAL_IMAGE', get_option('bmc-static-dual-image').enabled())
100  conf.set_quoted('ALT_ROFS_DIR', get_option('alt-rofs-dir'))
101  conf.set_quoted('ALT_RWFS', get_option('alt-rwfs-dir'))
102else
103  conf.set_quoted('ALT_RWFS', '/media/alt/var/persist')
104endif
105
106configure_file(output: 'config.h', configuration: conf)
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'})
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(pkgconfig : '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
156subdir('xyz/openbmc_project/Software/Image')
157
158image_updater_sources = files(
159    'activation.cpp',
160    'images.cpp',
161    'item_updater.cpp',
162    'item_updater_main.cpp',
163    'serialize.cpp',
164    'version.cpp',
165    'utils.cpp',
166    'msl_verify.cpp'
167)
168
169if get_option('bmc-layout').contains('static')
170    image_updater_sources += files(
171        'static/flash.cpp',
172        'static/item_updater_helper.cpp'
173    )
174elif get_option('bmc-layout').contains('ubi')
175    image_updater_sources += files(
176        'ubi/flash.cpp',
177        'ubi/item_updater_helper.cpp'
178    )
179
180    unit_files += [
181        'ubi/obmc-flash-bmc-cleanup.service.in',
182        'ubi/obmc-flash-bmc-mirroruboot.service.in',
183        'ubi/obmc-flash-bmc-ubiremount.service.in',
184        'ubi/obmc-flash-bmc-ubiro@.service.in',
185        'ubi/obmc-flash-bmc-ubiro-remove@.service.in',
186        'ubi/obmc-flash-bmc-ubirw.service.in',
187        'ubi/obmc-flash-bmc-ubirw-remove.service.in',
188        'ubi/obmc-flash-bmc-updateubootvars@.service.in'
189    ]
190elif get_option('bmc-layout').contains('mmc')
191    image_updater_sources += files(
192        'mmc/flash.cpp',
193        'mmc/item_updater_helper.cpp'
194    )
195
196    unit_files += [
197        'mmc/obmc-flash-mmc@.service.in',
198        'mmc/obmc-flash-mmc-mount.service.in',
199        'mmc/obmc-flash-mmc-remove@.service.in',
200        'mmc/obmc-flash-mmc-setprimary@.service.in',
201        'mmc/obmc-flash-mmc-umount.service.in',
202    ]
203endif
204
205if get_option('host-bios-upgrade').enabled()
206    unit_files += 'obmc-flash-host-bios@.service.in'
207endif
208
209if get_option('bmc-static-dual-image').enabled()
210    unit_files += [
211        'static/obmc-flash-bmc-alt@.service.in',
212        'static/obmc-flash-bmc-static-mount-alt.service.in',
213        'static/obmc-flash-bmc-prepare-for-sync.service.in',
214    ]
215endif
216
217if get_option('sync-bmc-files').enabled()
218    executable(
219        'phosphor-sync-software-manager',
220        'sync_manager.cpp',
221        'sync_manager_main.cpp',
222        'sync_watch.cpp',
223        dependencies: deps,
224        install: true
225    )
226
227    install_data('synclist',
228        install_dir:  get_option('sysconfdir')
229    )
230
231    install_data('sync-once.sh',
232        install_mode: 'rwxr-xr-x',
233        install_dir: get_option('bindir')
234    )
235endif
236
237if (get_option('verify-signature').enabled() or \
238    get_option('verify-full-signature').enabled())
239    image_updater_sources += files(
240        'utils.cpp',
241        'image_verify.cpp',
242        'openssl_alloc.cpp'
243    )
244endif
245
246executable(
247    'phosphor-download-manager',
248    'download_manager.cpp',
249    'download_manager_main.cpp',
250    dependencies: deps,
251    install: true
252)
253
254executable(
255    'phosphor-image-updater',
256    image_error_cpp,
257    image_error_hpp,
258    image_updater_sources,
259    dependencies: [deps, ssl],
260    install: true
261)
262
263executable(
264    'phosphor-version-software-manager',
265    image_error_cpp,
266    image_error_hpp,
267    'image_manager.cpp',
268    'image_manager_main.cpp',
269    'version.cpp',
270    'watch.cpp',
271    dependencies: [deps, ssl],
272    install: true
273)
274
275install_data('obmc-flash-bmc',
276    install_mode: 'rwxr-xr-x',
277    install_dir: get_option('bindir')
278)
279
280install_data('detect-slot-aspeed',
281    install_mode: 'rwxr-xr-x',
282    install_dir: get_option('bindir')
283)
284
285install_data('reset-cs0-aspeed',
286    install_mode: 'rwxr-xr-x',
287    install_dir: get_option('bindir')
288)
289
290install_data('software.conf',
291    install_dir: '/usr/lib/tmpfiles.d/'
292)
293
294foreach u : unit_files
295    configure_file(
296        input: u,
297        output: '@BASENAME@',
298        configuration: conf,
299        install: true,
300        install_dir: systemd_system_unit_dir,
301    )
302endforeach
303
304# If test coverage of source files within the root directory are wanted,
305# need to define and build the tests from here
306build_tests = get_option('tests')
307if not build_tests.disabled()
308    oe_sdk = get_option('oe-sdk')
309    if oe_sdk.enabled()
310        # Setup OE SYSROOT
311        OECORE_TARGET_SYSROOT = run_command('sh', '-c', 'echo $OECORE_TARGET_SYSROOT').stdout().strip()
312        if OECORE_TARGET_SYSROOT == ''
313            error('Unable to get $OECORE_TARGET_SYSROOT, check your environment.')
314        endif
315        message('OE_SYSROOT: ' + OECORE_TARGET_SYSROOT)
316        rpath = ':'.join([OECORE_TARGET_SYSROOT + '/lib', OECORE_TARGET_SYSROOT + '/usr/lib'])
317        ld_so = run_command('sh', '-c', 'find ' + OECORE_TARGET_SYSROOT + '/lib/ld-*.so | sort -r -n | head -n1').stdout().strip()
318        dynamic_linker = ['-Wl,-dynamic-linker,' + ld_so]
319    else
320        dynamic_linker = []
321    endif
322
323    gtest = dependency('gtest', main: true, disabler: true, required: build_tests)
324    include_srcs = declare_dependency(sources: [
325        'utils.cpp',
326        'image_verify.cpp',
327        'images.cpp',
328        'version.cpp']
329    )
330
331    test('utest',
332        executable(
333            'utest',
334            './test/utest.cpp',
335            link_args: dynamic_linker,
336            build_rpath: get_option('oe-sdk').enabled() ? rpath : '',
337            dependencies: [deps, gtest, include_srcs, ssl]
338        )
339)
340endif
341
342if get_option('usb-code-update').enabled()
343    subdir('usb')
344endif
345