xref: /openbmc/libcper/meson.build (revision 5220c9bd)
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)
46
47edk_sources = files('edk/Cper.c')
48
49generator_section_sources = files(
50    'generator/sections/gen-section-arm.c',
51    'generator/sections/gen-section-ccix-per.c',
52    'generator/sections/gen-section-cxl-component.c',
53    'generator/sections/gen-section-cxl-protocol.c',
54    'generator/sections/gen-section-dmar.c',
55    'generator/sections/gen-section-firmware.c',
56    'generator/sections/gen-section-generic.c',
57    'generator/sections/gen-section-ia32x64.c',
58    'generator/sections/gen-section-memory.c',
59    'generator/sections/gen-section-nvidia.c',
60    'generator/sections/gen-section-pci-bus.c',
61    'generator/sections/gen-section-pci-dev.c',
62    'generator/sections/gen-section-pcie.c',
63    'generator/sections/gen-section.c',
64)
65
66cc = meson.get_compiler('c')
67
68json_c_dep = dependency('json-c', required: true, fallback: ['json-c', 'json_c_dep'])
69
70libcper_parse_sources = [
71    'base64.c',
72    'cper-parse.c',
73    'ir-parse.c',
74    'cper-utils.c',
75    'common-utils.c',
76    'json-schema.c',
77]
78
79libcper_include = ['.']
80
81libcper_parse = library(
82    'cper-parse',
83    libcper_parse_sources,
84    section_sources,
85    edk_sources,
86    version: meson.project_version(),
87    include_directories: include_directories(libcper_include),
88    c_args: '-Wno-address-of-packed-member',
89    dependencies: [
90        json_c_dep,
91    ],
92    install: true,
93    install_dir: get_option('libdir'),
94)
95libcper_parse_dep = declare_dependency(
96    include_directories: include_directories(libcper_include),
97    link_with: libcper_parse,
98)
99
100libcper_generate_sources = ['generator/cper-generate.c', 'generator/gen-utils.c', 'common-utils.c']
101
102libcper_generate = library(
103    'cper-generate',
104    libcper_generate_sources,
105    generator_section_sources,
106    version: meson.project_version(),
107    include_directories: include_directories(libcper_include),
108    dependencies: [
109        libcper_parse_dep,
110        json_c_dep,
111    ],
112    install: true,
113    install_dir: get_option('libdir'),
114)
115libcper_generate_dep = declare_dependency(
116    include_directories: include_directories(libcper_include),
117    link_with: libcper_generate,
118)
119
120import('pkgconfig').generate(
121    libcper_parse,
122    name: meson.project_name(),
123    version: meson.project_version(),
124    description: 'C bindings for parsing CPER'
125)
126
127install_headers('cper-parse.h')
128install_headers('cper-parse-str.h')
129install_headers('cper-utils.h')
130install_headers('common-utils.h')
131install_headers('generator/cper-generate.h', subdir: 'generator')
132install_headers('edk/Cper.h', subdir: 'edk')
133install_headers('edk/BaseTypes.h', subdir: 'edk')
134
135if get_option('utility').allowed()
136    executable(
137        'cper-convert',
138        'cli-app/cper-convert.c',
139        include_directories: include_directories(libcper_include),
140        dependencies: [
141            libcper_parse_dep,
142            json_c_dep,
143        ],
144        install: true,
145        install_dir: get_option('bindir'),
146    )
147
148    executable(
149        'cper-generate',
150        'generator/cper-generate-cli.c',
151        edk_sources,
152        include_directories: include_directories(libcper_include),
153        dependencies: [
154            libcper_generate_dep,
155        ],
156        install: true,
157        install_dir: get_option('bindir'),
158    )
159endif
160
161if get_option('tests').allowed()
162    subdir('tests')
163endif
164