]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Update meson build system 1426/head
authorLzu Tao <taolzu@gmail.com>
Tue, 27 Nov 2018 18:04:41 +0000 (01:04 +0700)
committerLzu Tao <taolzu@gmail.com>
Tue, 27 Nov 2018 18:08:34 +0000 (01:08 +0700)
NOTE: This commit only tested on Linux (Ubuntu 18.04). Windows
build may not work as expected.

* Use meson >= 0.47.0 cause we use install_man function
* Add three helper Python script:
  * CopyFile.py: To copy file
  * CreateSymlink.py: To make symlink (both Windows and Unix)
  * GetZstdLibraryVersion.py: Parse lib/zstd.h to get zstd version
  These help emulating equivalent functions in CMake and Makefile.
* Use subdir from meson to split meson.build
  * Add contrib build
  * Fix other build
* Add new build options
  * build_programs: Enable programs build
  * build_contrib: Enable contrib build
  * build_tests: Enable tests build
  * use_static_runtime: Link to static run-time libraries on MSVC
  * zlib_support: Enable zlib support
  * lzma_support: Enable lzma support

contrib/meson/CopyFile.py [new file with mode: 0644]
contrib/meson/CreateSymlink.py [new file with mode: 0644]
contrib/meson/GetZstdLibraryVersion.py [new file with mode: 0644]
contrib/meson/contrib/gen_html/meson.build [new file with mode: 0644]
contrib/meson/contrib/meson.build [new file with mode: 0644]
contrib/meson/contrib/pzstd/meson.build [new file with mode: 0644]
contrib/meson/lib/meson.build [new file with mode: 0644]
contrib/meson/meson.build
contrib/meson/meson_options.txt
contrib/meson/programs/meson.build [new file with mode: 0644]
contrib/meson/tests/meson.build [new file with mode: 0644]

