|
| 1 | +project( |
| 2 | + 'aws-c-cal', |
| 3 | + 'c', |
| 4 | + version: '0.9.10', |
| 5 | + meson_version: '>=0.63.0', |
| 6 | + license: 'Apache-2.0', |
| 7 | +) |
| 8 | + |
| 9 | +cc = meson.get_compiler('c') |
| 10 | +fs = import('fs') |
| 11 | +pkg = import('pkgconfig') |
| 12 | + |
| 13 | +tests_opt = get_option('tests').disable_auto_if(meson.is_subproject()) |
| 14 | +ed25519_everywhere = get_option('ed25519_everywhere') |
| 15 | + |
| 16 | +public_c_args = ['-DAWS_CAL_USE_IMPORT_EXPORT=1'] |
| 17 | +c_args = ['-DAWS_CAL_EXPORTS=1'] |
| 18 | + |
| 19 | +if host_machine.system() == 'windows' and host_machine.cpu_family() in [ |
| 20 | + 'x86', |
| 21 | + 'aarch64', |
| 22 | +] |
| 23 | + error('unsupported architecture: only x86_64 Windows is supported') |
| 24 | +endif |
| 25 | + |
| 26 | +aws_c_common_dep = dependency('aws-c-common') |
| 27 | +libcrypto_dep = dependency( |
| 28 | + 'libcrypto', |
| 29 | + version: '>=1.1', |
| 30 | +) |
| 31 | +ncrypt = cc.find_library( |
| 32 | + 'ncrypt', |
| 33 | + required: host_machine.system() == 'windows', |
| 34 | +) |
| 35 | + |
| 36 | +foundation = dependency( |
| 37 | + 'appleframeworks', |
| 38 | + modules: ['Security', 'CoreFoundation'], |
| 39 | + required: host_machine.system() == 'darwin', |
| 40 | +) |
| 41 | + |
| 42 | +src = files( |
| 43 | + 'source/cal.c', |
| 44 | + 'source/der.c', |
| 45 | + 'source/ecc.c', |
| 46 | + 'source/ed25519.c', |
| 47 | + 'source/hash.c', |
| 48 | + 'source/hkdf.c', |
| 49 | + 'source/hmac.c', |
| 50 | + 'source/rsa.c', |
| 51 | + 'source/shared/ref_hkdf.c', |
| 52 | + 'source/symmetric_cipher.c', |
| 53 | +) |
| 54 | + |
| 55 | +if ed25519_everywhere or host_machine.system() == 'linux' |
| 56 | + src += files('source/shared/ed25519.c', 'source/shared/lccrypto_common.c') |
| 57 | + c_args = ['-DAWS_USE_LIBCRYPTO_TO_SUPPORT_ED25519_EVERYWHERE'] |
| 58 | +else |
| 59 | + src += files('source/shared/ed25519_noop.c') |
| 60 | +endif |
| 61 | + |
| 62 | +if host_machine.system() in ['cygwin', 'windows'] |
| 63 | + src += files( |
| 64 | + 'source/windows/bcrypt_aes.c', |
| 65 | + 'source/windows/bcrypt_ecc.c', |
| 66 | + 'source/windows/bcrypt_hash.c', |
| 67 | + 'source/windows/bcrypt_hmac.c', |
| 68 | + 'source/windows/bcrypt_platform_init.c', |
| 69 | + 'source/windows/bcrypt_rsa.c', |
| 70 | + ) |
| 71 | +elif host_machine.system() == 'darwin' |
| 72 | + src += files( |
| 73 | + 'source/darwin/commoncrypto_aes.c', |
| 74 | + 'source/darwin/commoncrypto_hmac.c', |
| 75 | + 'source/darwin/commoncrypto_md5.c', |
| 76 | + 'source/darwin/commoncrypto_platform_init.c', |
| 77 | + 'source/darwin/commoncrypto_sha1.c', |
| 78 | + 'source/darwin/commoncrypto_sha256.c', |
| 79 | + 'source/darwin/commoncrypto_sha512.c', |
| 80 | + 'source/darwin/securityframework_ecc.c', |
| 81 | + 'source/darwin/securityframework_rsa.c', |
| 82 | + ) |
| 83 | +elif host_machine.system() == 'linux' |
| 84 | + src += files( |
| 85 | + 'source/unix/openssl_aes.c', |
| 86 | + 'source/unix/openssl_platform_init.c', |
| 87 | + 'source/unix/openssl_rsa.c', |
| 88 | + 'source/unix/opensslcrypto_ecc.c', |
| 89 | + 'source/unix/opensslcrypto_hash.c', |
| 90 | + 'source/unix/opensslcrypto_hmac.c', |
| 91 | + ) |
| 92 | +else |
| 93 | + error('Unsupported platform: ' + host_machine.system()) |
| 94 | +endif |
| 95 | + |
| 96 | +inc = include_directories('include') |
| 97 | + |
| 98 | +libaws_c_cal = library( |
| 99 | + 'aws-c-cal', |
| 100 | + src, |
| 101 | + c_args: c_args + public_c_args, |
| 102 | + dependencies: [aws_c_common_dep, libcrypto_dep, ncrypt, foundation], |
| 103 | + include_directories: inc, |
| 104 | + version: meson.project_version(), |
| 105 | +) |
| 106 | + |
| 107 | +aws_c_cal_dep = declare_dependency( |
| 108 | + link_with: libaws_c_cal, |
| 109 | + include_directories: inc, |
| 110 | + compile_args: public_c_args, |
| 111 | +) |
| 112 | + |
| 113 | +meson.override_dependency('aws-c-cal', aws_c_cal_dep) |
| 114 | + |
| 115 | +pkg.generate( |
| 116 | + libaws_c_cal, |
| 117 | + extra_cflags: public_c_args, |
| 118 | + description: 'Aws Crypto Abstraction Layer: Cross-Platform, C99 wrapper for cryptography primitives.', |
| 119 | +) |
| 120 | + |
| 121 | +subdir('include') |
| 122 | + |
| 123 | +generate_tests = find_program( |
| 124 | + 'generate_tests.py', |
| 125 | + required: tests_opt, |
| 126 | +) |
| 127 | +run_test = find_program( |
| 128 | + 'run_test.py', |
| 129 | + required: tests_opt, |
| 130 | +) |
| 131 | + |
| 132 | +if generate_tests.found() and run_test.found() |
| 133 | + test_src = files( |
| 134 | + 'tests/aes256_test.c', |
| 135 | + 'tests/der_test.c', |
| 136 | + 'tests/ecc_test.c', |
| 137 | + 'tests/ed25519_test.c', |
| 138 | + 'tests/hkdf_test.c', |
| 139 | + 'tests/md5_test.c', |
| 140 | + 'tests/rsa_test.c', |
| 141 | + 'tests/sha1_test.c', |
| 142 | + 'tests/sha256_hmac_test.c', |
| 143 | + 'tests/sha256_test.c', |
| 144 | + 'tests/sha512_hmac_test.c', |
| 145 | + 'tests/sha512_test.c', |
| 146 | + ) |
| 147 | + |
| 148 | + libtestcases = static_library( |
| 149 | + 'aws_c_cal_testcases', |
| 150 | + test_src, |
| 151 | + dependencies: [aws_c_cal_dep, aws_c_common_dep], |
| 152 | + c_args: ['-DAWS_UNSTABLE_TESTING_API=1'], |
| 153 | + include_directories: inc, |
| 154 | + build_by_default: false, |
| 155 | + ) |
| 156 | + |
| 157 | + # implements an approximation of cmakes create_test_sourcelist |
| 158 | + test_harness_src = custom_target( |
| 159 | + 'generate_test_harness', |
| 160 | + input: 'tests.txt', |
| 161 | + output: 'test_harness.c', |
| 162 | + command: [generate_tests, '@INPUT@', '@OUTPUT@'], |
| 163 | + ) |
| 164 | + |
| 165 | + test_harness = executable( |
| 166 | + 'aws-c-cal-tests', |
| 167 | + test_harness_src, |
| 168 | + dependencies: [aws_c_cal_dep, aws_c_common_dep], |
| 169 | + link_with: [libtestcases], |
| 170 | + c_args: ['-DAWS_UNSTABLE_TESTING_API=1'], |
| 171 | + include_directories: inc, |
| 172 | + build_by_default: false, |
| 173 | + ) |
| 174 | + |
| 175 | + names = fs.read('tests.txt').split('\n') |
| 176 | + |
| 177 | + foreach name : names |
| 178 | + test( |
| 179 | + name, |
| 180 | + run_test, |
| 181 | + args: [test_harness, name], |
| 182 | + workdir: meson.current_source_dir(), |
| 183 | + timeout: 600, |
| 184 | + ) |
| 185 | + endforeach |
| 186 | +endif |
0 commit comments