]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Initial support for Windows build
authorLzu Tao <taolzu@gmail.com>
Fri, 30 Nov 2018 08:30:45 +0000 (15:30 +0700)
committerLzu Tao <taolzu@gmail.com>
Sat, 1 Dec 2018 16:18:59 +0000 (23:18 +0700)
build/meson/contrib/gen_html/meson.build
build/meson/contrib/pzstd/meson.build
build/meson/lib/meson.build
build/meson/meson.build
build/meson/meson_options.txt
build/meson/programs/meson.build

index 9f02baf6e31ff0c7dfa29cf0c35f3246ec6629b9..a2fea9d52993921229e3812b7b1a3bb131d63be1 100644 (file)
@@ -7,27 +7,23 @@
 # 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')
+zstd_rootdir = '../../../..'
 
-gen_html_includes = include_directories(programs_dir,
-    library_dir,
-    library_common_dir,
-    contrib_gen_html_dir)
+gen_html_includes = include_directories(join_paths(zstd_rootdir, 'programs'),
+  join_paths(zstd_rootdir, 'lib'),
+  join_paths(zstd_rootdir, 'lib/common'),
+  join_paths(zstd_rootdir, 'contrib/gen_html'))
 
 gen_html = executable('gen_html',
-    join_paths(contrib_gen_html_dir, 'gen_html.cpp'),
-    include_directories: gen_html_includes,
-    install: false)
+  join_paths(zstd_rootdir, 'contrib/gen_html/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 : false)
+  output : 'zstd_manual.html',
+  command : [gen_html,
+    zstd_version,
+    join_paths(meson.current_source_dir(), join_paths(zstd_rootdir, 'lib/zstd.h')),
+    '@OUTPUT@'],
+  install : false)
index 3531ace7d5dc3e350dc46bfefda411b659ddefec..8f3822fd7767bac99edfb120a10431edfcd1710f 100644 (file)
@@ -7,26 +7,18 @@
 # 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')]
+zstd_rootdir = '../../../..'
 
+pzstd_includes = include_directories(join_paths(zstd_rootdir, 'programs'),
+  join_paths(zstd_rootdir, 'contrib/pzstd'))
+pzstd_sources = [join_paths(zstd_rootdir, 'programs/util.c'),
+  join_paths(zstd_rootdir, 'contrib/pzstd/main.cpp'),
+  join_paths(zstd_rootdir, 'contrib/pzstd/Options.cpp'),
+  join_paths(zstd_rootdir, 'contrib/pzstd/Pzstd.cpp'),
+  join_paths(zstd_rootdir, 'contrib/pzstd/SkippableFrame.cpp')]
 pzstd = executable('pzstd',
-    pzstd_sources,
-    cpp_args: [ '-DNDEBUG', '-Wno-shadow', '-pedantic' ],
-    include_directories: pzstd_includes,
-    link_with: libzstd,
-    dependencies: [ thread_dep ],
-    install: true)
+  pzstd_sources,
+  cpp_args: [ '-DNDEBUG', '-Wno-shadow', '-pedantic' ],
+  include_directories: pzstd_includes,
+  dependencies: [ libzstd_dep, thread_dep ],
+  install: true)
index 8a693dc71068cdf94c2b40dd3db7dc97b7bbc010..5bfdbb074412aa377f6e0fd8ae915fb5139d9e1b 100644 (file)
 # 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')
+zstd_rootdir = '../../..'
 
-libzstd_includes = [include_directories(library_dir,
-    library_common_dir,
-    library_compress_dir,
-    library_decompress_dir,
-    library_dictbuilder_dir,
-    library_deprecated_dir)]
+libzstd_includes = [include_directories(join_paths(zstd_rootdir,'lib'),
+  join_paths(zstd_rootdir, 'lib/common'),
+  join_paths(zstd_rootdir, 'lib/compress'),
+  join_paths(zstd_rootdir, 'lib/decompress'),
+  join_paths(zstd_rootdir, 'lib/dictBuilder'),
+  join_paths(zstd_rootdir, 'lib/deprecated'))]
 
