Lzu Tao | 9a721e5 | 2018-11-28 01:04:41 +0700 | [diff] [blame] | 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 | # ############################################################################# |
Dima Krasner | c1f25ea | 2017-02-16 19:35:56 +0200 | [diff] [blame] | 10 | |
Lzu Tao | 9a721e5 | 2018-11-28 01:04:41 +0700 | [diff] [blame] | 11 | project('zstd', |
Lzu Tao | c55d65b | 2018-11-30 16:15:33 +0700 | [diff] [blame] | 12 | ['c', 'cpp'], |
| 13 | license: ['BSD', 'GPLv2'], |
Lzu Tao | 787a72c | 2018-12-28 11:20:33 +0700 | [diff] [blame] | 14 | default_options : [ |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 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 |
Lzu Tao | c55d65b | 2018-11-30 16:15:33 +0700 | [diff] [blame] | 19 | 'cpp_std=c++11', |
Eli Schwartz | d95a3f5 | 2021-08-08 21:11:20 -0400 | [diff] [blame] | 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' |
Lzu Tao | 787a72c | 2018-12-28 11:20:33 +0700 | [diff] [blame] | 25 | ], |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 26 | version: run_command( |
| 27 | find_program('GetZstdLibraryVersion.py'), '../../lib/zstd.h', |
| 28 | check: true).stdout().strip(), |
| 29 | meson_version: '>=0.50.0') |
Dima Krasner | c1f25ea | 2017-02-16 19:35:56 +0200 | [diff] [blame] | 30 | |
Lzu Tao | 9a721e5 | 2018-11-28 01:04:41 +0700 | [diff] [blame] | 31 | cc = meson.get_compiler('c') |
| 32 | cxx = meson.get_compiler('cpp') |
| 33 | pkgconfig = import('pkgconfig') |
Lzu Tao | 0a0683f | 2018-11-30 15:30:45 +0700 | [diff] [blame] | 34 | windows_mod = import('windows') |
| 35 | |
| 36 | host_machine_os = host_machine.system() |
| 37 | os_windows = 'windows' |
| 38 | os_linux = 'linux' |
| 39 | os_darwin = 'darwin' |
| 40 | os_freebsd = 'freebsd' |
| 41 | os_sun = 'sunos' |
| 42 | |
| 43 | cc_id = cc.get_id() |
| 44 | compiler_gcc = 'gcc' |
| 45 | compiler_clang = 'clang' |
| 46 | compiler_msvc = 'msvc' |
Dima Krasner | c1f25ea | 2017-02-16 19:35:56 +0200 | [diff] [blame] | 47 | |
Lzu Tao | 9a721e5 | 2018-11-28 01:04:41 +0700 | [diff] [blame] | 48 | zstd_version = meson.project_version() |
Dima Krasner | c1f25ea | 2017-02-16 19:35:56 +0200 | [diff] [blame] | 49 | |
Lzu Tao | fa2fc27 | 2018-12-05 01:12:11 +0700 | [diff] [blame] | 50 | zstd_libversion = zstd_version |
Dima Krasner | c1f25ea | 2017-02-16 19:35:56 +0200 | [diff] [blame] | 51 | |
Lzu Tao | 0a0683f | 2018-11-30 15:30:45 +0700 | [diff] [blame] | 52 | # ============================================================================= |
Lzu Tao | c55d65b | 2018-11-30 16:15:33 +0700 | [diff] [blame] | 53 | # Installation directories |
Lzu Tao | 0a0683f | 2018-11-30 15:30:45 +0700 | [diff] [blame] | 54 | # ============================================================================= |
| 55 | |
Lzu Tao | fa2fc27 | 2018-12-05 01:12:11 +0700 | [diff] [blame] | 56 | zstd_prefix = get_option('prefix') |
| 57 | zstd_bindir = get_option('bindir') |
| 58 | zstd_datadir = get_option('datadir') |
| 59 | zstd_mandir = get_option('mandir') |
Lzu Tao | 0a0683f | 2018-11-30 15:30:45 +0700 | [diff] [blame] | 60 | zstd_docdir = join_paths(zstd_datadir, 'doc', meson.project_name()) |
Lzu Tao | 9a721e5 | 2018-11-28 01:04:41 +0700 | [diff] [blame] | 61 | |
| 62 | # ============================================================================= |
| 63 | # Project options |
| 64 | # ============================================================================= |
Lzu Tao | 918e0d5 | 2018-11-29 12:52:35 +0700 | [diff] [blame] | 65 | |
Lzu Tao | 24bc513 | 2018-11-30 21:05:03 +0700 | [diff] [blame] | 66 | # Built-in options |
| 67 | use_debug = get_option('debug') |
Lzu Tao | 23d7515 | 2018-12-02 22:33:25 +0700 | [diff] [blame] | 68 | buildtype = get_option('buildtype') |
Bimba Shrestha | 834a8f8 | 2020-05-01 09:04:09 -0500 | [diff] [blame] | 69 | default_library_type = get_option('default_library') |
Lzu Tao | 24bc513 | 2018-11-30 21:05:03 +0700 | [diff] [blame] | 70 | |
| 71 | # Custom options |
| 72 | debug_level = get_option('debug_level') |
| 73 | legacy_level = get_option('legacy_level') |
| 74 | use_backtrace = get_option('backtrace') |
| 75 | use_static_runtime = get_option('static_runtime') |
| 76 | |
Lzu Tao | 8e590a1 | 2019-06-29 01:59:57 +0700 | [diff] [blame] | 77 | bin_programs = get_option('bin_programs') |
| 78 | bin_contrib = get_option('bin_contrib') |
| 79 | bin_tests = get_option('bin_tests') |
Lzu Tao | 24bc513 | 2018-11-30 21:05:03 +0700 | [diff] [blame] | 80 | |
| 81 | feature_multi_thread = get_option('multi_thread') |
| 82 | feature_zlib = get_option('zlib') |
| 83 | feature_lzma = get_option('lzma') |
| 84 | feature_lz4 = get_option('lz4') |
Lzu Tao | 9a721e5 | 2018-11-28 01:04:41 +0700 | [diff] [blame] | 85 | |
| 86 | # ============================================================================= |
Lzu Tao | 9a721e5 | 2018-11-28 01:04:41 +0700 | [diff] [blame] | 87 | # Dependencies |
| 88 | # ============================================================================= |
| 89 | |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 90 | libm_dep = cc.find_library('m', required: false) |
Lzu Tao | 24bc513 | 2018-11-30 21:05:03 +0700 | [diff] [blame] | 91 | thread_dep = dependency('threads', required: feature_multi_thread) |
| 92 | use_multi_thread = thread_dep.found() |
Lzu Tao | c4fb45f | 2018-11-29 13:15:18 +0700 | [diff] [blame] | 93 | # Arguments in dependency should be equivalent to those passed to pkg-config |
Lzu Tao | 24bc513 | 2018-11-30 21:05:03 +0700 | [diff] [blame] | 94 | zlib_dep = dependency('zlib', required: feature_zlib) |
| 95 | use_zlib = zlib_dep.found() |
| 96 | lzma_dep = dependency('liblzma', required: feature_lzma) |
| 97 | use_lzma = lzma_dep.found() |
| 98 | lz4_dep = dependency('liblz4', required: feature_lz4) |
| 99 | use_lz4 = lz4_dep.found() |
Lzu Tao | 9a721e5 | 2018-11-28 01:04:41 +0700 | [diff] [blame] | 100 | |
| 101 | # ============================================================================= |
| 102 | # Compiler flags |
| 103 | # ============================================================================= |
| 104 | |
Lzu Tao | c55d65b | 2018-11-30 16:15:33 +0700 | [diff] [blame] | 105 | add_project_arguments('-DXXH_NAMESPACE=ZSTD_', language: ['c']) |
Lzu Tao | 0a0683f | 2018-11-30 15:30:45 +0700 | [diff] [blame] | 106 | |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 107 | pzstd_warning_flags = [] |
Lzu Tao | 0a0683f | 2018-11-30 15:30:45 +0700 | [diff] [blame] | 108 | if [compiler_gcc, compiler_clang].contains(cc_id) |
Eli Schwartz | d95a3f5 | 2021-08-08 21:11:20 -0400 | [diff] [blame] | 109 | common_warning_flags = [ '-Wundef', '-Wshadow', '-Wcast-align', '-Wcast-qual' ] |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 110 | pzstd_warning_flags = ['-Wno-shadow', '-Wno-deprecated-declarations'] |
Lzu Tao | c55d65b | 2018-11-30 16:15:33 +0700 | [diff] [blame] | 111 | if cc_id == compiler_clang |
Lzu Tao | 23d7515 | 2018-12-02 22:33:25 +0700 | [diff] [blame] | 112 | common_warning_flags += ['-Wconversion', '-Wno-sign-conversion', '-Wdocumentation'] |
Lzu Tao | c55d65b | 2018-11-30 16:15:33 +0700 | [diff] [blame] | 113 | 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 Tao | 0a0683f | 2018-11-30 15:30:45 +0700 | [diff] [blame] | 118 | elif cc_id == compiler_msvc |
Lzu Tao | c55d65b | 2018-11-30 16:15:33 +0700 | [diff] [blame] | 119 | msvc_compile_flags = [ '/D_UNICODE', '/DUNICODE' ] |
Lzu Tao | 24bc513 | 2018-11-30 21:05:03 +0700 | [diff] [blame] | 120 | if use_multi_thread |
Lzu Tao | c55d65b | 2018-11-30 16:15:33 +0700 | [diff] [blame] | 121 | msvc_compile_flags += '/MP' |
| 122 | endif |
Bimba Shrestha | 834a8f8 | 2020-05-01 09:04:09 -0500 | [diff] [blame] | 123 | if use_static_runtime |
Lzu Tao | c55d65b | 2018-11-30 16:15:33 +0700 | [diff] [blame] | 124 | msvc_compile_flags += '/MT' |
| 125 | endif |
| 126 | add_project_arguments(msvc_compile_flags, language: ['c', 'cpp']) |
Dima Krasner | faaded1 | 2017-02-17 12:27:13 +0200 | [diff] [blame] | 127 | endif |
| 128 | |
Lzu Tao | 9a721e5 | 2018-11-28 01:04:41 +0700 | [diff] [blame] | 129 | # ============================================================================= |
| 130 | # Subdirs |
| 131 | # ============================================================================= |
Dima Krasner | c1f25ea | 2017-02-16 19:35:56 +0200 | [diff] [blame] | 132 | |
Lzu Tao | 9a721e5 | 2018-11-28 01:04:41 +0700 | [diff] [blame] | 133 | subdir('lib') |
Lzu Tao | c9f0144 | 2018-11-28 12:16:09 +0700 | [diff] [blame] | 134 | |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 135 | if bin_programs or bin_tests |
Lzu Tao | c55d65b | 2018-11-30 16:15:33 +0700 | [diff] [blame] | 136 | subdir('programs') |
Lzu Tao | 9a721e5 | 2018-11-28 01:04:41 +0700 | [diff] [blame] | 137 | endif |
Dima Krasner | c1f25ea | 2017-02-16 19:35:56 +0200 | [diff] [blame] | 138 | |
Lzu Tao | 8e590a1 | 2019-06-29 01:59:57 +0700 | [diff] [blame] | 139 | if bin_tests |
Lzu Tao | c55d65b | 2018-11-30 16:15:33 +0700 | [diff] [blame] | 140 | subdir('tests') |
Lzu Tao | 9a721e5 | 2018-11-28 01:04:41 +0700 | [diff] [blame] | 141 | endif |
Dima Krasner | c1f25ea | 2017-02-16 19:35:56 +0200 | [diff] [blame] | 142 | |
Lzu Tao | 8e590a1 | 2019-06-29 01:59:57 +0700 | [diff] [blame] | 143 | if bin_contrib |
Lzu Tao | c55d65b | 2018-11-30 16:15:33 +0700 | [diff] [blame] | 144 | subdir('contrib') |
Dima Krasner | c1f25ea | 2017-02-16 19:35:56 +0200 | [diff] [blame] | 145 | endif |