summaryrefslogtreecommitdiff
path: root/meson.build
blob: 3daa27a2dafeb32dae6239a2efc595b759b14490 (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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
project('libsoup', 'c',
        version: '2.63.92',
        meson_version : '>=0.43',
        license : 'LGPL2',
        default_options : 'c_std=c89')

gnome = import('gnome')
cc = meson.get_compiler('c')

soup_version = meson.project_version()
version_arr = soup_version.split('.')
soup_version_major = version_arr[0]
soup_version_minor = version_arr[1]
soup_version_micro = version_arr[2]

libversion = '1.8.0'
apiversion = '2.4'
soversion = '0'
libsoup_api_name = '@0@-@1@'.format(meson.project_name(), apiversion)

host_system = host_machine.system()

common_flags = [
  '-DHAVE_CONFIG_H',
]

# Enable extra warnings if compiler supports them.
if cc.get_id() == 'msvc'
  common_flags += ['/FImsvc_recommended_pragmas.h']
else
  test_cflags = [
      '-Wall',
      '-Wmissing-include-dirs',
      '-Wpointer-arith',
      '-Winit-self',
      '-Wdeclaration-after-statement',
      '-Werror=missing-prototypes',
      '-Werror=implicit-function-declaration',
      '-Werror=aggregate-return',
      '-Werror=format=2',
      '-Wstrict-prototypes',
      '-Wno-format-zero-length',
  ]

  common_flags += cc.get_supported_arguments(test_cflags)
endif

add_project_arguments(common_flags, language : 'c')

glib_required_version = '>= 2.38'
glib_dep = [dependency('glib-2.0', version : glib_required_version),
            dependency('gobject-2.0', version : glib_required_version),
            dependency('gio-2.0', version : glib_required_version)]

sqlite_dep = dependency('sqlite3', required: cc.get_id() != 'msvc')

# Fallback check for sqlite on Visual Studio, which normally does not
# generate a pkg-config file upon a successful build
if not sqlite_dep.found()
  cc.has_header('sqlite3.h')
  cc.has_header('sqlite3ext.h')
  sqlite_dep = cc.find_library('sqlite3')
endif

libxml_dep = dependency('libxml-2.0', required: cc.get_id() != 'msvc')

# Fallback check for libxml2 on Visual Studio, which normally does not
# generate a pkg-config file upon a successful build
if not libxml_dep.found()
  # Note: The XML include dir needs to be within the INCLUDE envvar,
  # such as <INCLUDEDIR>\libxml2
  cc.has_header('libxml/tree.h')
  libxml2_dep = cc.find_library('libxml2')
endif

cdata = configuration_data()

platform_deps = []
if host_machine.system() == 'windows'
  platform_deps = [cc.find_library('ws2_32')]
  cdata.set('_SOUP_EXTERN', '__declspec(dllexport)')
  cdata.set('DLL_EXPORT', 1)
endif

libpsl_required_version = '>= 0.20'
libpsl_dep = dependency('libpsl', version : libpsl_required_version)

###################
# GIO TLS support #
###################
enable_tls_check = get_option('tls_check')
if enable_tls_check
  check_gio_tls_src = '''#include <gio/gio.h>
  int main(void) {
    return !g_tls_backend_supports_tls (g_tls_backend_get_default ());
  }
  '''

  assert(cc.compiles(check_gio_tls_src, name : 'GIO has real TLS support', dependencies : glib_dep),
         'libsoup requires glib-networking or glib-openssl for TLS support')
endif

#################################
# Regression tests dependencies #
#################################
# This abomination is a result of https://github.com/mesonbuild/meson/issues/1576
apache_httpd2 = find_program('httpd2', 'httpd', 'apache2', 'apache',
	      '/sbin/httpd2', '/sbin/httpd', '/sbin/apache2', '/sbin/apache',
	      '/usr/sbin/httpd2', '/usr/sbin/httpd', '/usr/sbin/apache2', '/usr/sbin/apache',
	      required : false)
have_apache=false
apache_httpd2_version = ''
if apache_httpd2.found()
  apache_httpd2_version_raw = run_command(apache_httpd2.path(), '-v')
  if apache_httpd2_version_raw.returncode() == 0
    apache_httpd2_version = apache_httpd2_version_raw.stdout().split('\n')[0]
    apache_httpd2_version = apache_httpd2_version.split('/')[1].split(' ')[0]
    if apache_httpd2_version.version_compare('>=2.4')
      have_apache = true
      cdata.set_quoted('APACHE_HTTPD', apache_httpd2.path())
    else
      message('Found ' + apache_httpd2_version + ', but at least 2.4 is needed - ignoring')
    endif
  endif
endif

if have_apache
  apache_module_dirs_out = run_command('get_apache_module_dirs.py', apache_httpd2.path())
  have_apache = (apache_module_dirs_out.returncode() == 0)
  if have_apache
    apache_module_dirs = apache_module_dirs_out.stdout().split(':')
    message('Apache module directory: ' + apache_module_dirs[0])
    cdata.set('APACHE_MODULE_DIR', apache_module_dirs[0])
    cdata.set('APACHE_SSL_MODULE_DIR', apache_module_dirs[1])
    cdata.set('APACHE_PHP_MODULE_DIR', apache_module_dirs[2])
    apache_mod_unixd = run_command('test', '-f', join_paths(apache_module_dirs[0], 'mod_unixd.so'))
    cdata.set('IF_HAVE_MOD_UNIXD', apache_mod_unixd.returncode() == 0 ? '' : '#')
    cdata.set('HAVE_APACHE', have_apache)
  endif
endif

have_php = false
have_php_xmlrpc = false
if have_apache
  php = find_program('php', required : false)
  apache_php_module = run_command('test', '-d', cdata.get('APACHE_PHP_MODULE_DIR'))
  if apache_php_module.returncode() == 0
    have_php = true
    php_xmlrpc = run_command(php, '-d', 'extension=xmlrpc', '-r', 'exit(function_exists("xmlrpc_server_create")?0:1);')
    if php_xmlrpc.returncode() == 0
      message('php-xmlrpc found')
      have_php_xmlrpc = true
      cdata.set('HAVE_PHP_XMLRPC', '1')
    else
      message('php-xmlrpc not found')
    endif
  endif
  cdata.set('IF_HAVE_PHP', have_php ? '' : '#')
  cdata.set('IF_HAVE_PHP_XMLRPC', have_php_xmlrpc ? '' : ';')
endif

cdata.set('HAVE_CURL', find_program('curl', required : false).found())

##################
# GSSAPI support #
##################
enable_gssapi = get_option('gssapi')
if enable_gssapi
  if cc.get_id() == 'msvc'
    if host_machine.cpu_family() == 'x86'
      gssapi_lib_type = '32'
    else
      gssapi_lib_type = '64'
    endif
    if cc.has_header('gssapi/gssapi.h', required: false)
      gssapi_lib = cc.find_library('gssapi' + gssapi_lib_type, required: false)
      assert(gssapi_lib.found(), 'GSSAPI support requested, but the MIT Kerberos 5 headers and libraries are not found')
      add_project_link_arguments('gssapi@0@.lib'.format(gssapi_lib_type), language : 'c')
    endif
  else
    krb5_config_option = get_option('krb5_config')

    krb5_config_path = krb5_config_option != '' ? krb5_config_option : 'krb5-config'
    krb5_config = find_program(krb5_config_path, required : false)

    assert(krb5_config.found(), 'GSSAPI support requested, but krb5-config not found. Please specify its path with -Dkrb5-config=PATH')

    krb5_config_output = run_command (krb5_config, '--libs', 'gssapi')
    assert(krb5_config_output.returncode() == 0, 'Failed to obtain cflags for GSSAPI from krb5-config')
    add_project_link_arguments(krb5_config_output.stdout().split(), language : 'c')

    krb5_config_output = run_command (krb5_config, '--cflags', 'gssapi')
    assert(krb5_config_output.returncode() == 0, 'Failed to obtain cflags for GSSAPI from krb5-config')
    add_project_arguments(krb5_config_output.stdout().split(), language : 'c')
  endif

  if enable_gssapi
    add_project_arguments('-DLIBSOUP_HAVE_GSSAPI=1', language : 'c')
  endif
endif

################
# NTLM support #
################
# NTLM not supported on Windows
if host_machine.system() != 'windows'
  enable_ntlm = get_option('ntlm')
  if enable_ntlm
    ntlm_auth = find_program(get_option('ntlm_auth'), required: false)

    if ntlm_auth.found()
      add_project_arguments('-DUSE_NTLM_AUTH=1', language : 'c')
      add_project_arguments('-DNTLM_AUTH=' + ntlm_auth.path(), language : 'c')
    endif
  endif
endif

#################
# GNOME support #
#################
enable_gnome = get_option('gnome') and host_machine.system() != 'windows'

#########################
# GObject introspection #
#########################
enable_introspection = get_option('introspection') and find_program('g-ir-scanner', required: false).found() and not meson.is_cross_build()

############
# Vala API #
############
enable_vapi = get_option('vapi')
if enable_vapi
  assert(enable_introspection, 'vapi support was requested, but introspection support is mandatory.')
  assert(add_languages('vala', required: false), 'vapi support was requested, but vala not found.')
endif

configinc = include_directories('.')

prefix = get_option('prefix')

cdata.set_quoted('PACKAGE_VERSION', soup_version)
cdata.set_quoted('LOCALEDIR', join_paths(prefix, get_option('localedir')))
cdata.set_quoted('GETTEXT_PACKAGE', libsoup_api_name)
configure_file(output : 'config.h', configuration : cdata)

subdir('libsoup')
subdir('po')
subdir('examples')

if get_option('tests')
  subdir('tests')
 endif

if get_option('doc')
  subdir('docs/reference')
endif