-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')]
+libzstd_sources = [join_paths(zstd_rootdir, 'lib/common/entropy_common.c'),
+  join_paths(zstd_rootdir, 'lib/common/fse_decompress.c'),
+  join_paths(zstd_rootdir, 'lib/common/threading.c'),
+  join_paths(zstd_rootdir, 'lib/common/pool.c'),
+  join_paths(zstd_rootdir, 'lib/common/zstd_common.c'),
+  join_paths(zstd_rootdir, 'lib/common/error_private.c'),
+  join_paths(zstd_rootdir, 'lib/common/xxhash.c'),
+  join_paths(zstd_rootdir, 'lib/compress/hist.c'),
+  join_paths(zstd_rootdir, 'lib/compress/fse_compress.c'),
+  join_paths(zstd_rootdir, 'lib/compress/huf_compress.c'),
+  join_paths(zstd_rootdir, 'lib/compress/zstd_compress.c'),
+  join_paths(zstd_rootdir, 'lib/compress/zstdmt_compress.c'),
+  join_paths(zstd_rootdir, 'lib/compress/zstd_fast.c'),
+  join_paths(zstd_rootdir, 'lib/compress/zstd_double_fast.c'),
+  join_paths(zstd_rootdir, 'lib/compress/zstd_lazy.c'),
+  join_paths(zstd_rootdir, 'lib/compress/zstd_opt.c'),
+  join_paths(zstd_rootdir, 'lib/compress/zstd_ldm.c'),
+  join_paths(zstd_rootdir, 'lib/decompress/huf_decompress.c'),
+  join_paths(zstd_rootdir, 'lib/decompress/zstd_decompress.c'),
+  join_paths(zstd_rootdir, 'lib/decompress/zstd_decompress_block.c'),
+  join_paths(zstd_rootdir, 'lib/decompress/zstd_ddict.c'),
+  join_paths(zstd_rootdir, 'lib/dictBuilder/cover.c'),
+  join_paths(zstd_rootdir, 'lib/dictBuilder/fastcover.c'),
+  join_paths(zstd_rootdir, 'lib/dictBuilder/divsufsort.c'),
+  join_paths(zstd_rootdir, 'lib/dictBuilder/zdict.c'),
+  join_paths(zstd_rootdir, 'lib/deprecated/zbuff_common.c'),
+  join_paths(zstd_rootdir, 'lib/deprecated/zbuff_compress.c'),
+  join_paths(zstd_rootdir, 'lib/deprecated/zbuff_decompress.c')]
 
-if with_legacy_support == '0'
-    with_legacy_support = 'false'
-endif
-if with_legacy_support != 'false'
-    if with_legacy_support == 'true'
-        with_legacy_support = '5'
-    endif
-    legacy_int = with_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 lib/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')
+# Explicit define legacy support
+add_project_arguments('-DZSTD_LEGACY_SUPPORT=@0@'.format(with_legacy_support),
+  language: 'c')
+
+if with_legacy_support == 0
+  message('Legacy support: DISABLED')
+else
+  # See ZSTD_LEGACY_SUPPORT of lib/README.md
+  message('Enable legacy support back to version 0.@0@'.format(with_legacy_support))
+
+  libzstd_includes += [ include_directories(join_paths(zstd_rootdir, 'lib/legacy')) ]
+  foreach i : [1, 2, 3, 4, 5, 6, 7]
+    if with_legacy_support <= i
+      libzstd_sources += join_paths(zstd_rootdir, 'lib/legacy/zstd_v0@0@.c'.format(i))
     endif
+  endforeach
 endif
 
+libzstd_deps = []
 if enable_multithread
-    message('Enable multi-threading support')
-    add_project_arguments('-DZSTD_MULTITHREAD', language: 'c')
-    libzstd_deps = [ thread_dep ]
-else
-    libzstd_deps = []
+  message('Enable multi-threading support')
+  add_project_arguments('-DZSTD_MULTITHREAD', language: 'c')
+  libzstd_deps = [ thread_dep ]
+endif
+
+libzstd_c_args = []
+if cc_id == compiler_msvc
+  if default_library_type != 'static'
+    libzstd_sources += [windows_mod.compile_resources(
+      join_paths(zstd_rootdir, 'build/VS2010/libzstd-dll/libzstd-dll.rc'))]
+    libzstd_c_args += ['-DZSTD_DLL_EXPORT=1',
+      '-DZSTD_HEAPMODE=0',
+      '-D_CONSOLE',
+      '-D_CRT_SECURE_NO_WARNINGS']
+  else
+    libzstd_c_args += ['-DZSTD_HEAPMODE=0',
+      '-D_CRT_SECURE_NO_WARNINGS']
+  endif
 endif
 