diff --git a/contrib/meson/CopyFile.py b/contrib/meson/CopyFile.py
new file mode 100644 (file)
index 0000000..6c0288e
--- /dev/null
@@ -0,0 +1,35 @@
+#!/usr/bin/env python3
+# #############################################################################
+# Copyright (c) 2018-present    lzutao <taolzu(at)gmail.com>
+# All rights reserved.
+#
+# This source code is licensed under both the BSD-style license (found in the
+# LICENSE file in the root directory of this source tree) and the GPLv2 (found
+# in the COPYING file in the root directory of this source tree).
+# #############################################################################
+import os
+import sys
+import shutil
+
+
+def usage():
+    print('usage: python3 CreateSymlink.py <src> <dst>')
+    print('Copy the file named src to a file named dst')
+    sys.exit(1)
+
+
+def main():
+    if len(sys.argv) < 3:
+        usage()
+    src = sys.argv[1]
+    dst = sys.argv[2]
+
+    if os.path.exists(dst):
+            print ('File already exists: %r' % (dst))
+            return
+
+    shutil.copy2(src, dst)
+
+
+if __name__ == '__main__':
+    main()
diff --git a/contrib/meson/CreateSymlink.py b/contrib/meson/CreateSymlink.py
new file mode 100644 (file)
index 0000000..d0f9918
--- /dev/null
@@ -0,0 +1,36 @@
+#!/usr/bin/env python3
+# #############################################################################
+# Copyright (c) 2018-present    lzutao <taolzu(at)gmail.com>
+# All rights reserved.
+#
+# This source code is licensed under both the BSD-style license (found in the
+# LICENSE file in the root directory of this source tree) and the GPLv2 (found
+# in the COPYING file in the root directory of this source tree).
+# #############################################################################
+import os
+import sys
+
+
+def usage():
+    print('usage: python3 CreateSymlink.py <src> <dst> [dst is dir: True or False]')
+    sys.exit(1)
+
+
+def main():
+    if len(sys.argv) < 3:
+        usage()
+    src = sys.argv[1]
+    dst = sys.argv[2]
+    is_dir = False
+    if len(sys.argv) == 4:
+        is_dir = bool(sys.argv[3])
+
+    if os.path.islink(dst) and os.readlink(dst) == src:
+            print ('File exists: %r -> %r' % (dst, src))
+            return
+
+    os.symlink(src, dst, is_dir)
+
+
+if __name__ == '__main__':
+    main()
diff --git a/contrib/meson/GetZstdLibraryVersion.py b/contrib/meson/GetZstdLibraryVersion.py
new file mode 100644 (file)
index 0000000..364edc5
--- /dev/null
@@ -0,0 +1,45 @@
+#!/usr/bin/env python3
+# #############################################################################
+# Copyright (c) 2018-present    lzutao <taolzu(at)gmail.com>
+# All rights reserved.
+#
+# This source code is licensed under both the BSD-style license (found in the
+# LICENSE file in the root directory of this source tree) and the GPLv2 (found
+# in the COPYING file in the root directory of this source tree).
+# #############################################################################
+import re
+import sys
+
+
+def usage():
+    print('usage: python3 GetZstdLibraryVersion.py <path/to/zstd.h>')
+    sys.exit(1)
+
+
+def find_version(filepath):
+    version_file_data = None
+    with open(filepath) as fd:
+        version_file_data = fd.read()
+
+    patterns = r"""#\s*define\s+ZSTD_VERSION_MAJOR\s+([0-9]+)
+#\s*define\s+ZSTD_VERSION_MINOR\s+([0-9]+)
+#\s*define\s+ZSTD_VERSION_RELEASE\s+([0-9]+)
+"""
+    regex = re.compile(patterns, re.MULTILINE)
+    version_match = regex.search(version_file_data)
+    if version_match:
+        return version_match.groups()
+    raise RuntimeError("Unable to find version string.")
+
+
+def main():
+    if len(sys.argv) < 2:
+        usage()
+
+    filepath = sys.argv[1]
+    version_tup = find_version(filepath)
+    print('.'.join(version_tup))
+
+
+if __name__ == '__main__':
+    main()
diff --git a/contrib/meson/contrib/gen_html/meson.build b/contrib/meson/contrib/gen_html/meson.build
new file mode 100644 (file)
index 0000000..086b8f0
--- /dev/null
@@ -0,0 +1,36 @@
+# #############################################################################
+# Copyright (c) 2018-present    lzutao <taolzu(at)gmail.com>
+# All rights reserved.
+#
+# This source code is licensed under both the BSD-style license (found in the
+# LICENSE file in the root directory of this source tree) and the GPLv2 (found
+# in the COPYING file in the root directory of this source tree).
+# #############################################################################
+
+zstd_source_dir = join_paths('..', '..', '..', '..')
+library_dir = join_paths(zstd_source_dir, 'lib')
+library_common_dir = join_paths(library_dir, 'common')
+programs_dir = join_paths(zstd_source_dir, 'programs')
+contrib_gen_html_dir = join_paths(zstd_source_dir, 'contrib', 'gen_html')
+
+gen_html_includes = include_directories(programs_dir,
+    library_dir,
+    library_common_dir,
+    contrib_gen_html_dir )
+
+gen_html = executable('gen_html',
+    join_paths(contrib_gen_html_dir, 'gen_html.cpp'),
+    include_directories: gen_html_includes,
+    install: false )
+
+# Update zstd manual
+zstd_manual_html = custom_target('zstd_manual.html',
+    output : 'zstd_manual.html',
+    command : [
+        gen_html,
+        zstd_version,
+        join_paths(meson.current_source_dir(), library_dir, 'zstd.h'),
+        '@OUTPUT@'
+    ],
+    install : true,
+    install_dir : zstd_docdir )
diff --git a/contrib/meson/contrib/meson.build b/contrib/meson/contrib/meson.build
new file mode 100644 (file)
index 0000000..7f6d03a
--- /dev/null
@@ -0,0 +1,12 @@
+# #############################################################################
+# Copyright (c) 2018-present     Dima Krasner <dima@dimakrasner.com>
+#                                lzutao <taolzu(at)gmail.com>
+# All rights reserved.
+#
+# This source code is licensed under both the BSD-style license (found in the
+# LICENSE file in the root directory of this source tree) and the GPLv2 (found
+# in the COPYING file in the root directory of this source tree).
+# #############################################################################
+
+subdir('pzstd')
+subdir('gen_html')
diff --git a/contrib/meson/contrib/pzstd/meson.build b/contrib/meson/contrib/pzstd/meson.build
new file mode 100644 (file)
index 0000000..9239901
--- /dev/null
@@ -0,0 +1,32 @@
+# #############################################################################
+# Copyright (c) 2018-present    lzutao <taolzu(at)gmail.com>
+# All rights reserved.
+#
+# This source code is licensed under both the BSD-style license (found in the
+# LICENSE file in the root directory of this source tree) and the GPLv2 (found
+# in the COPYING file in the root directory of this source tree).
+# #############################################################################
+
+zstd_source_dir = join_paths('..', '..', '..', '..')
+library_dir = join_paths(zstd_source_dir, 'lib')
+library_common_dir = join_paths(library_dir, 'common')
+programs_dir = join_paths(zstd_source_dir, 'programs')
+contrib_pzstd_dir = join_paths(zstd_source_dir, 'contrib', 'pzstd')
+
+pzstd_includes = include_directories(programs_dir,
+    library_dir,
+    library_common_dir,
+    contrib_pzstd_dir)
+pzstd_sources = [join_paths(programs_dir, 'util.c'),
+    join_paths(contrib_pzstd_dir, 'main.cpp'),
+    join_paths(contrib_pzstd_dir, 'Options.cpp'),
+    join_paths(contrib_pzstd_dir, 'Pzstd.cpp'),
+    join_paths(contrib_pzstd_dir, 'SkippableFrame.cpp')]
+
+pzstd = executable('pzstd',
+    pzstd_sources,
+    cpp_args: [ '-DNDEBUG', '-Wno-shadow' ],
+    include_directories: pzstd_includes,
+    link_with: libzstd,
+    dependencies: [ thread_dep ],
+    install: true)
diff --git a/contrib/meson/lib/meson.build b/contrib/meson/lib/meson.build
new file mode 100644 (file)
index 0000000..b5d6778
--- /dev/null
@@ -0,0 +1,122 @@
+# #############################################################################
+# Copyright (c) 2018-present     Dima Krasner <dima@dimakrasner.com>
+#                                lzutao <taolzu(at)gmail.com>
+# All rights reserved.
+#
+# This source code is licensed under both the BSD-style license (found in the
+# LICENSE file in the root directory of this source tree) and the GPLv2 (found
+# in the COPYING file in the root directory of this source tree).
+# #############################################################################
+
+zstd_source_dir = join_paths('..', '..', '..')
+library_dir = join_paths(zstd_source_dir, 'lib')
+library_common_dir = join_paths(library_dir, 'common')
+library_compress_dir = join_paths(library_dir, 'compress')
+library_decompress_dir = join_paths(library_dir, 'decompress')
+library_dictbuilder_dir = join_paths(library_dir, 'dictBuilder')
+library_deprecated_dir = join_paths(library_dir, 'deprecated')
+library_legacy_dir = join_paths(library_dir, 'legacy')
+
+libzstd_includes = [include_directories(library_dir,
+    library_common_dir,
+    library_compress_dir,
+    library_decompress_dir,
+    library_dictbuilder_dir,
+    library_deprecated_dir)]
+
+libzstd_sources = [join_paths(library_common_dir, 'entropy_common.c'),
+    join_paths(library_common_dir, 'fse_decompress.c'),
+    join_paths(library_common_dir, 'threading.c'),
+    join_paths(library_common_dir, 'pool.c'),
+    join_paths(library_common_dir, 'zstd_common.c'),
+    join_paths(library_common_dir, 'error_private.c'),
+    join_paths(library_common_dir, 'xxhash.c'),
+    join_paths(library_compress_dir, 'hist.c'),
+    join_paths(library_compress_dir, 'fse_compress.c'),
+    join_paths(library_compress_dir, 'huf_compress.c'),
+    join_paths(library_compress_dir, 'zstd_compress.c'),
+    join_paths(library_compress_dir, 'zstdmt_compress.c'),
+    join_paths(library_compress_dir, 'zstd_fast.c'),
+    join_paths(library_compress_dir, 'zstd_double_fast.c'),
+    join_paths(library_compress_dir, 'zstd_lazy.c'),
+    join_paths(library_compress_dir, 'zstd_opt.c'),
+    join_paths(library_compress_dir, 'zstd_ldm.c'),
+    join_paths(library_decompress_dir, 'huf_decompress.c'),
+    join_paths(library_decompress_dir, 'zstd_decompress.c'),
+    join_paths(library_decompress_dir, 'zstd_decompress_block.c'),
+    join_paths(library_decompress_dir, 'zstd_ddict.c'),
+    join_paths(library_dictbuilder_dir, 'cover.c'),
+    join_paths(library_dictbuilder_dir, 'fastcover.c'),
+    join_paths(library_dictbuilder_dir, 'divsufsort.c'),
+    join_paths(library_dictbuilder_dir, 'zdict.c'),
+    join_paths(library_deprecated_dir, 'zbuff_common.c'),
+    join_paths(library_deprecated_dir, 'zbuff_compress.c'),
+    join_paths(library_deprecated_dir, 'zbuff_decompress.c')]
+
+if legacy_support == '0'
+    legacy_support = 'false'
+endif
+if legacy_support != 'false'
+    if legacy_support == 'true'
+        legacy_support = '1'
+    endif
+    legacy_int = legacy_support.to_int()
+    if legacy_int < 0 or legacy_int >= 8
+        legacy_int = 0
+    endif
+    add_project_arguments('-DZSTD_LEGACY_SUPPORT=@0@'.format(legacy_int),
+        language: 'c')
+    libzstd_includes += [ include_directories(library_legacy_dir) ]
+    # See ZSTD_LEGACY_SUPPORT of programs/README.md
+    message('Enable legacy support back to version 0.@0@'.format(legacy_int))
+    if legacy_int <= 1
+        libzstd_sources += join_paths(library_legacy_dir, 'zstd_v01.c')
+    endif
+    if legacy_int <= 2
+        libzstd_sources += join_paths(library_legacy_dir, 'zstd_v02.c')
+    endif
+    if legacy_int <= 3
+        libzstd_sources += join_paths(library_legacy_dir, 'zstd_v03.c')
+    endif
+    if legacy_int <= 4
+        libzstd_sources += join_paths(library_legacy_dir, 'zstd_v04.c')
+    endif
+    if legacy_int <= 5
+        libzstd_sources += join_paths(library_legacy_dir, 'zstd_v05.c')
+    endif
+    if legacy_int <= 6
+        libzstd_sources += join_paths(library_legacy_dir, 'zstd_v06.c')
+    endif
+    if legacy_int <= 7
+        libzstd_sources += join_paths(library_legacy_dir, 'zstd_v07.c')
+    endif
+endif
+
+if enable_multithread
+    message('Enable multi-threading support')
+    add_project_arguments('-DZSTD_MULTITHREAD', language: 'c')
+    libzstd_deps = [ thread_dep ]
+else
+    libzstd_deps = []
+endif
+
+libzstd = library('zstd',
+    libzstd_sources,
+    include_directories: libzstd_includes,
+    dependencies: libzstd_deps,
+    install: true,
+    soversion: '1')
+
+pkgconfig.generate(name: 'libzstd',
+    description: 'fast lossless compression algorithm library',
+    version: zstd_version,
+    filebase: 'libzstd',
+    libraries: [libzstd],
+    #subdirs: ['.']
+    )
+
+install_headers(join_paths(library_dir, 'zstd.h'),
+    join_paths(library_deprecated_dir, 'zbuff.h'),
+    join_paths(library_dictbuilder_dir, 'zdict.h'),
+    join_paths(library_dictbuilder_dir, 'cover.h'),
+    join_paths(library_common_dir, 'zstd_errors.h'))
index 98c9b0293007146c094a3f8996e7abb780c6076b..b9ac88281c90d957915c3c027edfec11bfb557d9 100644 (file)
-project('zstd', 'c', license: 'BSD')
-
-libm = meson.get_compiler('c').find_library('m', required: true)
-
-lib_dir = join_paths('..', '..', 'lib')
-common_dir = join_paths(lib_dir, 'common')
-compress_dir = join_paths(lib_dir, 'compress')
-decompress_dir = join_paths(lib_dir, 'decompress')
-dictbuilder_dir = join_paths(lib_dir, 'dictBuilder')
-deprecated_dir = join_paths(lib_dir, 'deprecated')
-
-libzstd_srcs = [
-    join_paths(common_dir, 'entropy_common.c'),
-    join_paths(common_dir, 'fse_decompress.c'),
-    join_paths(common_dir, 'threading.c'),
-    join_paths(common_dir, 'pool.c'),
-    join_paths(common_dir, 'zstd_common.c'),
-    join_paths(common_dir, 'error_private.c'),
-    join_paths(common_dir, 'xxhash.c'),
-    join_paths(compress_dir, 'fse_compress.c'),
-    join_paths(compress_dir, 'hist.c'),
-    join_paths(compress_dir, 'huf_compress.c'),
-    join_paths(compress_dir, 'zstd_compress.c'),
-    join_paths(compress_dir, 'zstd_fast.c'),
-    join_paths(compress_dir, 'zstd_double_fast.c'),
-    join_paths(compress_dir, 'zstd_lazy.c'),
-    join_paths(compress_dir, 'zstd_opt.c'),
-    join_paths(compress_dir, 'zstd_ldm.c'),
-    join_paths(compress_dir, 'zstdmt_compress.c'),
-    join_paths(decompress_dir, 'huf_decompress.c'),
-    join_paths(decompress_dir, 'zstd_decompress.c'),
-    join_paths(dictbuilder_dir, 'cover.c'),
-    join_paths(dictbuilder_dir, 'divsufsort.c'),
-    join_paths(dictbuilder_dir, 'zdict.c'),
-    join_paths(deprecated_dir, 'zbuff_common.c'),
-    join_paths(deprecated_dir, 'zbuff_compress.c'),
-    join_paths(deprecated_dir, 'zbuff_decompress.c')
-]
-
-libzstd_includes = [include_directories(common_dir, dictbuilder_dir, compress_dir, lib_dir)]
-
-legacy = get_option('legacy_support')
-if legacy == '0'
-    legacy = 'false'
-endif
-if legacy != 'false'
-    if legacy == 'true'
-        legacy = '1'
-    endif
-    #See ZSTD_LEGACY_SUPPORT of programs/README.md
-    message('Enabling legacy support back to version 0.' + legacy)
-    legacy_int = legacy.to_int()
-    if legacy_int > 7
-        legacy_int = 7
-    endif
-    libzstd_cflags = ['-DZSTD_LEGACY_SUPPORT=' + legacy]
+# #############################################################################
+# Copyright (c) 2018-present     Dima Krasner <dima@dimakrasner.com>
+#                                lzutao <taolzu(at)gmail.com>
+# All rights reserved.
+#
+# This source code is licensed under both the BSD-style license (found in the
+# LICENSE file in the root directory of this source tree) and the GPLv2 (found
+# in the COPYING file in the root directory of this source tree).
+# #############################################################################
 
