meson.build 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. # #############################################################################
  2. # Copyright (c) 2018-present Dima Krasner <[email protected]>
  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. project('zstd',
  11. ['c', 'cpp'],
  12. license: ['BSD', 'GPLv2'],
  13. default_options : [
  14. 'c_std=gnu99',
  15. 'cpp_std=c++11',
  16. 'buildtype=release',
  17. 'warning_level=3',
  18. # -Wdocumentation does not actually pass, nor do the test binaries,
  19. # so this isn't safe
  20. #'werror=true'
  21. ],
  22. version: 'DUMMY',
  23. meson_version: '>=0.48.0')
  24. cc = meson.get_compiler('c')
  25. cxx = meson.get_compiler('cpp')
  26. pkgconfig = import('pkgconfig')
  27. windows_mod = import('windows')
  28. host_machine_os = host_machine.system()
  29. os_windows = 'windows'
  30. os_linux = 'linux'
  31. os_darwin = 'darwin'
  32. os_freebsd = 'freebsd'
  33. os_sun = 'sunos'
  34. cc_id = cc.get_id()
  35. compiler_gcc = 'gcc'
  36. compiler_clang = 'clang'
  37. compiler_msvc = 'msvc'
  38. zstd_version = meson.project_version()
  39. zstd_h_file = join_paths(meson.current_source_dir(), '../../lib/zstd.h')
  40. GetZstdLibraryVersion_py = find_program('GetZstdLibraryVersion.py', native : true)
  41. r = run_command(GetZstdLibraryVersion_py, zstd_h_file)
  42. if r.returncode() == 0
  43. zstd_version = r.stdout().strip()
  44. message('Project version is now: @0@'.format(zstd_version))
  45. else
  46. error('Cannot find project version in @0@'.format(zstd_h_file))
  47. endif
  48. zstd_libversion = zstd_version
  49. # =============================================================================
  50. # Installation directories
  51. # =============================================================================
  52. zstd_prefix = get_option('prefix')
  53. zstd_bindir = get_option('bindir')
  54. zstd_datadir = get_option('datadir')
  55. zstd_mandir = get_option('mandir')
  56. zstd_docdir = join_paths(zstd_datadir, 'doc', meson.project_name())
  57. # =============================================================================
  58. # Project options
  59. # =============================================================================
  60. # Built-in options
  61. use_debug = get_option('debug')
  62. buildtype = get_option('buildtype')
  63. default_library_type = get_option('default_library')
  64. # Custom options
  65. debug_level = get_option('debug_level')
  66. legacy_level = get_option('legacy_level')
  67. use_backtrace = get_option('backtrace')
  68. use_static_runtime = get_option('static_runtime')
  69. bin_programs = get_option('bin_programs')
  70. bin_contrib = get_option('bin_contrib')
  71. bin_tests = get_option('bin_tests')
  72. feature_multi_thread = get_option('multi_thread')
  73. feature_zlib = get_option('zlib')
  74. feature_lzma = get_option('lzma')
  75. feature_lz4 = get_option('lz4')
  76. # =============================================================================
  77. # Dependencies
  78. # =============================================================================
  79. libm_dep = cc.find_library('m', required: bin_tests)
  80. thread_dep = dependency('threads', required: feature_multi_thread)
  81. use_multi_thread = thread_dep.found()
  82. # Arguments in dependency should be equivalent to those passed to pkg-config
  83. zlib_dep = dependency('zlib', required: feature_zlib)
  84. use_zlib = zlib_dep.found()
  85. lzma_dep = dependency('liblzma', required: feature_lzma)
  86. use_lzma = lzma_dep.found()
  87. lz4_dep = dependency('liblz4', required: feature_lz4)
  88. use_lz4 = lz4_dep.found()
  89. # =============================================================================
  90. # Compiler flags
  91. # =============================================================================
  92. add_project_arguments('-DXXH_NAMESPACE=ZSTD_', language: ['c'])
  93. if [compiler_gcc, compiler_clang].contains(cc_id)
  94. common_warning_flags = [ '-Wundef', '-Wshadow', '-Wcast-align', '-Wcast-qual' ]
  95. if cc_id == compiler_clang
  96. common_warning_flags += ['-Wconversion', '-Wno-sign-conversion', '-Wdocumentation']
  97. endif
  98. cc_compile_flags = cc.get_supported_arguments(common_warning_flags + ['-Wstrict-prototypes'])
  99. cxx_compile_flags = cxx.get_supported_arguments(common_warning_flags)
  100. add_project_arguments(cc_compile_flags, language : 'c')
  101. add_project_arguments(cxx_compile_flags, language : 'cpp')
  102. elif cc_id == compiler_msvc
  103. msvc_compile_flags = [ '/D_UNICODE', '/DUNICODE' ]
  104. if use_multi_thread
  105. msvc_compile_flags += '/MP'
  106. endif
  107. if use_static_runtime
  108. msvc_compile_flags += '/MT'
  109. endif
  110. add_project_arguments(msvc_compile_flags, language: ['c', 'cpp'])
  111. endif
  112. # =============================================================================
  113. # Subdirs
  114. # =============================================================================
  115. subdir('lib')
  116. if bin_programs
  117. subdir('programs')
  118. endif
  119. if bin_tests
  120. subdir('tests')
  121. endif
  122. if bin_contrib
  123. subdir('contrib')
  124. endif