+mingw_ansi_stdio_flags = []
+if host_machine_os == os_windows and cc_id == compiler_gcc
+  mingw_ansi_stdio_flags = [ '-D__USE_MINGW_ANSI_STDIO' ]
+endif
+libzstd_c_args += mingw_ansi_stdio_flags
+
+libzstd_debug_cflags = []
+if enable_debug and meson_buildtype == 'debug'
+  if cc_id == compiler_gcc or cc_id == compiler_clang
+    libzstd_debug_cflags = ['-Wstrict-aliasing=1', '-Wswitch-enum',
+      '-Wdeclaration-after-statement', '-Wstrict-prototypes',
+      '-Wundef', '-Wpointer-arith', '-Wformat-security', '-Wvla',
+      '-Wformat=2', '-Winit-self', '-Wfloat-equal', '-Wwrite-strings',
+      '-Wredundant-decls', '-Wmissing-prototypes', '-Wc++-compat']
+  endif
+endif
+libzstd_c_args += cc.get_supported_arguments(libzstd_debug_cflags)
+
 libzstd = library('zstd',
-    libzstd_sources,
-    include_directories: libzstd_includes,
-    dependencies: libzstd_deps,
-    install: true,
-    soversion: zstd_version)
+  libzstd_sources,
+  include_directories: libzstd_includes,
+  c_args: libzstd_c_args,
+  dependencies: libzstd_deps,
+  install: true,
+  soversion: zstd_libversion)
+
+libzstd_dep = declare_dependency(link_with: libzstd,
+  include_directories: libzstd_includes)
 
 pkgconfig.generate(name: 'libzstd',
-    filebase: 'libzstd',
-    libraries: [libzstd],
-    description: 'fast lossless compression algorithm library',
-    version: zstd_version,
-    url: 'http://www.zstd.net/')
+  filebase: 'libzstd',
+  libraries: [libzstd],
+  description: 'fast lossless compression algorithm library',
+  version: zstd_libversion,
+  url: 'http://www.zstd.net/')
 