-    legacy_dir = join_paths(lib_dir, 'legacy')
-    libzstd_includes += [include_directories(legacy_dir)]
-    if legacy_int <= 1
-        libzstd_srcs += join_paths(legacy_dir, 'zstd_v01.c')
-    endif
-    if legacy_int <= 2
-        libzstd_srcs += join_paths(legacy_dir, 'zstd_v02.c')
-    endif
-    if legacy_int <= 3
-        libzstd_srcs += join_paths(legacy_dir, 'zstd_v03.c')
-    endif
-    if legacy_int <= 4
-        libzstd_srcs += join_paths(legacy_dir, 'zstd_v04.c')
-    endif
-    if legacy_int <= 5
-        libzstd_srcs += join_paths(legacy_dir, 'zstd_v05.c')
-    endif
-    if legacy_int <= 6
-        libzstd_srcs += join_paths(legacy_dir, 'zstd_v06.c')
-    endif
-    if legacy_int <= 7
-        libzstd_srcs += join_paths(legacy_dir, 'zstd_v07.c')
+project('zstd',
+    ['c', 'cpp'],
+    license: 'BSD',
+    default_options : ['c_std=c99',
+        'cpp_std=c++11',
+        'buildtype=release'],
+    version: '1.3.7',
+    # for install_man
+    meson_version: '>=0.47.0')
+
+cc = meson.get_compiler('c')
+cxx = meson.get_compiler('cpp')
+pkgconfig = import('pkgconfig')
+python3 = import('python').find_installation()
+
+zstd_version = meson.project_version()
+
+# =============================================================================
+# Project directories
+# =============================================================================
+
+zstd_prefix = get_option('prefix')
+zstd_bindir = join_paths(zstd_prefix, get_option('bindir'))
+zstd_datadir = join_paths(zstd_prefix, get_option('datadir'))
+zstd_docdir = join_paths(zstd_datadir, 'doc', meson.project_name())
+zstd_mandir = join_paths(zstd_prefix, get_option('mandir'))
+
+zstd_source_dir = join_paths('..', '..')
+library_dir = join_paths(zstd_source_dir, 'lib')
+contrib_meson_dir = join_paths(zstd_source_dir, 'contrib', 'meson')
+
+# =============================================================================
+# Project options
+# =============================================================================
+
+legacy_support = get_option('legacy_support')
+enable_programs = get_option('build_programs')
+enable_tests = get_option('build_tests')
+enable_contrib = get_option('build_contrib')
+enable_multithread = get_option('multithread_support')
+enable_zlib = get_option('zlib_support')
+enable_lzma = get_option('lzma_support')
+
+# =============================================================================
+# Getting project version from zstd.h
+# =============================================================================
+
+GetZstdLibraryVersion_py = files('GetZstdLibraryVersion.py')
+zstd_h_file = join_paths(library_dir, 'zstd.h')
+r = run_command(python3, GetZstdLibraryVersion_py, zstd_h_file)
+if r.returncode() == 0
+    output = r.stdout().strip()
+    if output.version_compare('>@0@'.format(zstd_version))
+        zstd_version = output
+        message('Project version is now: @0@'.format(zstd_version))
     endif
