1project ('orc', 'c', version : '0.4.31',
2                     meson_version : '>= 0.47.0',
3                     default_options : ['buildtype=debugoptimized',
4                                        'warning_level=1',
5                                        'c_std=gnu99'] )
6
7orc_api = '0.4'
8orc_version_major = meson.project_version().split('.')[0]
9orc_version_minor = meson.project_version().split('.')[1]
10orc_version_micro = meson.project_version().split('.')[2]
11
12# maintaining compatibility with the previous libtool versioning
13soversion = 0
14curversion = orc_version_micro.to_int()
15libversion = '@0@.@1@.0'.format(soversion, curversion)
16osxversion = curversion + 1
17
18add_project_arguments('-DHAVE_CONFIG_H', language : 'c')
19
20orc_inc = include_directories('.')
21
22cc = meson.get_compiler('c')
23
24cdata = configuration_data()      # config.h
25pc_conf = configuration_data()    # orc.pc
26
27# -Bsymbolic-functions
28if meson.version().version_compare('>= 0.46.0')
29  if cc.has_link_argument('-Wl,-Bsymbolic-functions')
30    add_project_link_arguments('-Wl,-Bsymbolic-functions', language : 'c')
31  endif
32endif
33
34# Symbol visibility
35if cc.get_id() == 'msvc'
36  export_define = '__declspec(dllexport) extern'
37elif cc.has_argument('-fvisibility=hidden')
38  add_project_arguments('-fvisibility=hidden', language: 'c')
39  export_define = 'extern __attribute__ ((visibility ("default")))'
40else
41  export_define = 'extern'
42endif
43# Passing this through the command line would be too messy
44cdata.set('ORC_API_EXPORT', export_define)
45
46all_backends = ['sse', 'mmx', 'altivec', 'neon', 'mips', 'c64x'] # 'arm'
47
48backend = get_option('orc-backend')
49foreach b : all_backends
50  if backend == 'all' or backend == b
51    cdata.set('ENABLE_BACKEND_' + b.to_upper(), 1)
52  endif
53endforeach
54
55cpu_family = host_machine.cpu_family()
56if cpu_family == 'x86'
57  cdata.set('HAVE_I386', true)
58elif cpu_family == 'x86_64'
59  cdata.set('HAVE_AMD64', true)
60elif cpu_family == 'ppc' or cpu_family == 'ppc64'
61  cdata.set('HAVE_POWERPC', true)
62elif cpu_family == 'arm'
63  cdata.set('HAVE_ARM', true)
64elif cpu_family == 'mips' and host_machine.endian() == 'little'
65  cdata.set('HAVE_MIPSEL', true)
66else
67  warning(cpu_family + ' isn\'t a supported cpu family for optimization')
68endif
69
70libm = cc.find_library('m', required : false)
71
72librt = []
73pc_conf.set('LIBRT', '')
74if cc.has_function('clock_gettime')
75  cdata.set('HAVE_CLOCK_GETTIME', true)
76else
77  # On glibc older than 2.17, clock_gettime is provided by time.h and -lrt
78  librt = cc.find_library('rt', required : false)
79  if librt.found() and cc.has_function('clock_gettime', dependencies : librt)
80    pc_conf.set('LIBRT', '-lrt')
81  endif
82endif
83
84liblog = []
85if cc.has_header_symbol('android/log.h', '__android_log_print')
86  cdata.set('HAVE_ANDROID_LIBLOG', true)
87  liblog = [cc.find_library('log', required : true)]
88endif
89
90host_os = host_machine.system()
91if host_os == 'windows'
92  cdata.set('HAVE_CODEMEM_VIRTUALALLOC', true)
93  cdata.set('HAVE_OS_WIN32', true)
94  cdata.set('HAVE_THREAD_WIN32', true)
95  pc_conf.set('EXEEXT', '.exe')
96  pc_conf.set('PTHREAD_LIBS', '')
97else
98  # If it is not windows, we just assume it is a unix of sorts for now.
99  cdata.set('HAVE_CODEMEM_MMAP', true)
100  cdata.set('HAVE_THREAD_PTHREAD', true)
101  pc_conf.set('EXEEXT', '')
102  if host_os == 'android'
103    pc_conf.set('PTHREAD_LIBS', '')
104  else
105    pc_conf.set('PTHREAD_LIBS', '-lpthread')
106  endif
107endif
108
109monotonic_test = '''
110#include <time.h>
111#include <unistd.h>
112int main() {
113  #if !(defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 && defined(CLOCK_MONOTONIC))
114  #error No monotonic clock
115  #endif
116  return 0;
117}
118'''
119cdata.set('HAVE_MONOTONIC_CLOCK', cc.compiles(monotonic_test))
120cdata.set('HAVE_GETTIMEOFDAY', cc.has_function('gettimeofday'))
121cdata.set('HAVE_POSIX_MEMALIGN', cc.has_function('posix_memalign', prefix : '#include <stdlib.h>'))
122cdata.set('HAVE_MMAP', cc.has_function('mmap'))
123
124cdata.set('HAVE_SYS_TIME_H', cc.has_header('sys/time.h'))
125cdata.set('HAVE_UNISTD_H', cc.has_header('unistd.h'))
126cdata.set('HAVE_VALGRIND_VALGRIND_H', cc.has_header('valgrind/valgrind.h'))
127
128cdata.set_quoted('PACKAGE_VERSION', meson.project_version())
129cdata.set_quoted('VERSION', meson.project_version())
130
131subdir('orc')
132
133opt_examples = get_option('examples')
134opt_orctest = get_option('orc-test')
135opt_tests = get_option('tests')
136opt_tools = get_option('tools')
137
138if not opt_orctest.disabled()
139  subdir('orc-test')
140else
141  if opt_tests.enabled()
142    error('Tests were enabled explicitly, but the orc-test library was disabled.')
143  endif
144  orc_test_dep = disabler() # for testsuites + orc-bugreport
145endif
146
147if not opt_tools.disabled()
148  subdir('tools')
149else
150  orcc = disabler() # for testsuite/orcc/
151endif
152
153if not opt_examples.disabled()
154  subdir('examples')
155endif
156
157if not opt_tests.disabled()
158  subdir('testsuite')
159endif
160
161if build_machine.system() == 'windows'
162  message('Disabling gtk-doc while building on Windows')
163else
164  if find_program('gtkdoc-scan', required : get_option('gtk_doc')).found()
165    subdir('doc')
166  else
167    message('Not building documentation as gtk-doc was not found')
168  endif
169endif
170
171# FIXME: use pkg-config module
172pc_conf.set('prefix', get_option('prefix'))
173pc_conf.set('exec_prefix', get_option('prefix'))
174pc_conf.set('libdir', join_paths(get_option('prefix'), get_option('libdir')))
175pc_conf.set('includedir', join_paths(get_option('prefix'), 'include'))
176pc_conf.set('VERSION', meson.project_version())
177pc_conf.set('ORC_MAJORMINOR', orc_api)
178pc_conf.set('LIBM', libm.found() ? '-lm' : '')
179
180pkgconfigdir = join_paths (get_option('libdir'), 'pkgconfig')
181configure_file(input : 'orc.pc.in',
182  output : 'orc-' + orc_api + '.pc',
183  configuration : pc_conf,
184  install_dir : pkgconfigdir)
185
186# Install m4 macro that other projects use
187install_data('orc.m4', install_dir : 'share/aclocal')
188
189configure_file(output : 'config.h', configuration : cdata)
190