|
| 1 | +project( |
| 2 | + 'aklomp-base64', |
| 3 | + 'c', |
| 4 | + version: '0.5.2', |
| 5 | + license: 'BSD-2-Clause', |
| 6 | + meson_version: '>=0.59.0', |
| 7 | + default_options: ['warning_level=3'], |
| 8 | +) |
| 9 | + |
| 10 | +cc = meson.get_compiler('c') |
| 11 | +tests_opt = get_option('tests').disable_auto_if(meson.is_subproject()) |
| 12 | + |
| 13 | +c_args = ['-DBASE64_EXPORTS'] |
| 14 | +config = configuration_data() |
| 15 | + |
| 16 | +if get_option('default_library') == 'static' |
| 17 | + c_args += ['-DBASE64_STATIC_DEFINE'] |
| 18 | +endif |
| 19 | + |
| 20 | +neon32_supported = host_machine.cpu_family() == 'arm' and cc.has_argument( |
| 21 | + '-mfpu=neon', |
| 22 | +) |
| 23 | + |
| 24 | +is_x86 = host_machine.cpu_family() in ['x86', 'x86_64'] |
| 25 | +config.set10('BASE64_WITH_NEON32', neon32_supported) |
| 26 | +config.set10('BASE64_WITH_NEON64', host_machine.cpu_family() == 'aarch64') |
| 27 | + |
| 28 | +present_flags = {} |
| 29 | +arch_flags = {} |
| 30 | + |
| 31 | +if cc.get_id() == 'msvc' |
| 32 | + arch_flags += { |
| 33 | + 'SSSE3': [], |
| 34 | + 'SSE41': [], |
| 35 | + 'SSE42': [], |
| 36 | + 'AVX': ['/arch:AVX'], |
| 37 | + 'AVX2': ['/arch:AVX2'], |
| 38 | + 'AVX512': ['/arch:AVX512'], |
| 39 | + } |
| 40 | + |
| 41 | + present_flags += { |
| 42 | + 'SSSE3': true, |
| 43 | + 'SSE41': true, |
| 44 | + 'SSE42': true, |
| 45 | + } |
| 46 | + |
| 47 | + config.set10('BASE64_WITH_SSSE3', is_x86) |
| 48 | + config.set10('BASE64_WITH_SSE41', is_x86) |
| 49 | + config.set10('BASE64_WITH_SSE42', is_x86) |
| 50 | +else |
| 51 | + arch_flags += { |
| 52 | + 'SSSE3': ['-mssse3'], |
| 53 | + 'SSE41': ['-msse4.1'], |
| 54 | + 'SSE42': ['-msse4.2'], |
| 55 | + 'AVX': ['-mavx'], |
| 56 | + 'AVX2': ['-mavx2'], |
| 57 | + 'AVX512': ['-mavx512vl', '-mavx512vbmi'], |
| 58 | + } |
| 59 | +endif |
| 60 | + |
| 61 | +foreach feature, flags : arch_flags |
| 62 | + present = is_x86 and cc.has_multi_arguments(flags) |
| 63 | + config.set10('BASE64_WITH_' + feature, present) |
| 64 | + present_flags += { |
| 65 | + feature: present, |
| 66 | + } |
| 67 | +endforeach |
| 68 | + |
| 69 | +cfg = configure_file( |
| 70 | + input: 'cmake/config.h.in', |
| 71 | + output: 'config.h', |
| 72 | + configuration: config, |
| 73 | + format: 'cmake', |
| 74 | +) |
| 75 | + |
| 76 | +codecs = [] |
| 77 | + |
| 78 | +codecs += [ |
| 79 | + static_library( |
| 80 | + 'aklomp-base64-generic', |
| 81 | + 'lib/arch/generic/codec.c', |
| 82 | + 'lib/tables/tables.c', |
| 83 | + cfg, |
| 84 | + c_args: c_args, |
| 85 | + override_options: ['c_std=c99'], |
| 86 | + ), |
| 87 | + static_library( |
| 88 | + 'aklomp-base64-ssse3', |
| 89 | + 'lib/arch/ssse3/codec.c', |
| 90 | + cfg, |
| 91 | + c_args: c_args + (present_flags['SSSE3'] ? arch_flags['SSSE3'] : []), |
| 92 | + override_options: ['c_std=c99'], |
| 93 | + ), |
| 94 | + static_library( |
| 95 | + 'aklomp-base64-sse41', |
| 96 | + 'lib/arch/sse41/codec.c', |
| 97 | + cfg, |
| 98 | + c_args: c_args + (present_flags['SSE41'] ? arch_flags['SSE41'] : []), |
| 99 | + override_options: ['c_std=c99'], |
| 100 | + ), |
| 101 | + static_library( |
| 102 | + 'aklomp-base64-sse42', |
| 103 | + 'lib/arch/sse42/codec.c', |
| 104 | + cfg, |
| 105 | + c_args: c_args + (present_flags['SSE42'] ? arch_flags['SSE42'] : []), |
| 106 | + override_options: ['c_std=c99'], |
| 107 | + ), |
| 108 | + static_library( |
| 109 | + 'aklomp-base64-avx', |
| 110 | + 'lib/arch/avx/codec.c', |
| 111 | + cfg, |
| 112 | + c_args: c_args + (present_flags['AVX'] ? arch_flags['AVX'] : []), |
| 113 | + override_options: ['c_std=c99'], |
| 114 | + ), |
| 115 | + static_library( |
| 116 | + 'aklomp-base64-avx2', |
| 117 | + 'lib/arch/avx2/codec.c', |
| 118 | + cfg, |
| 119 | + c_args: c_args + (present_flags['AVX2'] ? arch_flags['AVX2'] : []), |
| 120 | + override_options: ['c_std=c99'], |
| 121 | + ), |
| 122 | + static_library( |
| 123 | + 'aklomp-base64-avx512', |
| 124 | + 'lib/arch/avx512/codec.c', |
| 125 | + cfg, |
| 126 | + c_args: c_args + (present_flags['AVX512'] ? arch_flags['AVX512'] : []), |
| 127 | + override_options: ['c_std=c99'], |
| 128 | + ), |
| 129 | + static_library( |
| 130 | + 'aklomp-base64-neon32', |
| 131 | + 'lib/arch/neon32/codec.c', |
| 132 | + cfg, |
| 133 | + c_args: c_args + (neon32_supported ? ['-mfpu=neon'] : []), |
| 134 | + override_options: ['c_std=c99'], |
| 135 | + ), |
| 136 | + static_library( |
| 137 | + 'aklomp-base64-neon64', |
| 138 | + 'lib/arch/neon64/codec.c', |
| 139 | + cfg, |
| 140 | + c_args: c_args, |
| 141 | + override_options: ['c_std=c99'], |
| 142 | + ), |
| 143 | +] |
| 144 | + |
| 145 | +src = [cfg, 'lib/lib.c', 'lib/codec_choose.c'] |
| 146 | + |
| 147 | +inc = include_directories('include') |
| 148 | + |
| 149 | +libbase64 = library( |
| 150 | + 'base64', |
| 151 | + src, |
| 152 | + c_args: c_args, |
| 153 | + include_directories: inc, |
| 154 | + link_with: codecs, |
| 155 | + install: true, |
| 156 | + version: meson.project_version(), |
| 157 | + override_options: ['c_std=c99'], |
| 158 | + gnu_symbol_visibility: 'hidden', |
| 159 | +) |
| 160 | + |
| 161 | +base64_dep = declare_dependency( |
| 162 | + include_directories: inc, |
| 163 | + link_with: libbase64, |
| 164 | +) |
| 165 | + |
| 166 | +install_headers('include/libbase64.h') |
| 167 | + |
| 168 | +meson.override_dependency('base64', base64_dep) |
| 169 | + |
| 170 | +if tests_opt.allowed() |
| 171 | + test_src = files('test/codec_supported.c', 'test/test_base64.c') |
| 172 | + |
| 173 | + test_exe = executable( |
| 174 | + 'base64-test', |
| 175 | + test_src, |
| 176 | + include_directories: inc, |
| 177 | + link_with: libbase64, |
| 178 | + override_options: ['c_std=c99'], |
| 179 | + build_by_default: false, |
| 180 | + ) |
| 181 | + test('base64', test_exe) |
| 182 | +endif |
0 commit comments