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