-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_common_dir, 'zstd_errors.h'))
+install_headers(join_paths(zstd_rootdir, 'lib/zstd.h'),
+  join_paths(zstd_rootdir, 'lib/deprecated/zbuff.h'),
+  join_paths(zstd_rootdir, 'lib/dictBuilder/zdict.h'),
+  join_paths(zstd_rootdir, 'lib/common/zstd_errors.h'))
index 750e841cfb3501840b5d488a3740e5d7760dbc24..f4c6f32d59a654d77bbf347bed82498c7b85f2ce 100644 (file)
@@ -10,7 +10,7 @@
 
 project('zstd',
     ['c', 'cpp'],
-    license: 'BSD',
+    license: ['BSD', 'GPLv2'],
     default_options : ['c_std=c99',
         'cpp_std=c++11',
         'buildtype=release'],
@@ -22,36 +22,65 @@ cc = meson.get_compiler('c')
 cxx = meson.get_compiler('cpp')
 pkgconfig = import('pkgconfig')
 python3 = import('python').find_installation()
+windows_mod = import('windows')
+
+host_machine_os = host_machine.system()
+os_windows = 'windows'
+os_linux = 'linux'
+os_darwin = 'darwin'
+os_freebsd = 'freebsd'
+os_sun = 'sunos'
+
+cc_id = cc.get_id()
+compiler_gcc = 'gcc'
+compiler_clang = 'clang'
+compiler_msvc = 'msvc'
 
 zstd_version = meson.project_version()
+zstd_libversion = ''
 
 # =============================================================================
 # 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_rootdir = '../..'
+
+# =============================================================================
+# Installing directories
+# =============================================================================
+
+if host_machine_os == os_windows
+    zstd_prefix = '.'
+    zstd_bindir = 'bin'
+    zstd_datadir = 'share'
+    zstd_mandir = join_paths(zstd_datadir, 'man')
+else
+    zstd_prefix = get_option('prefix')
+    zstd_bindir = join_paths(zstd_prefix, get_option('bindir'))
+    zstd_datadir = join_paths(zstd_prefix, get_option('datadir'))
+    zstd_mandir = join_paths(zstd_prefix, get_option('mandir'))
+endif
 
-zstd_source_dir = join_paths('..', '..')
-library_dir = join_paths(zstd_source_dir, 'lib')
-contrib_meson_dir = join_paths(zstd_source_dir, 'contrib', 'meson')
+zstd_docdir = join_paths(zstd_datadir, 'doc', meson.project_name())
 
 # =============================================================================
 # Project options
 # =============================================================================
 
 enable_debug = get_option('debug')
+default_library_type = get_option('default_library')
+meson_buildtype = get_option('buildtype')
 with_legacy_support = get_option('with-legacy-support')
 with_programs = get_option('with-programs')
 with_tests = get_option('with-tests')
 with_contrib = get_option('with-contrib')
+with_debug_level = get_option('with-debug-level')
 enable_multithread = get_option('enable-multithread')
+enable_static_runtime = get_option('enable-static-runtime')
 enable_zlib = get_option('enable-zlib')
 enable_lzma = get_option('enable-lzma')
 enable_lz4 = get_option('enable-lz4')
+enable_backtrace = get_option('enable-backtrace')
 
 # =============================================================================
 # Helper scripts for Meson
@@ -63,7 +92,7 @@ GetZstdLibraryVersion_py = files('GetZstdLibraryVersion.py')
 # Getting project version from zstd.h
 # =============================================================================
 
-zstd_h_file = join_paths(meson.current_source_dir(), library_dir, 'zstd.h')
+zstd_h_file = join_paths(meson.current_source_dir(), zstd_rootdir, 'lib/zstd.h')
 r = run_command(python3, GetZstdLibraryVersion_py, zstd_h_file)
 if r.returncode() == 0
     output = r.stdout().strip()
@@ -73,31 +102,42 @@ if r.returncode() == 0
     endif
 endif
 
+if host_machine_os != os_windows
+    zstd_libversion = zstd_version
+endif
+
 # =============================================================================
 # Dependencies
 # =============================================================================
 
-libm_dep = cc.find_library('m', required: true)
-thread_dep = dependency('threads', required: false)
+libm_dep = cc.find_library('m', required: with_tests)
+thread_dep = dependency('threads', required: enable_multithread)
 # Arguments in dependency should be equivalent to those passed to pkg-config
-zlib_dep = dependency('zlib', required: false)
-lzma_dep = dependency('liblzma', required: false)
-lz4_dep = dependency('liblz4', required: false)
+zlib_dep = dependency('zlib', required: enable_zlib)
+lzma_dep = dependency('liblzma', required: enable_lzma)
+lz4_dep = dependency('liblz4', required: enable_lz4)
 
 # =============================================================================
 # Compiler flags
 # =============================================================================
 
-if cxx.get_id() == 'gcc' or cxx.get_id() == 'clang'
-    common_flags = [ '-DXXH_NAMESPACE=ZSTD_' ]
+add_project_arguments('-DXXH_NAMESPACE=ZSTD_', language: [ 'c' ])
+
+if [compiler_gcc, compiler_clang].contains(cc_id)
     common_warning_flags = [ '-Wextra', '-Wundef', '-Wshadow', '-Wcast-align', '-Wcast-qual' ]
-    cc_compilation_flags = cc.get_supported_arguments(common_warning_flags)
-    cc_compilation_flags += cc.get_supported_arguments(['-Wstrict-prototypes'])
-    cc_compilation_flags += common_flags
-    cxx_compilation_flags = cxx.get_supported_arguments(common_warning_flags)
-    cxx_compilation_flags += common_flags
-    add_project_arguments(cc_compilation_flags, language : 'c')
-    add_project_arguments(cxx_compilation_flags, language : 'cpp')
+    cc_compile_flags = cc.get_supported_arguments(common_warning_flags + [ '-Wstrict-prototypes' ])
+    cxx_compile_flags = cxx.get_supported_arguments(common_warning_flags)
+    add_project_arguments(cc_compile_flags, language : 'c')
+    add_project_arguments(cxx_compile_flags, language : 'cpp')
+elif cc_id == compiler_msvc
+    msvc_compile_flags = [ '/D_UNICODE', '/DUNICODE' ]
+    if enable_multithread
+        msvc_compile_flags += [ '/MP' ]
+    endif
+    if enable_static_runtime
+        msvc_compile_flags += [ '/MT' ]
+    endif
+    add_project_arguments(msvc_compile_flags, language: ['c', 'cpp'])
 endif
 
 # =============================================================================
index dca6df809ecb382241f692f4c9368c709526da6a..d4bac3c4863fb082fcd4abd6e2899243395347a2 100644 (file)
@@ -8,21 +8,25 @@
 # in the COPYING file in the root directory of this source tree).
 # #############################################################################
 
-option('enable-multithread', type: 'boolean', value: true,
-    description: 'Enable multi-threading when pthread is detected')
-option('with-legacy-support', type: 'string', value: '5',
-    description: 'Support any legacy format: true or false, or 7 to 1 for v0.7+ to v0.1+')
+option('with-legacy-support', type: 'integer', min: 0, max: 7, value: '5',
+  description: 'Support any legacy format: 7 to 1 for v0.7+ to v0.1+')
 option('with-programs', type: 'boolean', value: true,
-    description: 'Enable programs build')
+  description: 'Enable programs build')
 option('with-contrib', type: 'boolean', value: false,
-    description: 'Enable contrib build')
+  description: 'Enable contrib build')
 option('with-tests', type: 'boolean', value: false,
-    description: 'Enable tests build')
+  description: 'Enable tests build')
+option('with-debug-level', type: 'integer', min: 0, max: 9, value: 1, # Since 0.45.0
+  description: 'Enable run-time debug. See lib/common/debug.h')
+option('enable-multithread', type: 'boolean', value: true,
+  description: 'Enable multi-threading when pthread is detected')
 option('enable-static-runtime', type: 'boolean', value: false,
-    description: 'Link to static run-time libraries on MSVC')
+  description: 'Link to static run-time libraries on MSVC')
 option('enable-zlib', type: 'boolean', value: false,
-    description: 'Enable zlib support')
+  description: 'Enable zlib support')
 option('enable-lzma', type: 'boolean', value: false,
-    description: 'Enable lzma support')
+  description: 'Enable lzma support')
 option('enable-lz4', type: 'boolean', value: false,
-    description: 'Enable lz4 support')
+  description: 'Enable lz4 support')
+option('enable-backtrace', type: 'boolean', value: false,
+  description: 'Display a stack backtrace when execution generates a runtime exception. Only in debug build mode.')
index c96b6d4584e022000d8fc84259504fd83c42c0ea..8102eda159dfff4b479658c1c7f83999d611a42d 100644 (file)
@@ -8,74 +8,86 @@
 # 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 = []
