summaryrefslogtreecommitdiff
path: root/meson.build
blob: b1901d34b78a047adf9f2d07e96c5866d193a90e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
project ('orc', 'c', version : '0.4.33.1',
                     meson_version : '>= 0.55.0',
                     default_options : ['buildtype=debugoptimized',
                                        'warning_level=1'] )

orc_api = '0.4'
orc_version_major = meson.project_version().split('.')[0]
orc_version_minor = meson.project_version().split('.')[1]
orc_version_micro = meson.project_version().split('.')[2]

# maintaining compatibility with the previous libtool versioning
soversion = 0
curversion = orc_version_micro.to_int()
libversion = '@0@.@1@.0'.format(soversion, curversion)
osxversion = curversion + 1

add_project_arguments('-DHAVE_CONFIG_H', language : 'c')

orc_inc = include_directories('.')

cc = meson.get_compiler('c')

cdata = configuration_data()      # config.h

pkg = import('pkgconfig')

# -Bsymbolic-functions
if cc.has_link_argument('-Wl,-Bsymbolic-functions')
  add_project_link_arguments('-Wl,-Bsymbolic-functions', language : 'c')
endif

# Symbol visibility
if cc.get_id() == 'msvc'
  export_define = '__declspec(dllexport) extern'
elif cc.has_argument('-fvisibility=hidden')
  add_project_arguments('-fvisibility=hidden', language: 'c')
  export_define = 'extern __attribute__ ((visibility ("default")))'
else
  export_define = 'extern'
endif
# Passing this through the command line would be too messy
cdata.set('ORC_API_EXPORT', export_define)

all_backends = ['sse', 'mmx']
extra_backends = ['altivec', 'neon', 'mips', 'c64x'] # 'arm'
enabled_backends = []

host_system = host_machine.system()
if host_system != 'windows'
  all_backends += extra_backends
endif

backend = get_option('orc-backend')
foreach b : all_backends
  if backend == 'all' or backend == b
    cdata.set('ENABLE_BACKEND_' + b.to_upper(), 1)
    enabled_backends += [b]
  endif
endforeach

cpu_family = host_machine.cpu_family()
if cpu_family == 'x86'
  cdata.set('HAVE_I386', true)
elif cpu_family == 'x86_64'
  cdata.set('HAVE_AMD64', true)
elif cpu_family == 'ppc' or cpu_family == 'ppc64'
  cdata.set('HAVE_POWERPC', true)
# TODO: Windows ARM device is not tested
elif cpu_family == 'arm' and host_system != 'windows'
  cdata.set('HAVE_ARM', true)
# TODO: Add support for Windows
# https://gitlab.freedesktop.org/gstreamer/orc/-/issues/38
elif cpu_family == 'aarch64' and host_system != 'windows'
  cdata.set('HAVE_AARCH64', true)
elif cpu_family == 'mips' and host_machine.endian() == 'little'
  cdata.set('HAVE_MIPSEL', true)
else
  warning(cpu_family + ' with ' + host_system + ' isn\'t a supported configuration for optimization')
endif

threads = dependency('threads')

libm = cc.find_library('m', required : false)

librt = []
if cc.has_function('clock_gettime')
  cdata.set('HAVE_CLOCK_GETTIME', true)
else
  # On glibc older than 2.17, clock_gettime is provided by time.h and -lrt
  librt = cc.find_library('rt', required : false)
endif

liblog = []
if cc.has_header_symbol('android/log.h', '__android_log_print')
  cdata.set('HAVE_ANDROID_LIBLOG', true)
  liblog = [cc.find_library('log', required : true)]
endif

host_os = host_machine.system()
if host_os == 'windows'
  cdata.set('HAVE_CODEMEM_VIRTUALALLOC', true)
  cdata.set('HAVE_OS_WIN32', true)
  cdata.set('HAVE_THREAD_WIN32', true)

  code = '''
  #include <windows.h>
  #if !(WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP))
  #error "Not building for UWP"
  #endif'''
  if cc.compiles(code, name : 'building for UWP')
    cdata.set('ORC_WINAPI_ONLY_APP', true)
  endif