-else
-    libzstd_cflags = []
 endif
 
-if get_option('multithread')
-    message('Enabling multi-threading support')
-    add_global_arguments('-DZSTD_MULTITHREAD', language: 'c')
-    libzstd_deps = [dependency('threads')]
-else
-    libzstd_deps = []
+# =============================================================================
+# Dependencies
+# =============================================================================
+
+libm_dep = cc.find_library('m', required: true)
+thread_dep = dependency('threads', required: false)
+zlib_dep = dependency('zlib', required: false)
+lzma_dep = dependency('lzma', required: false)
+
+# =============================================================================
+# Compiler flags
+# =============================================================================
+
+if cxx.get_id() == 'gcc' or cxx.get_id() == 'clang'
+    common_flags = [ '-DXXH_NAMESPACE=ZSTD_' ]
+    zstd_compilation_flags = [ '-Wextra', '-Wundef', '-Wshadow', '-Wcast-align', '-Wcast-qual' ]
+    cc_common_flags = cc.get_supported_arguments(zstd_compilation_flags)
+    cc_common_flags += cc.get_supported_arguments(['-Wstrict-prototypes'])
+    cc_common_flags += common_flags
+    cxx_common_flags = cxx.get_supported_arguments(zstd_compilation_flags)
+    cxx_common_flags += common_flags
+    add_project_arguments(cc_common_flags, language : 'c')
+    add_project_arguments(cxx_common_flags, language : 'cpp')
+endif
+
+# =============================================================================
+# Subdirs
+# =============================================================================
+
+subdir('lib')
+if enable_programs
+    subdir('programs')
+endif
+
+if enable_tests
+    subdir('tests')
 endif
 
