| John Chung | 197ea12 | 2024-05-03 19:57:55 +0800 | [diff] [blame] | 1 | project( | 
| Ed Tanous | a5b3d49 | 2024-06-18 13:24:05 -0700 | [diff] [blame] | 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 | ) | 
| John Chung | 197ea12 | 2024-05-03 19:57:55 +0800 | [diff] [blame] | 14 |  | 
| Andrew Adriance | 1a90898 | 2024-07-02 14:26:10 -0700 | [diff] [blame^] | 15 | library_is_share = get_option('default_library') == 'shared' | 
 | 16 |  | 
| John Chung | 197ea12 | 2024-05-03 19:57:55 +0800 | [diff] [blame] | 17 | project_description = 'libcper library' | 
 | 18 |  | 
 | 19 | SectionSources = files( | 
| Ed Tanous | a5b3d49 | 2024-06-18 13:24:05 -0700 | [diff] [blame] | 20 |     'sections/cper-section-arm.c', | 
 | 21 |     'sections/cper-section-ccix-per.c', | 
 | 22 |     'sections/cper-section-cxl-component.c', | 
 | 23 |     'sections/cper-section-cxl-protocol.c', | 
 | 24 |     'sections/cper-section-dmar-generic.c', | 
 | 25 |     'sections/cper-section-dmar-iommu.c', | 
 | 26 |     'sections/cper-section-dmar-vtd.c', | 
 | 27 |     'sections/cper-section-firmware.c', | 
 | 28 |     'sections/cper-section-generic.c', | 
 | 29 |     'sections/cper-section-ia32x64.c', | 
 | 30 |     'sections/cper-section-ipf.c', | 
 | 31 |     'sections/cper-section-memory.c', | 
 | 32 |     'sections/cper-section-pci-bus.c', | 
 | 33 |     'sections/cper-section-pci-dev.c', | 
 | 34 |     'sections/cper-section-pcie.c', | 
 | 35 |     'sections/cper-section.c', | 
| John Chung | 197ea12 | 2024-05-03 19:57:55 +0800 | [diff] [blame] | 36 | ) | 
 | 37 |  | 
| Ed Tanous | a5b3d49 | 2024-06-18 13:24:05 -0700 | [diff] [blame] | 38 | EDKSources = files('edk/Cper.c') | 
| John Chung | 197ea12 | 2024-05-03 19:57:55 +0800 | [diff] [blame] | 39 |  | 
 | 40 | GeneratorSectionSources = files( | 
| Ed Tanous | a5b3d49 | 2024-06-18 13:24:05 -0700 | [diff] [blame] | 41 |     'generator/sections/gen-section-arm.c', | 
 | 42 |     'generator/sections/gen-section-ccix-per.c', | 
 | 43 |     'generator/sections/gen-section-cxl-component.c', | 
 | 44 |     'generator/sections/gen-section-cxl-protocol.c', | 
 | 45 |     'generator/sections/gen-section-dmar.c', | 
 | 46 |     'generator/sections/gen-section-firmware.c', | 
 | 47 |     'generator/sections/gen-section-generic.c', | 
 | 48 |     'generator/sections/gen-section-ia32x64.c', | 
 | 49 |     'generator/sections/gen-section-memory.c', | 
 | 50 |     'generator/sections/gen-section-pci-bus.c', | 
 | 51 |     'generator/sections/gen-section-pci-dev.c', | 
 | 52 |     'generator/sections/gen-section-pcie.c', | 
 | 53 |     'generator/sections/gen-section.c', | 
| John Chung | 197ea12 | 2024-05-03 19:57:55 +0800 | [diff] [blame] | 54 | ) | 
 | 55 |  | 
 | 56 | cmake = import('cmake') | 
