1# #############################################################################
2# Copyright (c) 2018-present     Dima Krasner <dima@dimakrasner.com>
3#                                lzutao <taolzu(at)gmail.com>
4# All rights reserved.
5#
6# This source code is licensed under both the BSD-style license (found in the
7# LICENSE file in the root directory of this source tree) and the GPLv2 (found
8# in the COPYING file in the root directory of this source tree).
9# #############################################################################
10
11zstd_rootdir = '../../..'
12
13libzstd_includes = [include_directories(join_paths(zstd_rootdir,'lib'),
14  join_paths(zstd_rootdir, 'lib/common'),
15  join_paths(zstd_rootdir, 'lib/compress'),
16  join_paths(zstd_rootdir, 'lib/decompress'),
17  join_paths(zstd_rootdir, 'lib/dictBuilder'),
18  join_paths(zstd_rootdir, 'lib/deprecated'))]
19
20libzstd_sources = [join_paths(zstd_rootdir, 'lib/common/entropy_common.c'),
21  join_paths(zstd_rootdir, 'lib/common/fse_decompress.c'),
22  join_paths(zstd_rootdir, 'lib/common/threading.c'),
23  join_paths(zstd_rootdir, 'lib/common/pool.c'),
24  join_paths(zstd_rootdir, 'lib/common/zstd_common.c'),
25  join_paths(zstd_rootdir, 'lib/common/error_private.c'),
26  join_paths(zstd_rootdir, 'lib/common/xxhash.c'),
27  join_paths(zstd_rootdir, 'lib/compress/hist.c'),
28  join_paths(zstd_rootdir, 'lib/compress/fse_compress.c'),
29  join_paths(zstd_rootdir, 'lib/compress/huf_compress.c'),
30  join_paths(zstd_rootdir, 'lib/compress/zstd_compress.c'),
31  join_paths(zstd_rootdir, 'lib/compress/zstd_compress_literals.c'),
32  join_paths(zstd_rootdir, 'lib/compress/zstd_compress_sequences.c'),
33  join_paths(zstd_rootdir, 'lib/compress/zstdmt_compress.c'),
34  join_paths(zstd_rootdir, 'lib/compress/zstd_fast.c'),
35  join_paths(zstd_rootdir, 'lib/compress/zstd_double_fast.c'),
36  join_paths(zstd_rootdir, 'lib/compress/zstd_lazy.c'),
37  join_paths(zstd_rootdir, 'lib/compress/zstd_opt.c'),
38  join_paths(zstd_rootdir, 'lib/compress/zstd_ldm.c'),
39  join_paths(zstd_rootdir, 'lib/decompress/huf_decompress.c'),
40  join_paths(zstd_rootdir, 'lib/decompress/zstd_decompress.c'),
41  join_paths(zstd_rootdir, 'lib/decompress/zstd_decompress_block.c'),
42  join_paths(zstd_rootdir, 'lib/decompress/zstd_ddict.c'),
43  join_paths(zstd_rootdir, 'lib/dictBuilder/cover.c'),
44  join_paths(zstd_rootdir, 'lib/dictBuilder/fastcover.c'),
45  join_paths(zstd_rootdir, 'lib/dictBuilder/divsufsort.c'),
46  join_paths(zstd_rootdir, 'lib/dictBuilder/zdict.c'),
47  join_paths(zstd_rootdir, 'lib/deprecated/zbuff_common.c'),
48  join_paths(zstd_rootdir, 'lib/deprecated/zbuff_compress.c'),
49  join_paths(zstd_rootdir, 'lib/deprecated/zbuff_decompress.c')]
50
51# Explicit define legacy support
52add_project_arguments('-DZSTD_LEGACY_SUPPORT=@0@'.format(legacy_level),
53  language: 'c')
54
55if legacy_level == 0
56  message('Legacy support: DISABLED')
57else
58  # See ZSTD_LEGACY_SUPPORT of lib/README.md
59  message('Enable legacy support back to version 0.@0@'.format(legacy_level))
60
61  libzstd_includes += [ include_directories(join_paths(zstd_rootdir, 'lib/legacy')) ]
62  foreach i : [1, 2, 3, 4, 5, 6, 7]
63    if legacy_level <= i
64      libzstd_sources += join_paths(zstd_rootdir, 'lib/legacy/zstd_v0@0@.c'.format(i))
65    endif
66  endforeach
67endif
68
69libzstd_deps = []
70if use_multi_thread
71  message('Enable multi-threading support')
72  add_project_arguments('-DZSTD_MULTITHREAD', language: 'c')
73  libzstd_deps = [ thread_dep ]
74endif
75
76libzstd_c_args = []
77if cc_id == compiler_msvc
78  if default_library_type != 'static'
79    libzstd_sources += [windows_mod.compile_resources(
80      join_paths(zstd_rootdir, 'build/VS2010/libzstd-dll/libzstd-dll.rc'))]
81    libzstd_c_args += ['-DZSTD_DLL_EXPORT=1',
82      '-DZSTD_HEAPMODE=0',
83      '-D_CONSOLE',
84      '-D_CRT_SECURE_NO_WARNINGS']
85  else
86    libzstd_c_args += ['-DZSTD_HEAPMODE=0',
87      '-D_CRT_SECURE_NO_WARNINGS']
88  endif
89endif
90
91mingw_ansi_stdio_flags = []
92if host_machine_os == os_windows and cc_id == compiler_gcc
93  mingw_ansi_stdio_flags = [ '-D__USE_MINGW_ANSI_STDIO' ]
94endif
95libzstd_c_args += mingw_ansi_stdio_flags
96
97libzstd_debug_cflags = []
98if use_debug
99  libzstd_c_args += '-DDEBUGLEVEL=@0@'.format(debug_level)
100  if cc_id == compiler_gcc or cc_id == compiler_clang
101    libzstd_debug_cflags = ['-Wstrict-aliasing=1', '-Wswitch-enum',
102      '-Wdeclaration-after-statement', '-Wstrict-prototypes',
103      '-Wundef', '-Wpointer-arith', '-Wvla',
104      '-Wformat=2', '-Winit-self', '-Wfloat-equal', '-Wwrite-strings',
105      '-Wredundant-decls', '-Wmissing-prototypes', '-Wc++-compat']
106  endif
107endif
108libzstd_c_args += cc.get_supported_arguments(libzstd_debug_cflags)
109
110libzstd = library('zstd',
111  libzstd_sources,
112  include_directories: libzstd_includes,
113  c_args: libzstd_c_args,
114  dependencies: libzstd_deps,
115  install: true,
116  version: zstd_libversion)
117
118libzstd_dep = declare_dependency(link_with: libzstd,
119  include_directories: libzstd_includes)
120
121pkgconfig.generate(libzstd,
122  name: 'libzstd',
123  filebase: 'libzstd',
124  description: 'fast lossless compression algorithm library',
125  version: zstd_libversion,
126  url: 'http://www.zstd.net/')
127
128install_headers(join_paths(zstd_rootdir, 'lib/zstd.h'),
129  join_paths(zstd_rootdir, 'lib/deprecated/zbuff.h'),
130  join_paths(zstd_rootdir, 'lib/dictBuilder/zdict.h'),
131  join_paths(zstd_rootdir, 'lib/common/zstd_errors.h'))
132