-libzstd = library('zstd',
-                  libzstd_srcs,
-                  include_directories: libzstd_includes,
-                  c_args: libzstd_cflags,
-                  dependencies: libzstd_deps,
-                  install: true,
-                  soversion: '1',
-                 )
-
-programs_dir = join_paths('..', '..', 'programs')
-
-zstd = executable('zstd',
-                  join_paths(programs_dir, 'bench.c'),
-                  join_paths(programs_dir, 'datagen.c'),
-                  join_paths(programs_dir, 'dibio.c'),
-                  join_paths(programs_dir, 'fileio.c'),
-                  join_paths(programs_dir, 'zstdcli.c'),
-                  include_directories: libzstd_includes,
-                  c_args: ['-DZSTD_NODICT', '-DZSTD_NOBENCH'],
-                  link_with: libzstd,
-                  install: true)
-
-tests_dir = join_paths('..', '..', 'tests')
-datagen_c = join_paths(programs_dir, 'datagen.c')
-test_includes = libzstd_includes + [include_directories(programs_dir)]
-
-fullbench = executable('fullbench',
-                       datagen_c, join_paths(tests_dir, 'fullbench.c'),
-                       include_directories: test_includes,
-                       link_with: libzstd)
-test('fullbench', fullbench)
-
-fuzzer = executable('fuzzer',
-                    datagen_c, join_paths(tests_dir, 'fuzzer.c'),
-                    include_directories: test_includes,
-                    link_with: libzstd)
-test('fuzzer', fuzzer)
-
-if target_machine.system() != 'windows'
-    paramgrill = executable('paramgrill',
-                            datagen_c, join_paths(tests_dir, 'paramgrill.c'),
-                            join_paths(programs_dir, 'bench.c'),
-                            include_directories: test_includes,
-                            link_with: libzstd,
-                            dependencies: libm)
-    test('paramgrill', paramgrill)
-
-    datagen = executable('datagen',
-                         datagen_c, join_paths(tests_dir, 'datagencli.c'),
-                         include_directories: test_includes,
-                         link_with: libzstd)
+if enable_contrib
+    subdir('contrib')
 endif