| John Chung | abc62b8 | 2024-05-22 22:45:36 +0800 | [diff] [blame] | 57 | cc = meson.get_compiler('c') | 
| John Chung | 197ea12 | 2024-05-03 19:57:55 +0800 | [diff] [blame] | 58 |  | 
| Ed Tanous | a5b3d49 | 2024-06-18 13:24:05 -0700 | [diff] [blame] | 59 | json_c_dep = dependency('json-c', required: true, fallback: ['json-c', 'json_c_dep']) | 
| John Chung | 197ea12 | 2024-05-03 19:57:55 +0800 | [diff] [blame] | 60 |  | 
| John Chung | abc62b8 | 2024-05-22 22:45:36 +0800 | [diff] [blame] | 61 | libb64 = cc.find_library('base64', has_headers: 'libbase64.h', required: false) | 
| John Chung | 197ea12 | 2024-05-03 19:57:55 +0800 | [diff] [blame] | 62 | if not libb64.found() | 
| Ed Tanous | a5b3d49 | 2024-06-18 13:24:05 -0700 | [diff] [blame] | 63 |     opt_var = cmake.subproject_options() | 
 | 64 |     opt_var.add_cmake_defines( | 
 | 65 |         { | 
| Andrew Adriance | 1a90898 | 2024-07-02 14:26:10 -0700 | [diff] [blame^] | 66 |             'BUILD_SHARED_LIBS': library_is_share, | 
| Ed Tanous | a5b3d49 | 2024-06-18 13:24:05 -0700 | [diff] [blame] | 67 |             'BASE64_BUILD_CLI': false, | 
 | 68 |             'BASE64_WITH_AVX': false, | 
 | 69 |             'BASE64_WITH_AVX2': false, | 
 | 70 |             'BASE64_WITH_AVX512': false, | 
 | 71 |             'BASE64_WITH_SSSE3': false, | 
 | 72 |             'BASE64_WITH_SSE41': false, | 
 | 73 |             'BASE64_WITH_SSE42': false, | 
 | 74 |         }, | 
 | 75 |     ) | 
| John Chung | 197ea12 | 2024-05-03 19:57:55 +0800 | [diff] [blame] | 76 |  | 
| Ed Tanous | a5b3d49 | 2024-06-18 13:24:05 -0700 | [diff] [blame] | 77 |     libb64_ex = cmake.subproject('libb64', options: opt_var) | 
 | 78 |     libb64 = libb64_ex.dependency('base64') | 
| John Chung | 197ea12 | 2024-05-03 19:57:55 +0800 | [diff] [blame] | 79 | endif | 
 | 80 |  | 
 | 81 | libcper_parse_sources = [ | 
| Ed Tanous | a5b3d49 | 2024-06-18 13:24:05 -0700 | [diff] [blame] | 82 |     'cper-parse.c', | 
 | 83 |     'ir-parse.c', | 
 | 84 |     'cper-utils.c', | 
 | 85 |     'common-utils.c', | 
 | 86 |     'json-schema.c', | 
| John Chung | 197ea12 | 2024-05-03 19:57:55 +0800 | [diff] [blame] | 87 | ] | 
 | 88 |  | 
 | 89 | libcper_include = ['.'] | 
 | 90 |  | 
 | 91 | libcper_parse = library( | 
| Ed Tanous | a5b3d49 | 2024-06-18 13:24:05 -0700 | [diff] [blame] | 92 |     'cper-parse', | 
 | 93 |     libcper_parse_sources, | 
 | 94 |     SectionSources, | 
 | 95 |     EDKSources, | 
 | 96 |     version: meson.project_version(), | 
 | 97 |     include_directories: include_directories(libcper_include), | 
 | 98 |     c_args: '-Wno-address-of-packed-member', | 
 | 99 |     dependencies: [ | 
 | 100 |         json_c_dep, | 
 | 101 |         libb64, | 
 | 102 |     ], | 
 | 103 |     install: true, | 
 | 104 |     install_dir: get_option('libdir'), | 
| John Chung | 197ea12 | 2024-05-03 19:57:55 +0800 | [diff] [blame] | 105 | ) | 
 | 106 | libcper_parse = declare_dependency( | 
| Ed Tanous | a5b3d49 | 2024-06-18 13:24:05 -0700 | [diff] [blame] | 107 |     include_directories: include_directories(libcper_include), | 
 | 108 |     link_with: libcper_parse, | 
| John Chung | 197ea12 | 2024-05-03 19:57:55 +0800 | [diff] [blame] | 109 | ) | 
 | 110 |  | 
