blob: 15c56c2b13aa90b65578b47ee198f5a207261e8a [file] [log] [blame]
Lzu Tao9a721e52018-11-28 01:04:41 +07001# #############################################################################
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# #############################################################################
Dima Krasnerc1f25ea2017-02-16 19:35:56 +020010
Lzu Tao9a721e52018-11-28 01:04:41 +070011project('zstd',
Lzu Taoc55d65b2018-11-30 16:15:33 +070012 ['c', 'cpp'],
13 license: ['BSD', 'GPLv2'],
Lzu Tao787a72c2018-12-28 11:20:33 +070014 default_options : [
Elliott Hughes44aba642023-09-12 20:18:59 +000015 # 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
Lzu Taoc55d65b2018-11-30 16:15:33 +070019 'cpp_std=c++11',
Eli Schwartzd95a3f52021-08-08 21:11:20 -040020 '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'
Lzu Tao787a72c2018-12-28 11:20:33 +070025 ],
Elliott Hughes44aba642023-09-12 20:18:59 +000026 version: run_command(
27 find_program('GetZstdLibraryVersion.py'), '../../lib/zstd.h',
28 check: true).stdout().strip(),
29 meson_version: '>=0.50.0')
Dima Krasnerc1f25ea2017-02-16 19:35:56 +020030
Lzu Tao9a721e52018-11-28 01:04:41 +070031cc = meson.get_compiler('c')
32cxx = meson.get_compiler('cpp')
33pkgconfig = import('pkgconfig')
Lzu Tao0a0683f2018-11-30 15:30:45 +070034windows_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'
Dima Krasnerc1f25ea2017-02-16 19:35:56 +020047
Lzu Tao9a721e52018-11-28 01:04:41 +070048zstd_version = meson.project_version()
Dima Krasnerc1f25ea2017-02-16 19:35:56 +020049
Lzu Taofa2fc272018-12-05 01:12:11 +070050zstd_libversion = zstd_version
Dima Krasnerc1f25ea2017-02-16 19:35:56 +020051
Lzu Tao0a0683f2018-11-30 15:30:45 +070052# =============================================================================
Lzu Taoc55d65b2018-11-30 16:15:33 +070053# Installation directories
Lzu Tao0a0683f2018-11-30 15:30:45 +070054# =============================================================================
55
Lzu Taofa2fc272018-12-05 01:12:11 +070056zstd_prefix = get_option('prefix')
57zstd_bindir = get_option('bindir')
58zstd_datadir = get_option('datadir')
59zstd_mandir = get_option('mandir')
Lzu Tao0a0683f2018-11-30 15:30:45 +070060zstd_docdir = join_paths(zstd_datadir, 'doc', meson.project_name())
Lzu Tao9a721e52018-11-28 01:04:41 +070061
62# =============================================================================
63# Project options
64# =============================================================================
Lzu Tao918e0d52018-11-29 12:52:35 +070065
Lzu Tao24bc5132018-11-30 21:05:03 +070066# Built-in options
67use_debug = get_option('debug')
Lzu Tao23d75152018-12-02 22:33:25 +070068buildtype = get_option('buildtype')
Bimba Shrestha834a8f82020-05-01 09:04:09 -050069default_library_type = get_option('default_library')
Lzu Tao24bc5132018-11-30 21:05:03 +070070
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
Lzu Tao8e590a12019-06-29 01:59:57 +070077bin_programs = get_option('bin_programs')
78bin_contrib = get_option('bin_contrib')
79bin_tests = get_option('bin_tests')
Lzu Tao24bc5132018-11-30 21:05:03 +070080
81feature_multi_thread = get_option('multi_thread')
82feature_zlib = get_option('zlib')
83feature_lzma = get_option('lzma')
84feature_lz4 = get_option('lz4')
Lzu Tao9a721e52018-11-28 01:04:41 +070085
86# =============================================================================
Lzu Tao9a721e52018-11-28 01:04:41 +070087# Dependencies
88# =============================================================================
89
Elliott Hughes44aba642023-09-12 20:18:59 +000090libm_dep = cc.find_library('m', required: false)
Lzu Tao24bc5132018-11-30 21:05:03 +070091thread_dep = dependency('threads', required: feature_multi_thread)
92use_multi_thread = thread_dep.found()
Lzu Taoc4fb45f2018-11-29 13:15:18 +070093# Arguments in dependency should be equivalent to those passed to pkg-config
Lzu Tao24bc5132018-11-30 21:05:03 +070094zlib_dep = dependency('zlib', required: feature_zlib)
95use_zlib = zlib_dep.found()
96lzma_dep = dependency('liblzma', required: feature_lzma)
97use_lzma = lzma_dep.found()
98lz4_dep = dependency('liblz4', required: feature_lz4)
99use_lz4 = lz4_dep.found()
Lzu Tao9a721e52018-11-28 01:04:41 +0700100
101# =============================================================================
102# Compiler flags
103# =============================================================================
104
Lzu Taoc55d65b2018-11-30 16:15:33 +0700105add_project_arguments('-DXXH_NAMESPACE=ZSTD_', language: ['c'])
Lzu Tao0a0683f2018-11-30 15:30:45 +0700106
Elliott Hughes44aba642023-09-12 20:18:59 +0000107pzstd_warning_flags = []
Lzu Tao0a0683f2018-11-30 15:30:45 +0700108if [compiler_gcc, compiler_clang].contains(cc_id)
Eli Schwartzd95a3f52021-08-08 21:11:20 -0400109 common_warning_flags = [ '-Wundef', '-Wshadow', '-Wcast-align', '-Wcast-qual' ]
Elliott Hughes44aba642023-09-12 20:18:59 +0000110 pzstd_warning_flags = ['-Wno-shadow', '-Wno-deprecated-declarations']
Lzu Taoc55d65b2018-11-30 16:15:33 +0700111 if cc_id == compiler_clang
Lzu Tao23d75152018-12-02 22:33:25 +0700112 common_warning_flags += ['-Wconversion', '-Wno-sign-conversion', '-Wdocumentation']
Lzu Taoc55d65b2018-11-30 16:15:33 +0700113 endif
114 cc_compile_flags = cc.get_supported_arguments(common_warning_flags + ['-Wstrict-prototypes'])
115 cxx_compile_flags = cxx.get_supported_arguments(common_warning_flags)
116 add_project_arguments(cc_compile_flags, language : 'c')
117 add_project_arguments(cxx_compile_flags, language : 'cpp')
Lzu Tao0a0683f2018-11-30 15:30:45 +0700118elif cc_id == compiler_msvc
Lzu Taoc55d65b2018-11-30 16:15:33 +0700119 msvc_compile_flags = [ '/D_UNICODE', '/DUNICODE' ]
Lzu Tao24bc5132018-11-30 21:05:03 +0700120 if use_multi_thread
Lzu Taoc55d65b2018-11-30 16:15:33 +0700121 msvc_compile_flags += '/MP'
122 endif
Bimba Shrestha834a8f82020-05-01 09:04:09 -0500123 if use_static_runtime
Lzu Taoc55d65b2018-11-30 16:15:33 +0700124 msvc_compile_flags += '/MT'
125 endif
126 add_project_arguments(msvc_compile_flags, language: ['c', 'cpp'])
Dima Krasnerfaaded12017-02-17 12:27:13 +0200127endif
128
Lzu Tao9a721e52018-11-28 01:04:41 +0700129# =============================================================================
130# Subdirs
131# =============================================================================
Dima Krasnerc1f25ea2017-02-16 19:35:56 +0200132
Lzu Tao9a721e52018-11-28 01:04:41 +0700133subdir('lib')
Lzu Taoc9f01442018-11-28 12:16:09 +0700134
Elliott Hughes44aba642023-09-12 20:18:59 +0000135if bin_programs or bin_tests
Lzu Taoc55d65b2018-11-30 16:15:33 +0700136 subdir('programs')
Lzu Tao9a721e52018-11-28 01:04:41 +0700137endif
Dima Krasnerc1f25ea2017-02-16 19:35:56 +0200138
Lzu Tao8e590a12019-06-29 01:59:57 +0700139if bin_tests
Lzu Taoc55d65b2018-11-30 16:15:33 +0700140 subdir('tests')
Lzu Tao9a721e52018-11-28 01:04:41 +0700141endif
Dima Krasnerc1f25ea2017-02-16 19:35:56 +0200142
Lzu Tao8e590a12019-06-29 01:59:57 +0700143if bin_contrib
Lzu Taoc55d65b2018-11-30 16:15:33 +0700144 subdir('contrib')
Dima Krasnerc1f25ea2017-02-16 19:35:56 +0200145endif