blob: b34dab1c0eff2bb24703fa6160371b8b29c44931 [file] [log] [blame]
John Chung197ea122024-05-03 19:57:55 +08001project(
Ed Tanousa5b3d492024-06-18 13:24:05 -07002 '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)
John Chung197ea122024-05-03 19:57:55 +080014
15project_description = 'libcper library'
16
17SectionSources = files(
Ed Tanousa5b3d492024-06-18 13:24:05 -070018 'sections/cper-section-arm.c',
19 'sections/cper-section-ccix-per.c',
20 'sections/cper-section-cxl-component.c',
21 'sections/cper-section-cxl-protocol.c',
22 'sections/cper-section-dmar-generic.c',
23 'sections/cper-section-dmar-iommu.c',
24 'sections/cper-section-dmar-vtd.c',
25 'sections/cper-section-firmware.c',
26 'sections/cper-section-generic.c',
27 'sections/cper-section-ia32x64.c',
28 'sections/cper-section-ipf.c',
29 'sections/cper-section-memory.c',
30 'sections/cper-section-pci-bus.c',
31 'sections/cper-section-pci-dev.c',
32 'sections/cper-section-pcie.c',
33 'sections/cper-section.c',
John Chung197ea122024-05-03 19:57:55 +080034)
35
Ed Tanousa5b3d492024-06-18 13:24:05 -070036EDKSources = files('edk/Cper.c')
John Chung197ea122024-05-03 19:57:55 +080037
38GeneratorSectionSources = files(
Ed Tanousa5b3d492024-06-18 13:24:05 -070039 'generator/sections/gen-section-arm.c',
40 'generator/sections/gen-section-ccix-per.c',
41 'generator/sections/gen-section-cxl-component.c',
42 'generator/sections/gen-section-cxl-protocol.c',
43 'generator/sections/gen-section-dmar.c',
44 'generator/sections/gen-section-firmware.c',
45 'generator/sections/gen-section-generic.c',
46 'generator/sections/gen-section-ia32x64.c',
47 'generator/sections/gen-section-memory.c',
48 'generator/sections/gen-section-pci-bus.c',
49 'generator/sections/gen-section-pci-dev.c',
50 'generator/sections/gen-section-pcie.c',
51 'generator/sections/gen-section.c',
John Chung197ea122024-05-03 19:57:55 +080052)
53
54cmake = import('cmake')
John Chungabc62b82024-05-22 22:45:36 +080055cc = meson.get_compiler('c')
John Chung197ea122024-05-03 19:57:55 +080056
Ed Tanousa5b3d492024-06-18 13:24:05 -070057json_c_dep = dependency('json-c', required: true, fallback: ['json-c', 'json_c_dep'])
John Chung197ea122024-05-03 19:57:55 +080058
John Chungabc62b82024-05-22 22:45:36 +080059libb64 = cc.find_library('base64', has_headers: 'libbase64.h', required: false)
John Chung197ea122024-05-03 19:57:55 +080060if not libb64.found()
Ed Tanousa5b3d492024-06-18 13:24:05 -070061 opt_var = cmake.subproject_options()
62 opt_var.add_cmake_defines(
63 {
64 'BUILD_SHARED_LIBS': true,
65 'BASE64_BUILD_CLI': false,
66 'BASE64_WITH_AVX': false,
67 'BASE64_WITH_AVX2': false,
68 'BASE64_WITH_AVX512': false,
69 'BASE64_WITH_SSSE3': false,
70 'BASE64_WITH_SSE41': false,
71 'BASE64_WITH_SSE42': false,
72 },
73 )
John Chung197ea122024-05-03 19:57:55 +080074
Ed Tanousa5b3d492024-06-18 13:24:05 -070075
76 libb64_ex = cmake.subproject('libb64', options: opt_var)
77 libb64 = libb64_ex.dependency('base64')
John Chung197ea122024-05-03 19:57:55 +080078endif
79
80libcper_parse_sources = [
Ed Tanousa5b3d492024-06-18 13:24:05 -070081 'cper-parse.c',
82 'ir-parse.c',
83 'cper-utils.c',
84 'common-utils.c',
85 'json-schema.c',
John Chung197ea122024-05-03 19:57:55 +080086]
87
88libcper_include = ['.']
89
90libcper_parse = library(
Ed Tanousa5b3d492024-06-18 13:24:05 -070091 'cper-parse',
92 libcper_parse_sources,
93 SectionSources,
94 EDKSources,
95 version: meson.project_version(),
96 include_directories: include_directories(libcper_include),
97 c_args: '-Wno-address-of-packed-member',
98 dependencies: [
99 json_c_dep,
100 libb64,
101 ],
102 install: true,
103 install_dir: get_option('libdir'),
John Chung197ea122024-05-03 19:57:55 +0800104)
105libcper_parse = declare_dependency(
Ed Tanousa5b3d492024-06-18 13:24:05 -0700106 include_directories: include_directories(libcper_include),
107 link_with: libcper_parse,
John Chung197ea122024-05-03 19:57:55 +0800108)
109
Ed Tanousa5b3d492024-06-18 13:24:05 -0700110libcper_generate_sources = ['generator/cper-generate.c', 'generator/gen-utils.c', 'common-utils.c']
John Chung197ea122024-05-03 19:57:55 +0800111
112libcper_generate = library(
Ed Tanousa5b3d492024-06-18 13:24:05 -0700113 'cper-generate',
114 libcper_generate_sources,
115 GeneratorSectionSources,
116 version: meson.project_version(),
117 include_directories: include_directories(libcper_include),
118 dependencies: [
119 libcper_parse,
120 json_c_dep,
121 libb64,
122 ],
123 install: true,
124 install_dir: get_option('libdir'),
John Chung197ea122024-05-03 19:57:55 +0800125)
126libcper_generate = declare_dependency(
Ed Tanousa5b3d492024-06-18 13:24:05 -0700127 include_directories: include_directories(libcper_include),
128 link_with: libcper_generate,
John Chung197ea122024-05-03 19:57:55 +0800129)
130
John Chungabc62b82024-05-22 22:45:36 +0800131install_headers('cper-parse.h')
132install_headers('cper-utils.h')
133install_headers('common-utils.h')
134install_headers('generator/cper-generate.h', subdir: 'generator')
135install_headers('edk/Cper.h', subdir: 'edk')
136install_headers('edk/BaseTypes.h', subdir: 'edk')
John Chung197ea122024-05-03 19:57:55 +0800137
John Chungabc62b82024-05-22 22:45:36 +0800138if get_option('utility').allowed()
Ed Tanousa5b3d492024-06-18 13:24:05 -0700139 executable(
140 'cper-convert',
141 'cli-app/cper-convert.c',
142 include_directories: include_directories(libcper_include),
143 dependencies: [
144 libcper_parse,
145 json_c_dep,
146 ],
147 install: true,
148 install_dir: get_option('bindir'),
149 )
John Chungabc62b82024-05-22 22:45:36 +0800150
Ed Tanousa5b3d492024-06-18 13:24:05 -0700151 executable(
152 'cper-generate',
153 'generator/cper-generate-cli.c',
154 EDKSources,
155 include_directories: include_directories(libcper_include),
156 dependencies: [
157 libcper_generate,
158 ],
159 install: true,
160 install_dir: get_option('bindir'),
161 )
John Chungabc62b82024-05-22 22:45:36 +0800162endif
John Chung197ea122024-05-03 19:57:55 +0800163
Ed Tanous1e267b62024-06-18 13:20:42 -0700164run_command('cp', '-r', 'specification/json/', meson.current_build_dir(), check: true)
Ed Tanousa5b3d492024-06-18 13:24:05 -0700165run_command(
166 'mv',
167 meson.current_build_dir() / 'json',
168 meson.current_build_dir() / 'specification',
169)
John Chung197ea122024-05-03 19:57:55 +0800170
171if get_option('tests').allowed()
Ed Tanousa5b3d492024-06-18 13:24:05 -0700172 subdir('tests')
John Chung197ea122024-05-03 19:57:55 +0800173endif