• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
19libzstd_sources = [join_paths(zstd_rootdir, 'lib/common/entropy_common.c'),
20  join_paths(zstd_rootdir, 'lib/common/fse_decompress.c'),
21  join_paths(zstd_rootdir, 'lib/common/threading.c'),
22  join_paths(zstd_rootdir, 'lib/common/pool.c'),
23  join_paths(zstd_rootdir, 'lib/common/zstd_common.c'),
24  join_paths(zstd_rootdir, 'lib/common/error_private.c'),
25  join_paths(zstd_rootdir, 'lib/common/xxhash.c'),
26  join_paths(zstd_rootdir, 'lib/compress/hist.c'),
27  join_paths(zstd_rootdir, 'lib/compress/fse_compress.c'),
28  join_paths(zstd_rootdir, 'lib/compress/huf_compress.c'),
29  join_paths(zstd_rootdir, 'lib/compress/zstd_compress.c'),
30  join_paths(zstd_rootdir, 'lib/compress/zstd_compress_literals.c'),
31  join_paths(zstd_rootdir, 'lib/compress/zstd_compress_sequences.c'),
32  join_paths(zstd_rootdir, 'lib/compress/zstd_compress_superblock.c'),
33  join_paths(zstd_rootdir, 'lib/compress/zstd_preSplit.c'),
34  join_paths(zstd_rootdir, 'lib/compress/zstdmt_compress.c'),
35  join_paths(zstd_rootdir, 'lib/compress/zstd_fast.c'),
36  join_paths(zstd_rootdir, 'lib/compress/zstd_double_fast.c'),
37  join_paths(zstd_rootdir, 'lib/compress/zstd_lazy.c'),
38  join_paths(zstd_rootdir, 'lib/compress/zstd_opt.c'),
39  join_paths(zstd_rootdir, 'lib/compress/zstd_ldm.c'),
40  join_paths(zstd_rootdir, 'lib/decompress/huf_decompress.c'),
41  join_paths(zstd_rootdir, 'lib/decompress/zstd_decompress.c'),
42  join_paths(zstd_rootdir, 'lib/decompress/zstd_decompress_block.c'),
43  join_paths(zstd_rootdir, 'lib/decompress/zstd_ddict.c'),
44  join_paths(zstd_rootdir, 'lib/dictBuilder/cover.c'),
45  join_paths(zstd_rootdir, 'lib/dictBuilder/fastcover.c'),
46  join_paths(zstd_rootdir, 'lib/dictBuilder/divsufsort.c'),
47  join_paths(zstd_rootdir, 'lib/dictBuilder/zdict.c')]
48
49# really we need anything that defines __GNUC__ as that is what ZSTD_ASM_SUPPORTED is gated on
50# but these are the two compilers that are supported in tree and actually handle this correctly
51# Otherwise, explicitly disable assembly.
52if [compiler_gcc, compiler_clang].contains(cc_id)
53  libzstd_sources += join_paths(zstd_rootdir, 'lib/decompress/huf_decompress_amd64.S')
54else
55  add_project_arguments('-DZSTD_DISABLE_ASM', language: 'c')
56endif
57
58# Explicit define legacy support
59add_project_arguments('-DZSTD_LEGACY_SUPPORT=@0@'.format(legacy_level),
60  language: 'c')
61
62if legacy_level == 0
63  message('Legacy support: DISABLED')
64else
65  # See ZSTD_LEGACY_SUPPORT of lib/README.md
66  message('Enable legacy support back to version 0.@0@'.format(legacy_level))
67
68  libzstd_includes += [ include_directories(join_paths(zstd_rootdir, 'lib/legacy')) ]
69  foreach i : [1, 2, 3, 4, 5, 6, 7]
70    if legacy_level <= i
71      libzstd_sources += join_paths(zstd_rootdir, 'lib/legacy/zstd_v0@0@.c'.format(i))
72    endif
73  endforeach
74endif
75
76libzstd_deps = []
77if use_multi_thread
78  message('Enable multi-threading support')
79  add_project_arguments('-DZSTD_MULTITHREAD', language: 'c')
80  libzstd_deps = [ thread_dep ]
81endif
82
83libzstd_c_args = []
84if cc_id == compiler_msvc
85  if default_library_type != 'static'
86    libzstd_sources += [windows_mod.compile_resources(
87      join_paths(zstd_rootdir, 'build/VS2010/libzstd-dll/libzstd-dll.rc'),
88      include_directories: libzstd_includes)]
89    libzstd_c_args += ['-DZSTD_DLL_EXPORT=1',
90      '-DZSTD_HEAPMODE=0',
91      '-D_CONSOLE',
92      '-D_CRT_SECURE_NO_WARNINGS']
93  else
94    libzstd_c_args += ['-DZSTD_HEAPMODE=0',
95      '-D_CRT_SECURE_NO_WARNINGS']
96  endif
97endif
98
99mingw_ansi_stdio_flags = []
100if host_machine_os == os_windows and cc_id == compiler_gcc
101  mingw_ansi_stdio_flags = [ '-D__USE_MINGW_ANSI_STDIO' ]
102endif
103libzstd_c_args += mingw_ansi_stdio_flags
104
105libzstd_debug_cflags = []
106if use_debug
107  libzstd_c_args += '-DDEBUGLEVEL=@0@'.format(debug_level)
108  if cc_id == compiler_gcc or cc_id == compiler_clang
109    libzstd_debug_cflags = ['-Wstrict-aliasing=1', '-Wswitch-enum',
110      '-Wdeclaration-after-statement', '-Wstrict-prototypes',
111      '-Wundef', '-Wpointer-arith', '-Wvla',
112      '-Wformat=2', '-Winit-self', '-Wfloat-equal', '-Wwrite-strings',
113      '-Wredundant-decls', '-Wmissing-prototypes', '-Wc++-compat']
114  endif
115endif
116libzstd_c_args += cc.get_supported_arguments(libzstd_debug_cflags)
117
118libzstd = library('zstd',
119  libzstd_sources,
120  include_directories: libzstd_includes,
121  c_args: libzstd_c_args,
122  gnu_symbol_visibility: 'hidden',
123  dependencies: libzstd_deps,
124  install: true,
125  version: zstd_libversion)
126
127libzstd_dep = declare_dependency(link_with: libzstd,
128  include_directories: join_paths(zstd_rootdir,'lib')) # Do not expose private headers
129
130# we link to both:
131# - the shared library (for public symbols)
132# - the static library (for private symbols)
133#
134# this is needed because internally private symbols are used all the time, and
135# -fvisibility=hidden means those cannot be found
136if get_option('default_library') == 'static'
137  libzstd_static = libzstd
138  libzstd_internal_dep = declare_dependency(link_with: libzstd,
139      include_directories: libzstd_includes)
140else
141  if get_option('default_library') == 'shared'
142    libzstd_static = static_library('zstd_objlib',
143      objects: libzstd.extract_all_objects(recursive: true),
144      build_by_default: false)
145  else
146    libzstd_static = libzstd.get_static_lib()
147  endif
148
149  if cc_id == compiler_msvc
150    # msvc does not actually support linking to both, but errors out with:
151    #   error LNK2005: ZSTD_<foo> already defined in zstd.lib(zstd-1.dll)
152    libzstd_internal_dep = declare_dependency(link_with: libzstd_static,
153      include_directories: libzstd_includes)
154  else
155    libzstd_internal_dep = declare_dependency(link_with: libzstd,
156      # the static library must be linked after the shared one
157      dependencies: declare_dependency(link_with: libzstd_static),
158      include_directories: libzstd_includes)
159  endif
160endif
161
162pkgconfig.generate(libzstd,
163  name: 'libzstd',
164  filebase: 'libzstd',
165  description: 'fast lossless compression algorithm library',
166  version: zstd_libversion,
167  url: 'https://facebook.github.io/zstd/')
168
169install_headers(join_paths(zstd_rootdir, 'lib/zstd.h'),
170  join_paths(zstd_rootdir, 'lib/zdict.h'),
171  join_paths(zstd_rootdir, 'lib/zstd_errors.h'))
172