xref: /openbmc/libpldm/meson.build (revision 1be1d5ead48c9efe1776b8fcfaf87e74d81a1123)
1project(
2    'libpldm',
3    'c',
4    default_options: [
5        'debug=true',
6        'optimization=g',
7        'warning_level=3',
8        'werror=true',
9        'cpp_std=c++23',
10        'c_std=c17',
11        'b_ndebug=if-release',
12        'tests=' + (meson.is_subproject() ? 'disabled' : 'enabled'),
13    ],
14    version: '0.10.0',
15    meson_version: '>=1.3.0',
16)
17
18if get_option('tests').allowed()
19    add_languages('cpp')
20endif
21
22# For memmem() in src/msgbuf.h
23add_project_arguments('-D_GNU_SOURCE', language: ['c'])
24
25compiler = meson.get_compiler('c')
26if compiler.has_argument('-Wvla')
27    add_project_arguments('-Wvla', language: ['c'])
28endif
29
30conf = configuration_data()
31if compiler.has_header('poll.h')
32    conf.set('PLDM_HAS_POLL', 1)
33endif
34
35# ABI control
36compiler.has_function_attribute('visibility:default', required: true)
37entrypoint = '__attribute__((visibility("default")))'
38
39## Compile test until meson supports it via compiler.has_function_attribute()
40have_tainted_args_test = '#if !__has_attribute(tainted_args)\n#error\n#endif'
41if compiler.compiles(
42    have_tainted_args_test,
43    args: '-E',
44    name: 'compiler supports function attribute tainted_args',
45)
46    entrypoint += ' __attribute__((tainted_args))'
47endif
48
49libpldm_deprecated_aliases = []
50if get_option('abi').contains('deprecated')
51    conf.set('LIBPLDM_ABI_DEPRECATED', entrypoint)
52    conf.set(
53        'LIBPLDM_ABI_DEPRECATED_UNSAFE',
54        '__attribute((visibility("default")))',
55    )
56    add_project_arguments('-DLIBPLDM_API_DEPRECATED', language: ['c', 'cpp'])
57else
58    conf.set('LIBPLDM_ABI_DEPRECATED', '')
59endif
60conf.set('LIBPLDM_ABI_STABLE', entrypoint)  # Always expose the stable symbols
61if get_option('abi').contains('testing')
62    conf.set('LIBPLDM_ABI_TESTING', entrypoint)
63    add_project_arguments('-DLIBPLDM_API_TESTING', language: ['c', 'cpp'])
64else
65    conf.set('LIBPLDM_ABI_TESTING', '')
66endif
67
68config = configure_file(output: 'config.h', configuration: conf)
69
70add_project_arguments('-include', '@0@'.format(config), language: 'c')
71
72libpldm_include_dir = include_directories('include', is_system: true)
73
74subdir('include')
75subdir('src')
76
77if get_option('tests').allowed()
78    subdir('tests')
79endif
80
81install_subdir(
82    'instance-db',
83    install_mode: 'r--r--r--',
84    install_dir: get_option('datadir') / meson.project_name(),
85)
86