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 # There shouldn't be any need to force a C standard convention for zstd 16 # but in case one would want that anyway, this can be done here. 17 # 'c_std=gnu99', 18 # c++11 standard is useful for pzstd 19 'cpp_std=c++11', 20 'buildtype=release', 21 'warning_level=3', 22 # -Wdocumentation does not actually pass, nor do the test binaries, 23 # so this isn't safe 24 #'werror=true' 25 ], 26 version: run_command( 27 find_program('GetZstdLibraryVersion.py'), '../../lib/zstd.h', 28 check: true).stdout().strip(), 29 meson_version: '>=0.50.0') 30 31cc = meson.get_compiler('c') 32cxx = meson.get_compiler('cpp') 33pkgconfig = import('pkgconfig') 34windows_mod = import('windows') 35 36host_machine_os = host_machine.system() 37os_windows = 'windows' 38os_linux = 'linux' 39os_darwin = 'darwin' 40os_freebsd = 'freebsd' 41os_sun = 'sunos' 42 43cc_id = cc.get_id() 44compiler_gcc = 'gcc' 45compiler_clang = 'clang' 46compiler_msvc = 'msvc' 47 48zstd_version = meson.project_version() 49 50zstd_libversion = zstd_version 51 52# ============================================================================= 53# Installation directories 54# ============================================================================= 55 56zstd_prefix = get_option('prefix') 57zstd_bindir = get_option('bindir') 58zstd_datadir = get_option('datadir') 59zstd_mandir = get_option('mandir') 60zstd_docdir = join_paths(zstd_datadir, 'doc', meson.project_name()) 61 62# ============================================================================= 63# Project options 64# ============================================================================= 65 66# Built-in options 67use_debug = get_option('debug') 68buildtype = get_option('buildtype') 69default_library_type = get_option('default_library') 70 71# Custom options 72debug_level = get_option('debug_level') 73legacy_level = get_option('legacy_level') 74use_backtrace = get_option('backtrace') 75use_static_runtime = get_option('static_runtime') 76 77bin_programs = get_option('bin_programs') 78bin_contrib = get_option('bin_contrib') 79bin_tests = get_option('bin_tests') 80 81feature_multi_thread = get_option('multi_thread') 82feature_zlib = get_option('zlib') 83feature_lzma = get_option('lzma') 84feature_lz4 = get_option('lz4') 85 86# ============================================================================= 87# Dependencies 88# ============================================================================= 89 90libm_dep = cc.find_library('m', required: false) 91if host_machine_os == os_windows 92 thread_dep = dependency('', required: false) 93 use_multi_thread = not feature_multi_thread.disabled() 94else 95 thread_dep = dependency('threads', required: feature_multi_thread) 96 use_multi_thread = thread_dep.found() 97endif 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 112pzstd_warning_flags = [] 113if [compiler_gcc, compiler_clang].contains(cc_id) 114 common_warning_flags = [ '-Wundef', '-Wshadow', '-Wcast-align', '-Wcast-qual' ] 115 pzstd_warning_flags = ['-Wno-shadow', '-Wno-deprecated-declarations'] 116 if cc_id == compiler_clang 117 common_warning_flags += ['-Wconversion', '-Wno-sign-conversion', '-Wdocumentation'] 118 endif 119 noexecstack_flags = ['-Wa,--noexecstack' ] 120 noexecstack_link_flags = ['-Wl,-z,noexecstack'] 121 cc_compile_flags = cc.get_supported_arguments(common_warning_flags + noexecstack_flags + ['-Wstrict-prototypes']) 122 cxx_compile_flags = cxx.get_supported_arguments(common_warning_flags + noexecstack_flags) 123 add_project_arguments(cc_compile_flags, language : 'c') 124 add_project_arguments(cxx_compile_flags, language : 'cpp') 125 cc_link_flags = cc.get_supported_link_arguments(noexecstack_link_flags) 126 cxx_link_flags = cxx.get_supported_link_arguments(noexecstack_link_flags) 127 add_project_link_arguments(cc_link_flags, language: 'c') 128 add_project_link_arguments(cxx_link_flags, language: 'cpp') 129elif cc_id == compiler_msvc 130 msvc_compile_flags = [ '/D_UNICODE', '/DUNICODE' ] 131 if use_multi_thread 132 msvc_compile_flags += '/MP' 133 endif 134 if use_static_runtime 135 msvc_compile_flags += '/MT' 136 endif 137 add_project_arguments(msvc_compile_flags, language: ['c', 'cpp']) 138endif 139 140# ============================================================================= 141# Subdirs 142# ============================================================================= 143 144subdir('lib') 145 146if bin_programs or bin_tests 147 subdir('programs') 148endif 149 150if bin_tests 151 subdir('tests') 152endif 153 154if bin_contrib 155 subdir('contrib') 156endif 157