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/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/huf_decompress_amd64.S'), 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# Explicit define legacy support 50add_project_arguments('-DZSTD_LEGACY_SUPPORT=@0@'.format(legacy_level), 51 language: 'c') 52 53if legacy_level == 0 54 message('Legacy support: DISABLED') 55else 56 # See ZSTD_LEGACY_SUPPORT of lib/README.md 57 message('Enable legacy support back to version 0.@0@'.format(legacy_level)) 58 59 libzstd_includes += [ include_directories(join_paths(zstd_rootdir, 'lib/legacy')) ] 60 foreach i : [1, 2, 3, 4, 5, 6, 7] 61 if legacy_level <= i 62 libzstd_sources += join_paths(zstd_rootdir, 'lib/legacy/zstd_v0@0@.c'.format(i)) 63 endif 64 endforeach 65endif 66 67libzstd_deps = [] 68if use_multi_thread 69 message('Enable multi-threading support') 70 add_project_arguments('-DZSTD_MULTITHREAD', language: 'c') 71 libzstd_deps = [ thread_dep ] 72endif 73 74libzstd_c_args = [] 75if cc_id == compiler_msvc 76 if default_library_type != 'static' 77 libzstd_sources += [windows_mod.compile_resources( 78 join_paths(zstd_rootdir, 'build/VS2010/libzstd-dll/libzstd-dll.rc'))] 79 libzstd_c_args += ['-DZSTD_DLL_EXPORT=1', 80 '-DZSTD_HEAPMODE=0', 81 '-D_CONSOLE', 82 '-D_CRT_SECURE_NO_WARNINGS'] 83 else 84 libzstd_c_args += ['-DZSTD_HEAPMODE=0', 85 '-D_CRT_SECURE_NO_WARNINGS'] 86 endif 87endif 88 89mingw_ansi_stdio_flags = [] 90if host_machine_os == os_windows and cc_id == compiler_gcc 91 mingw_ansi_stdio_flags = [ '-D__USE_MINGW_ANSI_STDIO' ] 92endif 93libzstd_c_args += mingw_ansi_stdio_flags 94 95libzstd_debug_cflags = [] 96if use_debug 97 libzstd_c_args += '-DDEBUGLEVEL=@0@'.format(debug_level) 98 if cc_id == compiler_gcc or cc_id == compiler_clang 99 libzstd_debug_cflags = ['-Wstrict-aliasing=1', '-Wswitch-enum', 100 '-Wdeclaration-after-statement', '-Wstrict-prototypes', 101 '-Wundef', '-Wpointer-arith', '-Wvla', 102 '-Wformat=2', '-Winit-self', '-Wfloat-equal', '-Wwrite-strings', 103 '-Wredundant-decls', '-Wmissing-prototypes', '-Wc++-compat'] 104 endif 105endif 106libzstd_c_args += cc.get_supported_arguments(libzstd_debug_cflags) 107 108libzstd = library('zstd', 109 libzstd_sources, 110 include_directories: libzstd_includes, 111 c_args: libzstd_c_args, 112 gnu_symbol_visibility: 'hidden', 113 dependencies: libzstd_deps, 114 install: true, 115 version: zstd_libversion) 116 117libzstd_dep = declare_dependency(link_with: libzstd, 118 include_directories: libzstd_includes) 119 120pkgconfig.generate(libzstd, 121 name: 'libzstd', 122 filebase: 'libzstd', 123 description: 'fast lossless compression algorithm library', 124 version: zstd_libversion, 125 url: 'http://www.zstd.net/') 126 127install_headers(join_paths(zstd_rootdir, 'lib/zstd.h'), 128 join_paths(zstd_rootdir, 'lib/zdict.h'), 129 join_paths(zstd_rootdir, 'lib/zstd_errors.h')) 130