|
| 1 | +project( |
| 2 | + 'libcbor', |
| 3 | + 'c', |
| 4 | + version: '0.13.0', |
| 5 | + meson_version: '>=0.63.0', |
| 6 | + default_options: ['warning_level=3'], |
| 7 | + license: 'MIT', |
| 8 | +) |
| 9 | + |
| 10 | +cc = meson.get_compiler('c') |
| 11 | + |
| 12 | +tests_opt = get_option('tests').disable_auto_if(meson.is_subproject()) |
| 13 | + |
| 14 | +subdir('src/cbor') |
| 15 | + |
| 16 | +src = [ |
| 17 | + 'src/cbor.c', |
| 18 | + 'src/allocators.c', |
| 19 | + 'src/cbor/streaming.c', |
| 20 | + 'src/cbor/internal/encoders.c', |
| 21 | + 'src/cbor/internal/builder_callbacks.c', |
| 22 | + 'src/cbor/internal/loaders.c', |
| 23 | + 'src/cbor/internal/memory_utils.c', |
| 24 | + 'src/cbor/internal/stack.c', |
| 25 | + 'src/cbor/internal/unicode.c', |
| 26 | + 'src/cbor/encoding.c', |
| 27 | + 'src/cbor/serialization.c', |
| 28 | + 'src/cbor/arrays.c', |
| 29 | + 'src/cbor/common.c', |
| 30 | + 'src/cbor/floats_ctrls.c', |
| 31 | + 'src/cbor/bytestrings.c', |
| 32 | + 'src/cbor/callbacks.c', |
| 33 | + 'src/cbor/strings.c', |
| 34 | + 'src/cbor/maps.c', |
| 35 | + 'src/cbor/tags.c', |
| 36 | + 'src/cbor/ints.c', |
| 37 | +] |
| 38 | + |
| 39 | +inc = include_directories('src') |
| 40 | + |
| 41 | +c_args = ['-DCBOR_BUILD=1'] |
| 42 | + |
| 43 | +if get_option('default_library') == 'static' |
| 44 | + c_args += ['-DCBOR_BUILD_STATIC=1'] |
| 45 | +endif |
| 46 | + |
| 47 | +libcbor = library( |
| 48 | + 'cbor', |
| 49 | + src, |
| 50 | + config_file, |
| 51 | + c_args: c_args, |
| 52 | + include_directories: inc, |
| 53 | + install: true, |
| 54 | + version: meson.project_version(), |
| 55 | + override_options: ['c_std=c11'], |
| 56 | +) |
| 57 | + |
| 58 | +libcbor_dep = declare_dependency( |
| 59 | + link_with: libcbor, |
| 60 | + include_directories: inc, |
| 61 | +) |
| 62 | + |
| 63 | +meson.override_dependency('libcbor', libcbor_dep) |
| 64 | + |
| 65 | +headers = [ |
| 66 | + config_file, |
| 67 | + 'src/cbor/streaming.h', |
| 68 | + 'src/cbor/cbor_export.h', |
| 69 | + 'src/cbor/data.h', |
| 70 | + 'src/cbor/encoding.h', |
| 71 | + 'src/cbor/serialization.h', |
| 72 | + 'src/cbor/arrays.h', |
| 73 | + 'src/cbor/common.h', |
| 74 | + 'src/cbor/floats_ctrls.h', |
| 75 | + 'src/cbor/bytestrings.h', |
| 76 | + 'src/cbor/callbacks.h', |
| 77 | + 'src/cbor/strings.h', |
| 78 | + 'src/cbor/maps.h', |
| 79 | + 'src/cbor/tags.h', |
| 80 | + 'src/cbor/ints.h', |
| 81 | +] |
| 82 | + |
| 83 | +install_headers('src/cbor.h') |
| 84 | +install_headers( |
| 85 | + headers, |
| 86 | + subdir: 'cbor', |
| 87 | +) |
| 88 | + |
| 89 | +tests = [ |
| 90 | + 'test/array_encoders_test.c', |
| 91 | + 'test/array_test.c', |
| 92 | + 'test/bad_inputs_test.c', |
| 93 | + 'test/bytestring_encoders_test.c', |
| 94 | + 'test/bytestring_test.c', |
| 95 | + 'test/cbor_serialize_test.c', |
| 96 | + 'test/cbor_stream_decode_test.c', |
| 97 | + 'test/copy_test.c', |
| 98 | + 'test/fuzz_test.c', |
| 99 | + 'test/map_encoders_test.c', |
| 100 | + 'test/map_test.c', |
| 101 | + 'test/negint_encoders_test.c', |
| 102 | + 'test/negint_test.c', |
| 103 | + 'test/pretty_printer_test.c', |
| 104 | + 'test/stack_over_limit_test.c', |
| 105 | + 'test/string_encoders_test.c', |
| 106 | + 'test/string_test.c', |
| 107 | + 'test/tag_encoders_test.c', |
| 108 | + 'test/tag_test.c', |
| 109 | + 'test/uint_encoders_test.c', |
| 110 | + 'test/uint_test.c', |
| 111 | +] |
| 112 | + |
| 113 | +if host_machine.system() != 'windows' |
| 114 | + tests += ['test/callbacks_test.c', 'test/memory_utils_test.c', 'test/unicode_test.c'] |
| 115 | +endif |
| 116 | + |
| 117 | +if cc.get_id() != 'clang-cl' |
| 118 | + tests += ['test/float_ctrl_encoders_test.c', 'test/float_ctrl_test.c'] |
| 119 | +endif |
| 120 | + |
| 121 | +cmocka = dependency( |
| 122 | + 'cmocka', |
| 123 | + required: tests_opt, |
| 124 | +) |
| 125 | +m = cc.find_library( |
| 126 | + 'm', |
| 127 | + required: false, |
| 128 | +) |
| 129 | + |
| 130 | +if cmocka.found() and tests_opt.allowed() |
| 131 | + libcbor_test = static_library( |
| 132 | + 'cbor_test', |
| 133 | + ['test/assertions.c', 'test/stream_expectations.c', 'test/test_allocator.c'], |
| 134 | + include_directories: inc, |
| 135 | + dependencies: [libcbor_dep, cmocka, m], |
| 136 | + c_args: c_args, |
| 137 | + ) |
| 138 | + |
| 139 | + foreach path : tests |
| 140 | + name = path.split('/')[1].replace('.c', '') |
| 141 | + test_exe = executable( |
| 142 | + name, |
| 143 | + path, |
| 144 | + include_directories: inc, |
| 145 | + link_with: libcbor_test, |
| 146 | + dependencies: [libcbor_dep, cmocka, m], |
| 147 | + override_options: ['c_std=c11'], |
| 148 | + ) |
| 149 | + |
| 150 | + test( |
| 151 | + name, |
| 152 | + test_exe, |
| 153 | + suite: 'libcbor', |
| 154 | + should_fail: false, |
| 155 | + ) |
| 156 | + endforeach |
| 157 | +endif |
0 commit comments