+zstd_rootdir = '../../..'
+
+zstd_programs_sources = [join_paths(zstd_rootdir, 'programs/zstdcli.c'),
+  join_paths(zstd_rootdir, 'programs/util.c'),
+  join_paths(zstd_rootdir, 'programs/fileio.c'),
+  join_paths(zstd_rootdir, 'programs/benchfn.c'),
+  join_paths(zstd_rootdir, 'programs/benchzstd.c'),
+  join_paths(zstd_rootdir, 'programs/datagen.c'),
+  join_paths(zstd_rootdir, 'programs/dibio.c')]
+
+zstd_c_args = libzstd_debug_cflags
 if enable_multithread
-    zstd_c_args += [ '-DZSTD_MULTITHREAD' ]
+  zstd_c_args += [ '-DZSTD_MULTITHREAD' ]
 endif
 
-zstd_deps = []
+zstd_deps = [ libzstd_dep ]
 if enable_zlib and zlib_dep.found()
-    zstd_deps += [ zlib_dep ]
-    zstd_c_args += [ '-DZSTD_GZCOMPRESS', '-DZSTD_GZDECOMPRESS' ]
+  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' ]
+  zstd_deps += [ lzma_dep ]
+  zstd_c_args += [ '-DZSTD_LZMACOMPRESS', '-DZSTD_LZMADECOMPRESS' ]
 endif
 
 if enable_lz4 and lz4_dep.found()
-    zstd_deps += [ lz4_dep ]
-    zstd_c_args += [ '-DZSTD_LZ4COMPRESS', '-DZSTD_LZ4DECOMPRESS' ]
+  zstd_deps += [ lz4_dep ]
+  zstd_c_args += [ '-DZSTD_LZ4COMPRESS', '-DZSTD_LZ4DECOMPRESS' ]
 endif
 
