xref: /openbmc/libcper/meson.build (revision e42fb487839b242371b0150ab5b0b89c2d232976)
1project(
2    'libcper',
3    ['c', 'cpp'],
4    version: '0.1',
5    meson_version: '>=1.1.1',
6    default_options: [
7        'c_std=c18',
8        'cpp_std=c++23',
9        'tests=' + (meson.is_subproject() ? 'disabled' : 'enabled'),
10        'warning_level=2',
11        'werror=true',
12    ],
13)
14
15add_project_arguments(
16    '-DLIBCPER_JSON_SPEC="'
17    + meson.current_source_dir() + '/specification/json/cper-json.json"',
18    language: ['c', 'cpp'],
19)
20
21library_is_share = get_option('default_library') == 'shared'
22add_project_arguments('-D_POSIX_C_SOURCE=200809L', language: 'c')
23
24project_description = 'libcper library'
25
26section_sources = files(
27    'sections/cper-section-ampere.c',
28    'sections/cper-section-arm.c',
29    'sections/cper-section-ccix-per.c',
30    'sections/cper-section-cxl-component.c',
31    'sections/cper-section-cxl-protocol.c',
32    'sections/cper-section-dmar-generic.c',
33    'sections/cper-section-dmar-iommu.c',
34    'sections/cper-section-dmar-vtd.c',
35    'sections/cper-section-firmware.c',
36    'sections/cper-section-generic.c',
37    'sections/cper-section-ia32x64.c',
38    'sections/cper-section-ipf.c',
39    'sections/cper-section-memory.c',
40    'sections/cper-section-nvidia.c',
41    'sections/cper-section-pci-bus.c',
42    'sections/cper-section-pci-dev.c',
43    'sections/cper-section-pcie.c',
44    'sections/cper-section.c',
45)
46
47edk_sources = files('Cper.c')
48
49generator_section_sources = files(
50    'generator/sections/gen-section-ampere.c',
51    'generator/sections/gen-section-arm.c',
52    'generator/sections/gen-section-ccix-per.c',
53    'generator/sections/gen-section-cxl-component.c',
54    'generator/sections/gen-section-cxl-protocol.c',
55    'generator/sections/gen-section-dmar.c',
56    'generator/sections/gen-section-firmware.c',
57    'generator/sections/gen-section-generic.c',
58    'generator/sections/gen-section-ia32x64.c',
59    'generator/sections/gen-section-memory.c',
60    'generator/sections/gen-section-nvidia.c',
61    'generator/sections/gen-section-pci-bus.c',
62    'generator/sections/gen-section-pci-dev.c',
63    'generator/sections/gen-section-pcie.c',
64    'generator/sections/gen-section.c',
65)
66
67cc = meson.get_compiler('c')
68
69json_c_dep = dependency('json-c', required: false)
70if not json_c_dep.found()
71    json_c = subproject(
72        'json-c',
73        required: true,
74        default_options: ['warning_level=0'],
75    )
76    json_c_dep = json_c.get_variable('json_c_dep')
77endif
78
79libcper_parse_sources = files(
80    'base64.c',
81    'common-utils.c',
82    'cper-parse.c',
83    'cper-utils.c',
84    'ir-parse.c',
85    'json-schema.c',
86)
87
88libcper_include = ['include']
89libcper_include_dir = include_directories(libcper_include, is_system: true)
90subdir('include')
91
92libcper_parse = library(
93    'cper-parse',
94    libcper_parse_sources,
95    section_sources,
96    edk_sources,
97    version: meson.project_version(),
98    include_directories: libcper_include_dir,
99    c_args: '-Wno-address-of-packed-member',
100    dependencies: [json_c_dep],
101    install: true,
102    install_dir: get_option('libdir'),
103)
104libcper_parse_dep = declare_dependency(
105    include_directories: libcper_include_dir,
106    link_with: libcper_parse,
107)
108
109libcper_generate_sources = [
110    'common-utils.c',
111    'generator/cper-generate.c',
112    'generator/gen-utils.c',
113]
114
115libcper_generate = library(
116    'cper-generate',
117    libcper_generate_sources,
118    generator_section_sources,
119    version: meson.project_version(),
120    include_directories: libcper_include_dir,
121    dependencies: [libcper_parse_dep, json_c_dep],
122    install: true,
123    install_dir: get_option('libdir'),
124)
125libcper_generate_dep = declare_dependency(
126    include_directories: libcper_include_dir,
127    link_with: libcper_generate,
128)
129
130import('pkgconfig').generate(
131    libcper_parse,
132    name: meson.project_name(),
133    version: meson.project_version(),
134    description: 'C bindings for parsing CPER',
135)
136
137if get_option('utility').allowed()
138    executable(
139        'cper-convert',
140        'cli-app/cper-convert.c',
141        include_directories: libcper_include_dir,
142        dependencies: [libcper_parse_dep, json_c_dep],
143        install: true,
144        install_dir: get_option('bindir'),
145    )
146
147    executable(
148        'cper-generate',
149        'generator/cper-generate-cli.c',
150        edk_sources,
151        include_directories: libcper_include_dir,
152        dependencies: [libcper_generate_dep],
153        install: true,
154        install_dir: get_option('bindir'),
155    )
156endif
157
158if get_option('tests').allowed()
159    subdir('tests')
160endif
161