1 # #############################################################################
2 # Copyright (c) 2018-present Dima Krasner <dima@dimakrasner.com>
3 # lzutao <taolzu(at)gmail.com>
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 # #############################################################################
11 zstd_rootdir = '../../..'
13 libzstd_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'))]
19 libzstd_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/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')]
48 # really we need anything that defines __GNUC__ as that is what ZSTD_ASM_SUPPORTED is gated on
49 # but these are the two compilers that are supported in tree and actually handle this correctly
50 # Otherwise, explicitly disable assembly.
51 if [compiler_gcc, compiler_clang].contains(cc_id)
52 libzstd_sources += join_paths(zstd_rootdir, 'lib/decompress/huf_decompress_amd64.S')
54 add_project_arguments('-DZSTD_DISABLE_ASM', language: 'c')
57 # Explicit define legacy support
58 add_project_arguments('-DZSTD_LEGACY_SUPPORT=@0@'.format(legacy_level),
62 message('Legacy support: DISABLED')
64 # See ZSTD_LEGACY_SUPPORT of lib/README.md
65 message('Enable legacy support back to version 0.@0@'.format(legacy_level))
67 libzstd_includes += [ include_directories(join_paths(zstd_rootdir, 'lib/legacy')) ]
68 foreach i : [1, 2, 3, 4, 5, 6, 7]
70 libzstd_sources += join_paths(zstd_rootdir, 'lib/legacy/zstd_v0@0@.c'.format(i))
77 message('Enable multi-threading support')
78 add_project_arguments('-DZSTD_MULTITHREAD', language: 'c')
79 libzstd_deps = [ thread_dep ]
83 if cc_id == compiler_msvc
84 if default_library_type != 'static'
85 libzstd_sources += [windows_mod.compile_resources(
86 join_paths(zstd_rootdir, 'build/VS2010/libzstd-dll/libzstd-dll.rc'),
87 include_directories: libzstd_includes)]
88 libzstd_c_args += ['-DZSTD_DLL_EXPORT=1',
91 '-D_CRT_SECURE_NO_WARNINGS']
93 libzstd_c_args += ['-DZSTD_HEAPMODE=0',
94 '-D_CRT_SECURE_NO_WARNINGS']
98 mingw_ansi_stdio_flags = []
99 if host_machine_os == os_windows and cc_id == compiler_gcc
100 mingw_ansi_stdio_flags = [ '-D__USE_MINGW_ANSI_STDIO' ]
102 libzstd_c_args += mingw_ansi_stdio_flags
104 libzstd_debug_cflags = []
106 libzstd_c_args += '-DDEBUGLEVEL=@0@'.format(debug_level)
107 if cc_id == compiler_gcc or cc_id == compiler_clang
108 libzstd_debug_cflags = ['-Wstrict-aliasing=1', '-Wswitch-enum',
109 '-Wdeclaration-after-statement', '-Wstrict-prototypes',
110 '-Wundef', '-Wpointer-arith', '-Wvla',
111 '-Wformat=2', '-Winit-self', '-Wfloat-equal', '-Wwrite-strings',
112 '-Wredundant-decls', '-Wmissing-prototypes', '-Wc++-compat']
115 libzstd_c_args += cc.get_supported_arguments(libzstd_debug_cflags)
117 libzstd = library('zstd',
119 include_directories: libzstd_includes,
120 c_args: libzstd_c_args,
121 gnu_symbol_visibility: 'hidden',
122 dependencies: libzstd_deps,
124 version: zstd_libversion)
126 libzstd_dep = declare_dependency(link_with: libzstd,
127 include_directories: libzstd_includes)
130 # - the shared library (for public symbols)
131 # - the static library (for private symbols)
133 # this is needed because internally private symbols are used all the time, and
134 # -fvisibility=hidden means those cannot be found
135 if get_option('default_library') == 'static'
136 libzstd_static = libzstd
137 libzstd_internal_dep = libzstd_dep
139 if get_option('default_library') == 'shared'
140 libzstd_static = static_library('zstd_objlib',
141 objects: libzstd.extract_all_objects(recursive: true),
142 build_by_default: false)
144 libzstd_static = libzstd.get_static_lib()
147 if cc_id == compiler_msvc
148 # msvc does not actually support linking to both, but errors out with:
149 # error LNK2005: ZSTD_<foo> already defined in zstd.lib(zstd-1.dll)
150 libzstd_internal_dep = declare_dependency(link_with: libzstd_static)
152 libzstd_internal_dep = declare_dependency(link_with: libzstd,
153 # the static library must be linked after the shared one
154 dependencies: declare_dependency(link_with: libzstd_static))
158 pkgconfig.generate(libzstd,
161 description: 'fast lossless compression algorithm library',
162 version: zstd_libversion,
163 url: 'https://facebook.github.io/zstd/')
165 install_headers(join_paths(zstd_rootdir, 'lib/zstd.h'),
166 join_paths(zstd_rootdir, 'lib/zdict.h'),
167 join_paths(zstd_rootdir, 'lib/zstd_errors.h'))