xref: /openbmc/libpldm/meson.build (revision a7989cd6)
1project('libpldm', ['c','cpp'],
2    default_options: [
3      'debug=true',
4      'optimization=g',
5      'warning_level=3',
6      'werror=true',
7      'cpp_std=c++20',
8      'c_std=c17',
9      'b_ndebug=if-release',
10      'tests=' + (meson.is_subproject() ? 'disabled' : 'enabled'),
11    ],
12    version: '0.7.0',
13    meson_version: '>=1.1.0',
14)
15
16add_project_arguments('-D_DEFAULT_SOURCE', language: ['c'])
17
18compiler = meson.get_compiler('c')
19conf = configuration_data()
20if compiler.has_header('poll.h')
21  conf.set('PLDM_HAS_POLL', 1)
22endif
23
24# ABI control
25visible =  '__attribute__((visibility("default")))'
26if get_option('abi').contains('deprecated')
27  conf.set('LIBPLDM_ABI_DEPRECATED', visible)
28  add_project_arguments('-DLIBPLDM_API_DEPRECATED', language: ['c', 'cpp'])
29else
30  conf.set('LIBPLDM_ABI_DEPRECATED', '')
31endif
32conf.set('LIBPLDM_ABI_STABLE', visible) # Always expose the stable symbols
33if get_option('abi').contains('testing')
34  conf.set('LIBPLDM_ABI_TESTING', visible)
35  add_project_arguments('-DLIBPLDM_API_TESTING', language: ['c', 'cpp'])
36else
37  conf.set('LIBPLDM_ABI_TESTING', '')
38endif
39
40config = configure_file(output: 'config.h',
41  configuration: conf
42)
43
44add_project_arguments('-include', '@0@'.format(config), language: 'c')
45
46libpldm_include_dir = include_directories('include', is_system: true)
47
48subdir('include')
49subdir('src')
50
51if get_option('tests').enabled()
52  subdir('tests')
53
54  c_suite = meson.get_compiler('c').get_id()
55  cpp_suite = meson.get_compiler('cpp').get_id()
56
57  if get_option('abi-compliance-check').allowed() and c_suite == cpp_suite and c_suite == 'gcc'
58    host = host_machine.cpu_family()
59    baseline_dump = meson.project_source_root() / 'abi' / host / '@0@.dump'.format(c_suite)
60
61    abi_dumper = find_program('abi-dumper',
62                              native: true,
63                              required: get_option('abi-compliance-check'))
64    abi_compliance_checker = find_program('abi-compliance-checker',
65                                          native: true,
66                                          required: get_option('abi-compliance-check'))
67
68    test_abi_compliance = abi_dumper.found() and \
69                          abi_compliance_checker.found() and \
70                          import('fs').is_file(baseline_dump)
71
72    if test_abi_compliance
73      current_dump = custom_target('abi-dump',
74                               input: libpldm,
75                               output: 'current.dump',
76                               command: [ abi_dumper,
77                                          '-public-headers',
78                                          meson.project_source_root() / 'include',
79                                          '@INPUT@',
80                                          '-o',
81                                          '@OUTPUT@',
82                                          '-lver',
83                                          meson.project_version()])
84      abi_compliance = custom_target('abi-compliance',
85                                     input: [baseline_dump, current_dump],
86                                     output: 'abi-compliance',
87                                     command: [ abi_compliance_checker,
88                                                '-l',
89                                                meson.project_name(),
90                                                '-old',
91                                                '@INPUT0@',
92                                                '-new',
93                                                '@INPUT1@' ],
94                                                build_by_default: true)
95    endif
96  endif
97endif
98
99install_subdir('instance-db',
100               install_mode: 'r--r--r--',
101               install_dir: get_option('datadir') / meson.project_name())
102