1project('zstd', 'c', license: 'BSD')
2
3libm = meson.get_compiler('c').find_library('m', required: true)
4
5lib_dir = join_paths('..', '..', 'lib')
6common_dir = join_paths(lib_dir, 'common')
7compress_dir = join_paths(lib_dir, 'compress')
8decompress_dir = join_paths(lib_dir, 'decompress')
9dictbuilder_dir = join_paths(lib_dir, 'dictBuilder')
10deprecated_dir = join_paths(lib_dir, 'deprecated')
11
12libzstd_srcs = [
13    join_paths(common_dir, 'entropy_common.c'),
14    join_paths(common_dir, 'fse_decompress.c'),
15    join_paths(common_dir, 'threading.c'),
16    join_paths(common_dir, 'pool.c'),
17    join_paths(common_dir, 'zstd_common.c'),
18    join_paths(common_dir, 'error_private.c'),
19    join_paths(common_dir, 'xxhash.c'),
20    join_paths(compress_dir, 'fse_compress.c'),
21    join_paths(compress_dir, 'huf_compress.c'),
22    join_paths(compress_dir, 'zstd_compress.c'),
23    join_paths(compress_dir, 'zstd_fast.c'),
24    join_paths(compress_dir, 'zstd_double_fast.c'),
25    join_paths(compress_dir, 'zstd_lazy.c'),
26    join_paths(compress_dir, 'zstd_opt.c'),
27    join_paths(compress_dir, 'zstd_ldm.c'),
28    join_paths(compress_dir, 'zstdmt_compress.c'),
29    join_paths(decompress_dir, 'huf_decompress.c'),
30    join_paths(decompress_dir, 'zstd_decompress.c'),
31    join_paths(dictbuilder_dir, 'cover.c'),
32    join_paths(dictbuilder_dir, 'divsufsort.c'),
33    join_paths(dictbuilder_dir, 'zdict.c'),
34    join_paths(deprecated_dir, 'zbuff_common.c'),
35    join_paths(deprecated_dir, 'zbuff_compress.c'),
36    join_paths(deprecated_dir, 'zbuff_decompress.c')
37]
38
39libzstd_includes = [include_directories(common_dir, dictbuilder_dir, compress_dir, lib_dir)]
40
41legacy = get_option('legacy_support')
42if legacy == '0'
43    legacy = 'false'
44endif
45if legacy != 'false'
46    if legacy == 'true'
47        legacy = '1'
48    endif
49    #See ZSTD_LEGACY_SUPPORT of programs/README.md
50    message('Enabling legacy support back to version 0.' + legacy)
51    legacy_int = legacy.to_int()
52    if legacy_int > 7
53        legacy_int = 7
54    endif
55    libzstd_cflags = ['-DZSTD_LEGACY_SUPPORT=' + legacy]
56
57    legacy_dir = join_paths(lib_dir, 'legacy')
58    libzstd_includes += [include_directories(legacy_dir)]
59    if legacy_int <= 1
60        libzstd_srcs += join_paths(legacy_dir, 'zstd_v01.c')
61    endif
62    if legacy_int <= 2
63        libzstd_srcs += join_paths(legacy_dir, 'zstd_v02.c')
64    endif
65    if legacy_int <= 3
66        libzstd_srcs += join_paths(legacy_dir, 'zstd_v03.c')
67    endif
68    if legacy_int <= 4
69        libzstd_srcs += join_paths(legacy_dir, 'zstd_v04.c')
70    endif
71    if legacy_int <= 5
72        libzstd_srcs += join_paths(legacy_dir, 'zstd_v05.c')
73    endif
74    if legacy_int <= 6
75        libzstd_srcs += join_paths(legacy_dir, 'zstd_v06.c')
76    endif
77    if legacy_int <= 7
78        libzstd_srcs += join_paths(legacy_dir, 'zstd_v07.c')
79    endif
80else
81    libzstd_cflags = []
82endif
83
84if get_option('multithread')
85    message('Enabling multi-threading support')
86    add_global_arguments('-DZSTD_MULTITHREAD', language: 'c')
87    libzstd_deps = [dependency('threads')]
88else
89    libzstd_deps = []
90endif
91
92libzstd = library('zstd',
93                  libzstd_srcs,
94                  include_directories: libzstd_includes,
95                  c_args: libzstd_cflags,
96                  dependencies: libzstd_deps,
97                  install: true,
98                  soversion: '1',
99                 )
100
101programs_dir = join_paths('..', '..', 'programs')
102
103zstd = executable('zstd',
104                  join_paths(programs_dir, 'bench.c'),
105                  join_paths(programs_dir, 'datagen.c'),
106                  join_paths(programs_dir, 'dibio.c'),
107                  join_paths(programs_dir, 'fileio.c'),
108                  join_paths(programs_dir, 'zstdcli.c'),
109                  include_directories: libzstd_includes,
110                  c_args: ['-DZSTD_NODICT', '-DZSTD_NOBENCH'],
111                  link_with: libzstd,
112                  install: true)
113
114tests_dir = join_paths('..', '..', 'tests')
115datagen_c = join_paths(programs_dir, 'datagen.c')
116test_includes = libzstd_includes + [include_directories(programs_dir)]
117
118fullbench = executable('fullbench',
119                       datagen_c, join_paths(tests_dir, 'fullbench.c'),
120                       include_directories: test_includes,
121                       link_with: libzstd)
122test('fullbench', fullbench)
123
124fuzzer = executable('fuzzer',
125                    datagen_c, join_paths(tests_dir, 'fuzzer.c'),
126                    include_directories: test_includes,
127                    link_with: libzstd)
128test('fuzzer', fuzzer)
129
130if target_machine.system() != 'windows'
131    paramgrill = executable('paramgrill',
132                            datagen_c, join_paths(tests_dir, 'paramgrill.c'),
133                            include_directories: test_includes,
134                            link_with: libzstd,
135                            dependencies: libm)
136    test('paramgrill', paramgrill)
137
138    datagen = executable('datagen',
139                         datagen_c, join_paths(tests_dir, 'datagencli.c'),
140                         include_directories: test_includes,
141                         link_with: libzstd)
142endif
143