| Ed Tanous | a5b3d49 | 2024-06-18 13:24:05 -0700 | [diff] [blame] | 111 | libcper_generate_sources = ['generator/cper-generate.c', 'generator/gen-utils.c', 'common-utils.c'] | 
| John Chung | 197ea12 | 2024-05-03 19:57:55 +0800 | [diff] [blame] | 112 |  | 
 | 113 | libcper_generate = library( | 
| Ed Tanous | a5b3d49 | 2024-06-18 13:24:05 -0700 | [diff] [blame] | 114 |     'cper-generate', | 
 | 115 |     libcper_generate_sources, | 
 | 116 |     GeneratorSectionSources, | 
 | 117 |     version: meson.project_version(), | 
 | 118 |     include_directories: include_directories(libcper_include), | 
 | 119 |     dependencies: [ | 
 | 120 |         libcper_parse, | 
 | 121 |         json_c_dep, | 
 | 122 |         libb64, | 
 | 123 |     ], | 
 | 124 |     install: true, | 
 | 125 |     install_dir: get_option('libdir'), | 
| John Chung | 197ea12 | 2024-05-03 19:57:55 +0800 | [diff] [blame] | 126 | ) | 
 | 127 | libcper_generate = declare_dependency( | 
| Ed Tanous | a5b3d49 | 2024-06-18 13:24:05 -0700 | [diff] [blame] | 128 |     include_directories: include_directories(libcper_include), | 
 | 129 |     link_with: libcper_generate, | 
| John Chung | 197ea12 | 2024-05-03 19:57:55 +0800 | [diff] [blame] | 130 | ) | 
 | 131 |  | 
| John Chung | abc62b8 | 2024-05-22 22:45:36 +0800 | [diff] [blame] | 132 | install_headers('cper-parse.h') | 
 | 133 | install_headers('cper-utils.h') | 
 | 134 | install_headers('common-utils.h') | 
 | 135 | install_headers('generator/cper-generate.h', subdir: 'generator') | 
 | 136 | install_headers('edk/Cper.h', subdir: 'edk') | 
 | 137 | install_headers('edk/BaseTypes.h', subdir: 'edk') | 
| John Chung | 197ea12 | 2024-05-03 19:57:55 +0800 | [diff] [blame] | 138 |  | 
| John Chung | abc62b8 | 2024-05-22 22:45:36 +0800 | [diff] [blame] | 139 | if get_option('utility').allowed() | 
| Ed Tanous | a5b3d49 | 2024-06-18 13:24:05 -0700 | [diff] [blame] | 140 |     executable( | 
 | 141 |         'cper-convert', | 
 | 142 |         'cli-app/cper-convert.c', | 
 | 143 |         include_directories: include_directories(libcper_include), | 
 | 144 |         dependencies: [ | 
 | 145 |             libcper_parse, | 
 | 146 |             json_c_dep, | 
 | 147 |         ], | 
 | 148 |         install: true, | 
 | 149 |         install_dir: get_option('bindir'), | 
 | 150 |     ) | 
| John Chung | abc62b8 | 2024-05-22 22:45:36 +0800 | [diff] [blame] | 151 |  | 
| Ed Tanous | a5b3d49 | 2024-06-18 13:24:05 -0700 | [diff] [blame] | 152 |     executable( | 
 | 153 |         'cper-generate', | 
 | 154 |         'generator/cper-generate-cli.c', | 
 | 155 |         EDKSources, | 
 | 156 |         include_directories: include_directories(libcper_include), | 
 | 157 |         dependencies: [ | 
 | 158 |             libcper_generate, | 
 | 159 |         ], | 
 | 160 |         install: true, | 
 | 161 |         install_dir: get_option('bindir'), | 
 | 162 |     ) | 
| John Chung | abc62b8 | 2024-05-22 22:45:36 +0800 | [diff] [blame] | 163 | endif | 
| John Chung | 197ea12 | 2024-05-03 19:57:55 +0800 | [diff] [blame] | 164 |  | 
| Ed Tanous | 1e267b6 | 2024-06-18 13:20:42 -0700 | [diff] [blame] | 165 | run_command('cp', '-r', 'specification/json/', meson.current_build_dir(), check: true) | 
| Ed Tanous | a5b3d49 | 2024-06-18 13:24:05 -0700 | [diff] [blame] | 166 | run_command( | 
 | 167 |     'mv', | 
 | 168 |     meson.current_build_dir() / 'json', | 
 | 169 |     meson.current_build_dir() / 'specification', | 
 | 170 | ) | 
| John Chung | 197ea12 | 2024-05-03 19:57:55 +0800 | [diff] [blame] | 171 |  | 
 | 172 | if get_option('tests').allowed() | 
| Ed Tanous | a5b3d49 | 2024-06-18 13:24:05 -0700 | [diff] [blame] | 173 |     subdir('tests') | 
| John Chung | 197ea12 | 2024-05-03 19:57:55 +0800 | [diff] [blame] | 174 | endif |