index 99845c8aa5131a6b38a153fe2db99a05db477b11..1d28c71a8d1fa941dd9639e28a19de1ecc1316e8 100644 (file)
@@ -1,3 +1,26 @@
-option('multithread', type: 'boolean', value: false)
+# #############################################################################
+# Copyright (c) 2018-present     Dima Krasner <dima@dimakrasner.com>
+#                                lzutao <taolzu(at)gmail.com>
+# All rights reserved.
+#
+# This source code is licensed under both the BSD-style license (found in the
+# LICENSE file in the root directory of this source tree) and the GPLv2 (found
+# in the COPYING file in the root directory of this source tree).
+# #############################################################################
+
+option('multithread_support', type: 'boolean', value: true,
+    description: 'Enable multithreading when pthread is detected')
 option('legacy_support', type: 'string', value: '4',
-    description: 'True or false, or 7 to 1 for v0.7+ to v0.1+.')
+    description: 'Support any legacy format: true or false, or 7 to 1 for v0.7+ to v0.1+')
+option('build_programs', type: 'boolean', value: true,
+    description: 'Enable programs build')
+option('build_contrib', type: 'boolean', value: false,
+    description: 'Enable contrib build')
+option('build_tests', type: 'boolean', value: false,
+    description: 'Enable tests build')
+option('use_static_runtime', type: 'boolean', value: false,
+    description: 'Link to static run-time libraries on MSVC')
+option('zlib_support', type: 'boolean', value: false,
+    description: 'Enable zlib support')
+option('lzma_support', type: 'boolean', value: false,
+    description: 'Enable lzma support')
diff --git a/contrib/meson/programs/meson.build b/contrib/meson/programs/meson.build
new file mode 100644 (file)
index 0000000..63ea328
--- /dev/null
@@ -0,0 +1,113 @@
+# #############################################################################
+# Copyright (c) 2018-present     Dima Krasner <dima@dimakrasner.com>
+#                                lzutao <taolzu(at)gmail.com>
+# All rights reserved.
+#
+# This source code is licensed under both the BSD-style license (found in the
+# LICENSE file in the root directory of this source tree) and the GPLv2 (found
+# in the COPYING file in the root directory of this source tree).
+# #############################################################################
+
+zstd_source_dir = join_paths('..', '..', '..')
+programs_dir = join_paths(zstd_source_dir, 'programs')
+
+zstdcli_c_file = join_paths(programs_dir, 'zstdcli.c')
+util_c_file = join_paths(programs_dir, 'util.c')
+fileio_c_file = join_paths(programs_dir, 'fileio.c')
+zstd_programs_sources = [zstdcli_c_file,
+    util_c_file,
+    fileio_c_file,
+    join_paths(programs_dir, 'benchfn.c'),
+    join_paths(programs_dir, 'benchzstd.c'),
+    join_paths(programs_dir, 'datagen.c'),
+    join_paths(programs_dir, 'dibio.c')]
+
+zstd_c_args = []
+if enable_multithread
+    zstd_c_args += [ '-DZSTD_MULTITHREAD' ]
+endif
+
+zstd_deps = []
+if enable_zlib and zlib_dep.found()
+    zstd_deps += [ zlib_dep ]
+    zstd_c_args += [ '-DZSTD_GZCOMPRESS', '-DZSTD_GZDECOMPRESS' ]
+endif
+
+if enable_lzma and lzma_dep.found()
+    zstd_deps += [ lzma_dep ]
+    zstd_c_args += [ '-DZSTD_LZMACOMPRESS', '-DZSTD_LZMADECOMPRESS' ]
+endif
+
+zstd = executable('zstd',
+    zstd_programs_sources,
+    c_args: zstd_c_args,
+    include_directories: libzstd_includes,
+    link_with: libzstd,
+    dependencies: zstd_deps,
+    install: true)
+
+zstd_frugal_sources = [join_paths(programs_dir, 'zstdcli.c'),
+    util_c_file,
+    fileio_c_file]
+
+executable('zstd-frugal',
+    zstd_frugal_sources,
+    include_directories: libzstd_includes,
+    link_with: libzstd,
+    c_args: [ '-DZSTD_NOBENCH', '-DZSTD_NODICT' ],
+    install: true)
+
+# =============================================================================
+# Program symlinks
+# =============================================================================
+
+CreateSymlink_py = join_paths(meson.current_source_dir(), '..', 'CreateSymlink.py')
+
+foreach f : [ 'zstdcat', 'unzstd' ]
+    custom_target(f,
+        output : f,
+        input: zstd,
+        command : [python3, CreateSymlink_py, '@PLAINNAME@', '@OUTPUT@'],
+        build_always_stale: false,
+        install : true,
+        install_dir: zstd_bindir)
+endforeach
+
+if enable_multithread
+    custom_target('zstdmt',
+        output : 'zstdmt',
+        input: zstd,
+        command : [python3, CreateSymlink_py, '@PLAINNAME@', '@OUTPUT@'],
+        build_always_stale: false,
+        install : true,
+        install_dir: zstd_bindir)
+endif
+
+# =============================================================================
+# Manpages
+# =============================================================================
+
+zstd_man1_dir = join_paths(zstd_mandir, 'man1')
+zstd_1_file = join_paths(programs_dir, 'zstd.1')
+CopyFile_py = join_paths(meson.current_source_dir(), '..', 'CopyFile.py')
+
+custom_target('zstd.1',
+        output : 'zstd.1',
+        input: zstd_1_file,
+        command : [python3, CopyFile_py, '@INPUT@', '@OUTPUT@'],
+        build_always_stale: false,
+        install : true,
+        install_dir: zstd_man1_dir)
+
+foreach f : [ 'zstdcat.1', 'unzstd.1' ]
+    custom_target(f,
+        output : f,
+        input: zstd_1_file,
+        command : [python3, CreateSymlink_py, '@PLAINNAME@', '@OUTPUT@'],
+        install : true,
+        build_always_stale: false,
+        install_dir: zstd_man1_dir)
+endforeach
+
+install_man(join_paths(programs_dir, 'zstdgrep.1'),
+    join_paths(programs_dir, 'zstdless.1'))
diff --git a/contrib/meson/tests/meson.build b/contrib/meson/tests/meson.build
new file mode 100644 (file)
index 0000000..cc9e1ee
--- /dev/null
@@ -0,0 +1,65 @@
+# #############################################################################
+# Copyright (c) 2018-present     Dima Krasner <dima@dimakrasner.com>
+#                                lzutao <taolzu(at)gmail.com>
+# All rights reserved.
+#
+# This source code is licensed under both the BSD-style license (found in the
+# LICENSE file in the root directory of this source tree) and the GPLv2 (found
+# in the COPYING file in the root directory of this source tree).
+# #############################################################################
+
+zstd_source_dir = join_paths('..', '..', '..')
+programs_dir = join_paths(zstd_source_dir, 'programs')
+tests_dir = join_paths(zstd_source_dir, 'tests')
+
+datagen_c_file = join_paths(programs_dir, 'datagen.c')
+util_c_file = join_paths(programs_dir, 'util.c')
+benchfn_c_file = join_paths(programs_dir, 'benchfn.c')
+
+datagen_sources = [datagen_c_file,
+    join_paths(tests_dir, 'datagencli.c')]
+test_includes = libzstd_includes + [include_directories(programs_dir)]
+
+datagen = executable('datagen',
+    datagen_sources,
+    include_directories: test_includes,
+    link_with: libzstd,
+    install: false)
+test('datagen', datagen)
+
+fullbench_sources = [datagen_c_file,
+    util_c_file,
+    benchfn_c_file,
+    join_paths(programs_dir, 'benchzstd.c'),
+    join_paths(programs_dir, 'fullbench.c')]
+fullbench = executable('fullbench',
+    fullbench_sources,
+    include_directories: test_includes,
+    link_with: libzstd,
+    install: false)
+test('fullbench', fullbench)
+
+fuzzer_sources = [datagen_c_file,
+    util_c_file,
+    join_paths(tests_dir, 'fuzzer.c')]
+fuzzer = executable('fuzzer',
+    fuzzer_sources,
+    include_directories: test_includes,
+    link_with: libzstd,
+    install: false)
+test('fuzzer', fuzzer)
+
+paramgrill_sources = [benchfn_c_file
+    join_paths(programs_dir, 'benchzstd.c'),
+    datagen_c_file
+    util_c_file
+    join_paths(tests_dir, 'paramgrill.c')]
+if host_machine.system() != 'windows'
+    paramgrill = executable('paramgrill',
+        paramgrill_sources,
+        include_directories: test_includes,
+        link_with: libzstd,
+        dependencies: libm_dep,
+        install: false )
+    test('paramgrill', paramgrill)
+endif