else
  # If it is not windows, we just assume it is a unix of sorts for now.
  cdata.set('HAVE_CODEMEM_MMAP', true)
  cdata.set('HAVE_THREAD_PTHREAD', true)
endif

monotonic_test = '''
#include <time.h>
#include <unistd.h>
int main() {
  #if !(defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 && defined(CLOCK_MONOTONIC))
  #error No monotonic clock
  #endif
  return 0;
}
'''
cdata.set('HAVE_MONOTONIC_CLOCK', cc.compiles(monotonic_test))
cdata.set('HAVE_GETTIMEOFDAY', cc.has_function('gettimeofday'))
cdata.set('HAVE_POSIX_MEMALIGN', cc.has_function('posix_memalign', prefix : '#include <stdlib.h>'))
cdata.set('HAVE_MMAP', cc.has_function('mmap'))
cdata.set('HAVE_SYS_TIME_H', cc.has_header('sys/time.h'))
cdata.set('HAVE_UNISTD_H', cc.has_header('unistd.h'))
cdata.set('HAVE_VALGRIND_VALGRIND_H', cc.has_header('valgrind/valgrind.h'))

cdata.set_quoted('PACKAGE_VERSION', meson.project_version())
cdata.set_quoted('VERSION', meson.project_version())

subdir('orc')

opt_benchmarks = get_option('benchmarks')
opt_examples = get_option('examples')
opt_orctest = get_option('orc-test')
opt_tests = get_option('tests')
opt_tools = get_option('tools')

if not opt_orctest.disabled()
  subdir('orc-test')
else
  if opt_tests.enabled()
    error('Tests were enabled explicitly, but the orc-test library was disabled.')
  endif
  orc_test_dep = disabler() # for testsuites + orc-bugreport
endif

if not opt_tools.disabled()
  subdir('tools')
else
  orcc = disabler() # for testsuite/orcc/
  tools_variables = []
endif

if not opt_examples.disabled()
  subdir('examples')
endif

if not opt_tests.disabled()
  subdir('testsuite')
endif

have_docs = false
if build_machine.system() == 'windows'
  message('Disabling gtk-doc while building on Windows')
  gtk_doc_disabled_reason = 'disabled on windows'
else
  if find_program('gtkdoc-scan', required : get_option('gtk_doc')).found()
    subdir('doc')
    have_docs = true
    gtk_doc_disabled_reason = ''
  elif get_option('gtk_doc').disabled()
    message('Not building documentation (disabled)')
    gtk_doc_disabled_reason = 'disabled'
  else
    message('Not building documentation as gtk-doc was not found')
    gtk_doc_disabled_reason = 'gtk-doc not found'
  endif
endif

pkg.generate (orc_lib,
  subdirs : 'orc-' + orc_api,
  description : 'Library of Optimized Inner Loops Runtime Compiler',
  variables : tools_variables,
  extra_cflags: orc_dep_cargs,
  libraries_private : orc_dependencies)

# Install m4 macro that other projects use
install_data('orc.m4', install_dir : 'share/aclocal')

configure_file(output : 'config.h', configuration : cdata)

# summary
summary({
  'SSE': 'sse' in enabled_backends,
  'MMX': 'mmx' in enabled_backends,
  'NEON': 'neon' in enabled_backends,
  'MIPS': 'mips' in enabled_backends,
  'c64x': 'c64x' in enabled_backends,
  'Altivec': 'altivec' in enabled_backends,
  }, section: 'Backends', bool_yn: true)

if not have_docs
  doc_summary = [have_docs, gtk_doc_disabled_reason]
else
  doc_summary = have_docs
endif

summary({
  'Tools': not opt_tools.disabled(),
  'Tests': not opt_tests.disabled(),
  'Examples': not opt_examples.disabled(),
  'Benchmarks': not opt_benchmarks.disabled(),
  'Documentation': doc_summary,
  'Orc-test library': not opt_orctest.disabled(),
  }, section: 'Build options', bool_yn: true, list_sep: '  ')