• 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
11project('zstd',
12  ['c', 'cpp'],
13  license: ['BSD', 'GPLv2'],
14  default_options : [
15    'c_std=gnu99',
16    'cpp_std=c++11',
17    'buildtype=release',
18    'warning_level=3',
19    # -Wdocumentation does not actually pass, nor do the test binaries,
20    # so this isn't safe
21    #'werror=true'
22  ],
23  version: 'DUMMY',
24  meson_version: '>=0.48.0')
25
26cc = meson.get_compiler('c')
27cxx = meson.get_compiler('cpp')
28pkgconfig = import('pkgconfig')
29windows_mod = import('windows')
30
31host_machine_os = host_machine.system()
32os_windows = 'windows'
33os_linux = 'linux'
34os_darwin = 'darwin'
35os_freebsd = 'freebsd'
36os_sun = 'sunos'
37
38cc_id = cc.get_id()
39compiler_gcc = 'gcc'
40compiler_clang = 'clang'
41compiler_msvc = 'msvc'
42
43zstd_version = meson.project_version()
44
45zstd_h_file = join_paths(meson.current_source_dir(), '../../lib/zstd.h')
46GetZstdLibraryVersion_py = find_program('GetZstdLibraryVersion.py', native : true)
47r = run_command(GetZstdLibraryVersion_py, zstd_h_file)
48if r.returncode() == 0
49  zstd_version = r.stdout().strip()
50  message('Project version is now: @0@'.format(zstd_version))
51else
52  error('Cannot find project version in @0@'.format(zstd_h_file))
53endif
54
55zstd_libversion = zstd_version
56
57# =============================================================================
58# Installation directories
59# =============================================================================
60
61zstd_prefix = get_option('prefix')
62zstd_bindir = get_option('bindir')
63zstd_datadir = get_option('datadir')
64zstd_mandir = get_option('mandir')
65zstd_docdir = join_paths(zstd_datadir, 'doc', meson.project_name())
66
67# =============================================================================
68# Project options
69# =============================================================================
70
71# Built-in options
72use_debug = get_option('debug')
73buildtype = get_option('buildtype')
74default_library_type = get_option('default_library')
75
76# Custom options
77debug_level = get_option('debug_level')
78legacy_level = get_option('legacy_level')
79use_backtrace = get_option('backtrace')
80use_static_runtime = get_option('static_runtime')
81
82bin_programs = get_option('bin_programs')
83bin_contrib = get_option('bin_contrib')
84bin_tests = get_option('bin_tests')
85
86feature_multi_thread = get_option('multi_thread')
87feature_zlib = get_option('zlib')
88feature_lzma = get_option('lzma')
89feature_lz4 = get_option('lz4')
90
91# =============================================================================
92# Dependencies
93# =============================================================================
94
95libm_dep = cc.find_library('m', required: bin_tests)
96thread_dep = dependency('threads', required: feature_multi_thread)
97use_multi_thread = thread_dep.found()
98# Arguments in dependency should be equivalent to those passed to pkg-config
99zlib_dep = dependency('zlib', required: feature_zlib)
100use_zlib = zlib_dep.found()
101lzma_dep = dependency('liblzma', required: feature_lzma)
102use_lzma = lzma_dep.found()
103lz4_dep = dependency('liblz4', required: feature_lz4)
104use_lz4 = lz4_dep.found()
105
106# =============================================================================
107# Compiler flags
108# =============================================================================
109
110add_project_arguments('-DXXH_NAMESPACE=ZSTD_', language: ['c'])
111
112if [compiler_gcc, compiler_clang].contains(cc_id)
113  common_warning_flags = [ '-Wundef', '-Wshadow', '-Wcast-align', '-Wcast-qual' ]
114  if cc_id == compiler_clang
115    common_warning_flags += ['-Wconversion', '-Wno-sign-conversion', '-Wdocumentation']
116  endif
117  cc_compile_flags = cc.get_supported_arguments(common_warning_flags + ['-Wstrict-prototypes'])
118  cxx_compile_flags = cxx.get_supported_arguments(common_warning_flags)
119  add_project_arguments(cc_compile_flags, language : 'c')
120  add_project_arguments(cxx_compile_flags, language : 'cpp')
121elif cc_id == compiler_msvc
122  msvc_compile_flags = [ '/D_UNICODE', '/DUNICODE' ]
123  if use_multi_thread
124    msvc_compile_flags += '/MP'
125  endif
126  if use_static_runtime
127    msvc_compile_flags += '/MT'
128  endif
129  add_project_arguments(msvc_compile_flags, language: ['c', 'cpp'])
130endif
131
132# =============================================================================
133# Subdirs
134# =============================================================================
135
136subdir('lib')
137
138if bin_programs
139  subdir('programs')
140endif
141
142if bin_tests
143  subdir('tests')
144endif
145
146if bin_contrib
147  subdir('contrib')
148endif
149