-zstd = executable('zstd',
-    zstd_programs_sources,
-    c_args: zstd_c_args,
-    include_directories: libzstd_includes,
-    link_with: libzstd,
-    dependencies: zstd_deps,
-    install: true)
+export_dynamic_on_windows = false
+# explicit backtrace enable/disable for Linux & Darwin
+if not enable_backtrace
+  zstd_c_args += '-DBACKTRACE_ENABLE=0'
+elif enable_debug and host_machine_os == os_windows  # MinGW target
+  zstd_c_args += '-DBACKTRACE_ENABLE=1'
+  export_dynamic_on_windows = true
+endif
 
-zstd_frugal_sources = [join_paths(programs_dir, 'zstdcli.c'),
-    util_c_file,
-    fileio_c_file]
+if cc_id == compiler_msvc
+  if default_library_type != 'static'
+    zstd_programs_sources += [windows_mod.compile_resources(
+      join_paths(zstd_rootdir, 'build/VS2010/zstd/zstd.rc'))]
+  endif
+endif
 
+zstd = executable('zstd',
+  zstd_programs_sources,
+  c_args: zstd_c_args,
+  dependencies: zstd_deps,
+  export_dynamic: export_dynamic_on_windows, # Since Meson 0.45.0
+  install: true)
+
+zstd_frugal_sources = [join_paths(zstd_rootdir, 'programs/zstdcli.c'),
+  join_paths(zstd_rootdir, 'programs/util.c'),
+  join_paths(zstd_rootdir, 'programs/fileio.c')]
+
+# Minimal target, with only zstd compression and decompression.
+# No bench. No legacy.
 executable('zstd-frugal',
-    zstd_frugal_sources,
-    include_directories: libzstd_includes,
-    link_with: libzstd,
-    c_args: [ '-DZSTD_NOBENCH', '-DZSTD_NODICT' ],
-    install: true)
+  zstd_frugal_sources,
+  dependencies: libzstd_dep,
+  c_args: [ '-DZSTD_NOBENCH', '-DZSTD_NODICT' ],
+  install: true)
 
-install_data(join_paths(programs_dir, 'zstdgrep'),
-    join_paths(programs_dir, 'zstdless'),
-    install_dir: zstd_bindir)
+install_data(join_paths(zstd_rootdir, 'programs/zstdgrep'),
+  join_paths(zstd_rootdir, 'programs/zstdless'),
+  install_dir: zstd_bindir)
 
 # =============================================================================
 # Program symlinks
 # =============================================================================
 
-InstallSymlink_py = join_paths('..', 'InstallSymlink.py')
+InstallSymlink_py = '../InstallSymlink.py'
 meson.add_install_script(InstallSymlink_py, 'zstd', 'zstdcat', zstd_bindir)
 meson.add_install_script(InstallSymlink_py, 'zstd', 'unzstd', zstd_bindir)
 
 if enable_multithread
-    meson.add_install_script(InstallSymlink_py, 'zstd', 'zstdmt', zstd_bindir)
+  meson.add_install_script(InstallSymlink_py, 'zstd', 'zstdmt', zstd_bindir)
 endif
 
 # =============================================================================
@@ -84,9 +96,9 @@ endif
 
 zstd_man1_dir = join_paths(zstd_mandir, 'man1')
 
-install_man(join_paths(programs_dir, 'zstd.1'),
-    join_paths(programs_dir, 'zstdgrep.1'),
-    join_paths(programs_dir, 'zstdless.1'))
+install_man(join_paths(zstd_rootdir, 'programs/zstd.1'),
+  join_paths(zstd_rootdir, 'programs/zstdgrep.1'),
+  join_paths(zstd_rootdir, 'programs/zstdless.1'))
 
 # Meson automatically compresses manpages to gz format
 # WARNING: This may fail on Windows. Test NEEDED.
@@ -94,5 +106,5 @@ meson.add_install_script(InstallSymlink_py, 'zstd.1.gz', 'zstdcat.1.gz', zstd_ma
 meson.add_install_script(InstallSymlink_py, 'zstd.1.gz', 'unzstd.1.gz', zstd_man1_dir)
 
 if enable_multithread
-    meson.add_install_script(InstallSymlink_py, 'zstd.1.gz', 'zstdmt.1.gz', zstd_man1_dir)
+  meson.add_install_script(InstallSymlink_py, 'zstd.1.gz', 'zstdmt.1.gz', zstd_man1_dir)
 endif