1# #############################################################################
2# Copyright (c) 2018-present    lzutao <taolzu(at)gmail.com>
3# All rights reserved.
4#
5# This source code is licensed under both the BSD-style license (found in the
6# LICENSE file in the root directory of this source tree) and the GPLv2 (found
7# in the COPYING file in the root directory of this source tree).
8# #############################################################################
9
10cc = meson.get_compiler('c')
11pkgconfig = import('pkgconfig')
12c_std = get_option('c_std')
13default_library = get_option('default_library')
14
15host_machine_os = host_machine.system()
16os_windows = 'windows'
17os_linux = 'linux'
18os_darwin = 'darwin'
19os_freebsd = 'freebsd'
20os_sun = 'sunos'
21
22cc_id = cc.get_id()
23compiler_gcc = 'gcc'
24compiler_clang = 'clang'
25compiler_msvc = 'msvc'
26
27lz4_version = meson.project_version()
28
29lz4_h_file = join_paths(meson.current_source_dir(), '../../../lib/lz4.h')
30GetLz4LibraryVersion_py = find_program('GetLz4LibraryVersion.py', native : true)
31r = run_command(GetLz4LibraryVersion_py, lz4_h_file)
32if r.returncode() == 0
33  lz4_version = r.stdout().strip()
34  message('Project version is now: @0@'.format(lz4_version))
35else
36  error('Cannot find project version in @0@'.format(lz4_h_file))
37endif
38
39lz4_libversion = lz4_version
40
41# =============================================================================
42# Installation directories
43# =============================================================================
44
45lz4_prefix = get_option('prefix')
46lz4_bindir = get_option('bindir')
47lz4_datadir = get_option('datadir')
48lz4_mandir = get_option('mandir')
49lz4_docdir = join_paths(lz4_datadir, 'doc', meson.project_name())
50
51# =============================================================================
52# Project options
53# =============================================================================
54
55buildtype = get_option('buildtype')
56
57# Built-in options
58use_debug = get_option('debug')
59
60# Custom options
61debug_level = get_option('debug_level')
62use_backtrace = get_option('backtrace')
63
64bin_programs = get_option('bin_programs')
65bin_contrib = get_option('bin_contrib')
66bin_tests = get_option('bin_tests')
67bin_examples = get_option('bin_examples')
68#feature_multi_thread = get_option('multi_thread')
69
70# =============================================================================
71# Dependencies
72# =============================================================================
73
74#libm_dep = cc.find_library('m', required: bin_tests)
75#thread_dep = dependency('threads', required: feature_multi_thread)
76#use_multi_thread = thread_dep.found()
77
78# =============================================================================
79# Compiler flags
80# =============================================================================
81
82add_project_arguments(['-DXXH_NAMESPACE=LZ4_'], language: 'c')
83
84if [compiler_gcc, compiler_clang].contains(cc_id)
85  common_warning_flags = []
86  # Should use Meson's own --werror build option
87  #common_warning_flags += ['-Werror']
88  if c_std == 'c89' or c_std == 'gnu89'
89    common_warning_flags += ['-pedantic', '-Wno-long-long', '-Wno-variadic-macros']
90  elif c_std == 'c99' or c_std == 'gnu99'
91    common_warning_flags += ['-pedantic']
92  endif
93  cc_compile_flags = cc.get_supported_arguments(common_warning_flags)
94  add_project_arguments(cc_compile_flags, language: 'c')
95endif
96
97# =============================================================================
98# Subdirs
99# =============================================================================
100
101subdir('lib')
102
103if bin_programs
104  subdir('programs')
105endif
106
107if bin_tests
108  subdir('tests')
109endif
110
111if bin_contrib
112  subdir('contrib')
113endif
114
115if bin_examples
116  subdir('examples')
117endif
118