blob: 6a46f4297839a09d9539d63b358916911177e2ff [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'),
Ed Tanousa5b3d492024-06-18 13:24:05 -070010 'warning_level=2',
Ed Tanous0df69a82024-10-03 17:35:11 -070011 'werror=true',
Ed Tanousa5b3d492024-06-18 13:24:05 -070012 ],
13)
John Chung197ea122024-05-03 19:57:55 +080014
Karthik Rajagopalan45e73322024-07-26 14:27:24 -070015add_project_arguments(
Ed Tanous358c7e12024-07-15 13:54:57 -070016 '-DLIBCPER_JSON_SPEC="'
Ed Tanous10eb6de2024-10-03 17:23:12 -070017 + meson.current_source_dir() + '/specification/json/cper-json.json"',
Ed Tanous358c7e12024-07-15 13:54:57 -070018 language: ['c', 'cpp'],
19)
20
Aushim Nagarkatti517282f2025-03-03 17:08:31 -080021add_project_arguments('-DLIBCPER_EXAMPLES="'
22 + meson.current_source_dir() + '/examples"', language: ['c', 'cpp'])
Aushim Nagarkattiae8f6d92025-01-29 17:34:44 -080023
Andrew Adriance1a908982024-07-02 14:26:10 -070024library_is_share = get_option('default_library') == 'shared'
Ed Tanous10eb6de2024-10-03 17:23:12 -070025add_project_arguments('-D_POSIX_C_SOURCE=200809L', language: 'c')
Andrew Adriance1a908982024-07-02 14:26:10 -070026
Aushim Nagarkattidd9e8d92025-02-28 11:20:45 -080027if get_option('output-all-properties').enabled()
28 add_project_arguments('-DOUTPUT_ALL_PROPERTIES', language: ['c', 'cpp'])
29endif
30
John Chung197ea122024-05-03 19:57:55 +080031project_description = 'libcper library'
32
Ed Tanous8121f7e2025-03-06 14:39:07 -080033libcper_parse_sources = files(
Ed Tanous10eb6de2024-10-03 17:23:12 -070034 'sections/cper-section-ampere.c',
Ed Tanousa5b3d492024-06-18 13:24:05 -070035 'sections/cper-section-arm.c',
36 'sections/cper-section-ccix-per.c',
37 'sections/cper-section-cxl-component.c',
38 'sections/cper-section-cxl-protocol.c',
39 'sections/cper-section-dmar-generic.c',
40 'sections/cper-section-dmar-iommu.c',
41 'sections/cper-section-dmar-vtd.c',
42 'sections/cper-section-firmware.c',
43 'sections/cper-section-generic.c',
44 'sections/cper-section-ia32x64.c',
45 'sections/cper-section-ipf.c',
46 'sections/cper-section-memory.c',
Karthik Rajagopalan683e0552024-03-07 12:30:43 -080047 'sections/cper-section-nvidia.c',
Ed Tanousa5b3d492024-06-18 13:24:05 -070048 'sections/cper-section-pci-bus.c',
49 'sections/cper-section-pci-dev.c',
50 'sections/cper-section-pcie.c',
51 'sections/cper-section.c',
John Chung197ea122024-05-03 19:57:55 +080052)
53
Ed Tanousa3b7f8a2024-11-04 16:38:59 -080054edk_sources = files('Cper.c')
John Chung197ea122024-05-03 19:57:55 +080055
Ed Tanousa84fc932024-07-15 13:48:35 -070056generator_section_sources = files(
Ed Tanous10eb6de2024-10-03 17:23:12 -070057 'generator/sections/gen-section-ampere.c',
Ed Tanousa5b3d492024-06-18 13:24:05 -070058 'generator/sections/gen-section-arm.c',
59 'generator/sections/gen-section-ccix-per.c',
60 'generator/sections/gen-section-cxl-component.c',
61 'generator/sections/gen-section-cxl-protocol.c',
62 'generator/sections/gen-section-dmar.c',
63 'generator/sections/gen-section-firmware.c',
64 'generator/sections/gen-section-generic.c',
65 'generator/sections/gen-section-ia32x64.c',
66 'generator/sections/gen-section-memory.c',
Karthik Rajagopalan683e0552024-03-07 12:30:43 -080067 'generator/sections/gen-section-nvidia.c',
Ed Tanousa5b3d492024-06-18 13:24:05 -070068 'generator/sections/gen-section-pci-bus.c',
69 'generator/sections/gen-section-pci-dev.c',
70 'generator/sections/gen-section-pcie.c',
71 'generator/sections/gen-section.c',
John Chung197ea122024-05-03 19:57:55 +080072)
73
John Chungabc62b82024-05-22 22:45:36 +080074cc = meson.get_compiler('c')
John Chung197ea122024-05-03 19:57:55 +080075
Ed Tanouseed88bb2024-10-03 17:18:20 -070076json_c_dep = dependency('json-c', required: false)
77if not json_c_dep.found()
Ed Tanous10eb6de2024-10-03 17:23:12 -070078 json_c = subproject(
79 'json-c',
80 required: true,
81 default_options: ['warning_level=0'],
82 )
Ed Tanouseed88bb2024-10-03 17:18:20 -070083 json_c_dep = json_c.get_variable('json_c_dep')
84endif
John Chung197ea122024-05-03 19:57:55 +080085
Ed Tanous8121f7e2025-03-06 14:39:07 -080086libcper_parse_sources += files(
Ed Tanousa7d2cdd2024-07-15 11:07:27 -070087 'base64.c',
Ed Tanousa5b3d492024-06-18 13:24:05 -070088 'common-utils.c',
Ed Tanous0df69a82024-10-03 17:35:11 -070089 'cper-parse.c',
90 'cper-utils.c',
91 'ir-parse.c',
Ed Tanous0df69a82024-10-03 17:35:11 -070092)
John Chung197ea122024-05-03 19:57:55 +080093
Thu Nguyene42fb482024-10-15 14:43:11 +000094libcper_include = ['include']
95libcper_include_dir = include_directories(libcper_include, is_system: true)
96subdir('include')
John Chung197ea122024-05-03 19:57:55 +080097
98libcper_parse = library(
Ed Tanousa5b3d492024-06-18 13:24:05 -070099 'cper-parse',
100 libcper_parse_sources,
Ed Tanousa84fc932024-07-15 13:48:35 -0700101 edk_sources,
Ed Tanousa5b3d492024-06-18 13:24:05 -0700102 version: meson.project_version(),
Thu Nguyene42fb482024-10-15 14:43:11 +0000103 include_directories: libcper_include_dir,
Ed Tanousa5b3d492024-06-18 13:24:05 -0700104 c_args: '-Wno-address-of-packed-member',
Ed Tanous10eb6de2024-10-03 17:23:12 -0700105 dependencies: [json_c_dep],
Ed Tanousa5b3d492024-06-18 13:24:05 -0700106 install: true,
107 install_dir: get_option('libdir'),
John Chung197ea122024-05-03 19:57:55 +0800108)
Karthik Rajagopalan9fe2cb52024-08-08 15:12:29 -0700109libcper_parse_dep = declare_dependency(
Thu Nguyene42fb482024-10-15 14:43:11 +0000110 include_directories: libcper_include_dir,
Ed Tanousa5b3d492024-06-18 13:24:05 -0700111 link_with: libcper_parse,
John Chung197ea122024-05-03 19:57:55 +0800112)
113
Ed Tanous10eb6de2024-10-03 17:23:12 -0700114libcper_generate_sources = [
Ed Tanous0df69a82024-10-03 17:35:11 -0700115 'common-utils.c',
Ed Tanous10eb6de2024-10-03 17:23:12 -0700116 'generator/cper-generate.c',
117 'generator/gen-utils.c',
Ed Tanous10eb6de2024-10-03 17:23:12 -0700118]
John Chung197ea122024-05-03 19:57:55 +0800119
120libcper_generate = library(
Ed Tanousa5b3d492024-06-18 13:24:05 -0700121 'cper-generate',
122 libcper_generate_sources,
Ed Tanousa84fc932024-07-15 13:48:35 -0700123 generator_section_sources,
Ed Tanousa5b3d492024-06-18 13:24:05 -0700124 version: meson.project_version(),
Thu Nguyene42fb482024-10-15 14:43:11 +0000125 include_directories: libcper_include_dir,
Ed Tanous10eb6de2024-10-03 17:23:12 -0700126 dependencies: [libcper_parse_dep, json_c_dep],
Ed Tanousa5b3d492024-06-18 13:24:05 -0700127 install: true,
128 install_dir: get_option('libdir'),
John Chung197ea122024-05-03 19:57:55 +0800129)
Karthik Rajagopalan9fe2cb52024-08-08 15:12:29 -0700130libcper_generate_dep = declare_dependency(
Thu Nguyene42fb482024-10-15 14:43:11 +0000131 include_directories: libcper_include_dir,
Ed Tanousa5b3d492024-06-18 13:24:05 -0700132 link_with: libcper_generate,
John Chung197ea122024-05-03 19:57:55 +0800133)
134
Karthik Rajagopalan9fe2cb52024-08-08 15:12:29 -0700135import('pkgconfig').generate(
136 libcper_parse,
137 name: meson.project_name(),
138 version: meson.project_version(),
Ed Tanous10eb6de2024-10-03 17:23:12 -0700139 description: 'C bindings for parsing CPER',
Karthik Rajagopalan9fe2cb52024-08-08 15:12:29 -0700140)
141
John Chungabc62b82024-05-22 22:45:36 +0800142if get_option('utility').allowed()
Ed Tanousa5b3d492024-06-18 13:24:05 -0700143 executable(
144 'cper-convert',
145 'cli-app/cper-convert.c',
Thu Nguyene42fb482024-10-15 14:43:11 +0000146 include_directories: libcper_include_dir,
Ed Tanous10eb6de2024-10-03 17:23:12 -0700147 dependencies: [libcper_parse_dep, json_c_dep],
Ed Tanousa5b3d492024-06-18 13:24:05 -0700148 install: true,
149 install_dir: get_option('bindir'),
150 )
John Chungabc62b82024-05-22 22:45:36 +0800151
Ed Tanousa5b3d492024-06-18 13:24:05 -0700152 executable(
153 'cper-generate',
154 'generator/cper-generate-cli.c',
Ed Tanousa84fc932024-07-15 13:48:35 -0700155 edk_sources,
Thu Nguyene42fb482024-10-15 14:43:11 +0000156 include_directories: libcper_include_dir,
Ed Tanous10eb6de2024-10-03 17:23:12 -0700157 dependencies: [libcper_generate_dep],
Ed Tanousa5b3d492024-06-18 13:24:05 -0700158 install: true,
159 install_dir: get_option('bindir'),
160 )
John Chungabc62b82024-05-22 22:45:36 +0800161endif
John Chung197ea122024-05-03 19:57:55 +0800162
Aushim Nagarkattidd9e8d92025-02-28 11:20:45 -0800163# Disable unit tests when output-all-properties is enabled
164# because it changes CPER-IR output format.
165if get_option('output-all-properties').disabled()
166 if get_option('tests').allowed()
167 subdir('tests')
168 endif
Karthik Rajagopalan5220c9b2024-08-08 00:24:44 -0700169endif