meson.build 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. project('speex', 'c', version: '1.2.1',
  2. meson_version: '>= 0.59')
  3. libversion = '1.5.2'
  4. speex_version = meson.project_version()
  5. version_arr = speex_version.split('.')
  6. speex_version_major = version_arr[0].to_int()
  7. speex_version_minor = version_arr[1].to_int()
  8. # extra version might be "-svn" or ".2" or empty
  9. if version_arr.length() == 4
  10. speex_version_micro = version_arr[2].to_int()
  11. speex_version_extra = '.' + version_arr[3]
  12. elif version_arr[2].contains('-')
  13. speex_version_micro = version_arr[2].split('-')[0].to_int()
  14. speex_version_extra = '-' + version_arr[2].split('-')[1]
  15. else
  16. speex_version_micro = version_arr[2].to_int()
  17. speex_version_extra = ''
  18. endif
  19. host_system = host_machine.system()
  20. host_cpu_family = host_machine.cpu_family()
  21. if host_machine.endian() == 'big'
  22. cdata.set('WORDS_BIGENDIAN', true)
  23. endif
  24. cc = meson.get_compiler('c')
  25. config_inc = include_directories('.')
  26. speex_incs = include_directories('include', 'include/speex')
  27. cdata = configuration_data()
  28. add_project_arguments('-DHAVE_CONFIG_H=1', language: 'c')
  29. cdata.set_quoted('SPEEX_VERSION', speex_version,
  30. description: 'Complete version string')
  31. cdata.set('SPEEX_MAJOR_VERSION', speex_version_major,
  32. description: 'Version major')
  33. cdata.set('SPEEX_MINOR_VERSION', speex_version_minor,
  34. description: 'Version minor')
  35. cdata.set('SPEEX_MICRO_VERSION', speex_version_micro,
  36. description: 'Version micro')
  37. cdata.set_quoted('SPEEX_EXTRA_VERSION', speex_version_extra,
  38. description: 'Version extra (version suffix string)')
  39. # Test whether the compiler supports the 'long double' type.
  40. have_var_arrays = cc.compiles('void func (int n) {int arr[n]; }',
  41. name: 'C99 variable-size arrays')
  42. cdata.set('VAR_ARRAYS', have_var_arrays,
  43. description: 'Use C99 variable-size arrays')
  44. has_sse = false
  45. if host_cpu_family in ['x86', 'x86_64'] and get_option('sse').allowed()
  46. intrin_check = '''#include <xmmintrin.h>
  47. __m128 testfunc(float *a, float *b) {
  48. return _mm_add_ps(_mm_loadu_ps(a), _mm_loadu_ps(b));
  49. }
  50. int main (int argc, char ** argv) {
  51. float a = 2.0, b = 99.0;
  52. testfunc(&a, &b);
  53. return 0;
  54. }
  55. '''
  56. # Intrinsics arguments are not available with MSVC-like compilers
  57. intrin_args = cc.get_argument_syntax() == 'msvc' ? [] : ['-msse']
  58. if cc.links(intrin_check, name: 'Compiler supports SEE intrinsics', args: intrin_args)
  59. has_sse = true
  60. endif
  61. # Mimicing the logic in win32/config.h
  62. if cc.get_id() == 'msvc' and host_cpu_family == 'x86'
  63. m_ix86_fp = cc.get_define('_M_IX86_FP')
  64. if m_ix86_fp == '' or m_ix86_fp.to_int() < 1
  65. has_sse = false
  66. endif
  67. endif
  68. endif
  69. # Visual Studio supports alloca(), but it always aligns variables to 16-bit
  70. # boundary, while SSE needs 128-bit alignment. So we disable alloca() when
  71. # SSE is enabled (from win32/config.h)
  72. allow_alloca = not (cc.get_id() == 'msvc' and has_sse)
  73. use_alloca = false
  74. if allow_alloca
  75. alloca_check = 'int main (int n) { char * array = alloca(n); }'
  76. if cc.has_header('alloca.h')
  77. cdata.set('HAVE_ALLOCA_H', true)
  78. if cc.links('#include <alloca.h>\n' + alloca_check, name: 'alloca (alloca.h)')
  79. use_alloca = true
  80. endif
  81. endif
  82. if cc.links('#include <malloc.h>\n#include <stdlib.h>\n' + alloca_check, name: 'alloca (malloc.h)')
  83. use_alloca = true
  84. endif
  85. endif
  86. cdata.set('USE_ALLOCA', use_alloca)
  87. if cc.get_id() != 'msvc' and cc.has_argument('-fvisibility=hidden')
  88. add_project_arguments('-fvisibility=hidden', language: 'c')
  89. cdata.set('EXPORT', '__attribute__((visibility("default")))')
  90. else
  91. cdata.set('EXPORT', '/* */')
  92. endif
  93. # FFT implementation
  94. fft_dep = []
  95. use_fixed_point = get_option('fixed-point').enabled()
  96. if use_fixed_point
  97. default_fft = 'kiss'
  98. has_sse = false
  99. cdata.set('FIXED_POINT', true)
  100. else
  101. default_fft = 'smallft'
  102. cdata.set('FLOATING_POINT', true)
  103. endif
  104. fft_opt = get_option('fft')
  105. if fft_opt == 'auto'
  106. fft_used = default_fft
  107. elif fft_opt == 'kiss'
  108. fft_used = 'kiss'
  109. elif fft_opt == 'smallft'
  110. fft_used = 'smallft'
  111. elif fft_opt == 'gpl-fftw3'
  112. fft_used = 'gpl-fftw3'
  113. fft_dep = dependency('fftw3f', required: true)
  114. elif fft_opt == 'proprietary-intel-mkl'
  115. error('FIXME: add support for proprietary-intel-mkl FFT')
  116. else
  117. error('Unexpected FFT option', fft_opt)
  118. endif
  119. if not has_sse and get_option('sse').enabled()
  120. error('No SSE support, but SSE support required via options')
  121. endif
  122. cdata.set('_USE_SSE', has_sse)
  123. opt_arm4_asm = get_option('arm4-asm').enabled()
  124. opt_arm5e_asm = get_option('arm5e-asm').enabled()
  125. opt_blackfin_asm = get_option('blackfin-asm').enabled()
  126. # opt_ti_c55x = get_option('ti-c55x').enabled()
  127. cdata.set('ARM4_ASM', opt_arm4_asm)
  128. cdata.set('ARM5E_ASM', opt_arm5e_asm)
  129. cdata.set('BFIN_ASM', opt_blackfin_asm)
  130. # cdata.set('TI_C55X', opt_ti_c55x) # has_char16=yes
  131. opt_disable_vbr = get_option('vbr').disabled()
  132. opt_disable_float_api = get_option('float-api').disabled()
  133. opt_fixed_point_debug = get_option('fixed-point-debug').enabled()
  134. opt_valgrind = get_option('valgrind').enabled()
  135. opt_vorbis_psy = get_option('vorbis-psy').enabled()
  136. cdata.set('DISABLE_VBR', opt_disable_vbr)
  137. cdata.set('DISABLE_FLOAT_API', opt_disable_float_api)
  138. cdata.set('FIXED_POINT_DEBUG', opt_fixed_point_debug)
  139. cdata.set('ENABLE_VALGRIND', opt_valgrind)
  140. subdir('doc')
  141. subdir('include/speex')
  142. subdir('libspeex')
  143. if not get_option('tools').disabled()
  144. subdir('src')
  145. endif
  146. # config.h
  147. configure_file(output: 'config.h', configuration: cdata)
  148. # summary
  149. building_speex_tools = get_variable('building_speex_tools', false)
  150. opt_disable_vbr = get_option('vbr').disabled()
  151. opt_disable_float_api = get_option('float-api').disabled()
  152. opt_fixed_point_debug = get_option('fixed-point-debug').enabled()
  153. opt_valgrind = get_option('valgrind').enabled()
  154. asms = {
  155. 'has_sse': 'SSE',
  156. 'opt_arm4_asm': 'ARM4 assembly',
  157. 'opt_arm5e_asm': 'ARMv5e assembly',
  158. 'opt_blackfin_asm': 'Blackfin assembly',
  159. 'opt_ti_c55x': 'TI C55X DSP',
  160. }
  161. optimizations = []
  162. foreach var, desc : asms
  163. if get_variable(var, false)
  164. optimizations += [desc]
  165. endif
  166. endforeach
  167. summary(
  168. {
  169. 'Assembly optimizations': optimizations.length() > 0 ? optimizations : false,
  170. 'Floating point support': not use_fixed_point,
  171. 'Fixed point debugging': use_fixed_point ? opt_fixed_point_debug : 'N/A',
  172. 'Float API': not opt_disable_float_api,
  173. 'FFT': fft_used,
  174. 'VBR + VAD support': not opt_disable_vbr,
  175. 'Vorbis psy model': opt_vorbis_psy,
  176. 'Tools': building_speex_tools,
  177. },
  178. bool_yn: true,
  179. list_sep: ', ',
  180. )