xref: /openbmc/libcper/meson.build (revision eed88bbf9ee922e1132a20d3ca196ccf4289a8b9)
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        'werror=true',
11        'warning_level=2',
12    ],
13)
14
15add_project_arguments(
16    '-DLIBCPER_JSON_SPEC="'
17    + meson.current_source_dir()
18    + '/specification/json/cper-json.json"',
19    language: ['c', 'cpp'],
20)
21
22library_is_share = get_option('default_library') == 'shared'
23add_project_arguments('-D_POSIX_C_SOURCE=200809L', language : 'c')
24
25project_description = 'libcper library'
26
27section_sources = files(
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    'sections/cper-section-ampere.c',
46)
47
48edk_sources = files('edk/Cper.c')
49
50generator_section_sources = files(
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    'generator/sections/gen-section-ampere.c',
66)
67
68cc = meson.get_compiler('c')
69
70json_c_dep = dependency('json-c', required: false)
71if not json_c_dep.found()
72    json_c = subproject('json-c', required: true, default_options: ['warning_level=0'])
73    json_c_dep = json_c.get_variable('json_c_dep')
74endif
75
76libcper_parse_sources = [
77    'base64.c',
78    'cper-parse.c',
79    'ir-parse.c',
80    'cper-utils.c',
81    'common-utils.c',
82    'json-schema.c',
83]
84
85libcper_include = ['.']
86
87libcper_parse = library(
88    'cper-parse',
89    libcper_parse_sources,
90    section_sources,
91    edk_sources,
92    version: meson.project_version(),
93    include_directories: include_directories(libcper_include),
94    c_args: '-Wno-address-of-packed-member',
95    dependencies: [
96        json_c_dep,
97    ],
98    install: true,
99    install_dir: get_option('libdir'),
100)
101libcper_parse_dep = declare_dependency(
102    include_directories: include_directories(libcper_include),
103    link_with: libcper_parse,
104)
105
106libcper_generate_sources = ['generator/cper-generate.c', 'generator/gen-utils.c', 'common-utils.c']
107
108libcper_generate = library(
109    'cper-generate',
110    libcper_generate_sources,
111    generator_section_sources,
112    version: meson.project_version(),
113    include_directories: include_directories(libcper_include),
114    dependencies: [
115        libcper_parse_dep,
116        json_c_dep,
117    ],
118    install: true,
119    install_dir: get_option('libdir'),
120)
121libcper_generate_dep = declare_dependency(
122    include_directories: include_directories(libcper_include),
123    link_with: libcper_generate,
124)
125
126import('pkgconfig').generate(
127    libcper_parse,
128    name: meson.project_name(),
129    version: meson.project_version(),
130    description: 'C bindings for parsing CPER'
131)
132
133install_headers('cper-parse.h')
134install_headers('cper-parse-str.h')
135install_headers('cper-utils.h')
136install_headers('common-utils.h')
137install_headers('generator/cper-generate.h', subdir: 'generator')
138install_headers('edk/Cper.h', subdir: 'edk')
139install_headers('edk/BaseTypes.h', subdir: 'edk')
140
141if get_option('utility').allowed()
142    executable(
143        'cper-convert',
144        'cli-app/cper-convert.c',
145        include_directories: include_directories(libcper_include),
146        dependencies: [
147            libcper_parse_dep,
148            json_c_dep,
149        ],
150        install: true,
151        install_dir: get_option('bindir'),
152    )
153
154    executable(
155        'cper-generate',
156        'generator/cper-generate-cli.c',
157        edk_sources,
158        include_directories: include_directories(libcper_include),
159        dependencies: [
160            libcper_generate_dep,
161        ],
162        install: true,
163        install_dir: get_option('bindir'),
164    )
165endif
166
167if get_option('tests').allowed()
168    subdir('tests')
169endif
170