meson.build 12.8 KB
Newer Older
1
project('gdk-pixbuf', 'c',
Matthias Clasen's avatar
Matthias Clasen committed
2
        version: '2.36.12',
3 4 5 6 7 8
        license: 'LGPLv2.1+',
        default_options: [
          'buildtype=debugoptimized',
          'warning_level=1',
          'c_std=c99',
        ],
9
        meson_version: '>= 0.45.0')
10

11
add_project_arguments([ '-D_POSIX_C_SOURCE=200809L', '-D_DEFAULT_SOURCE', '-D_XOPEN_SOURCE' ], language: 'c')
12 13 14 15 16 17 18 19 20 21 22 23 24 25

cc = meson.get_compiler('c')
host_system = host_machine.system()

# Versioning
gdk_pixbuf_version = meson.project_version()
version_arr = gdk_pixbuf_version.split('.')
gdk_pixbuf_version_major = version_arr[0].to_int()
gdk_pixbuf_version_minor = version_arr[1].to_int()
gdk_pixbuf_version_micro = version_arr[2].to_int()

gdk_pixbuf_api_version = '2.0'
gdk_pixbuf_binary_version = '2.10.0'

26 27
gdk_pixbuf_api_name = '@0@-@1@'.format(meson.project_name(), gdk_pixbuf_api_version)

28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
if gdk_pixbuf_version_minor.is_odd()
  gdk_pixbuf_interface_age = 0
else
  gdk_pixbuf_interface_age = gdk_pixbuf_version_micro
endif

gdk_pixbuf_binary_age = 100 * gdk_pixbuf_version_minor + gdk_pixbuf_version_micro

# maintaining compatibility with the previous libtool versioning
# current = binary - interface
# revision = interface
soversion = 0
current = gdk_pixbuf_binary_age - gdk_pixbuf_interface_age
revision = gdk_pixbuf_interface_age
libversion = '@0@.@1@.@2@'.format(soversion, current, revision)
43 44
age = gdk_pixbuf_binary_age - gdk_pixbuf_interface_age
current_minus_age = current - age
45 46 47 48

# Paths
gdk_pixbuf_prefix = get_option('prefix')
gdk_pixbuf_libdir = join_paths(gdk_pixbuf_prefix, get_option('libdir'))
49
gdk_pixbuf_bindir = join_paths(gdk_pixbuf_prefix, get_option('bindir'))
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
gdk_pixbuf_includedir = join_paths(gdk_pixbuf_prefix, get_option('includedir'))
gdk_pixbuf_datadir = join_paths(gdk_pixbuf_prefix, get_option('datadir'))
gdk_pixbuf_mandir = join_paths(gdk_pixbuf_prefix, get_option('mandir'))
gdk_pixbuf_localedir = join_paths(gdk_pixbuf_prefix, get_option('localedir'))
gdk_pixbuf_libexecdir = join_paths(gdk_pixbuf_prefix, get_option('libexecdir'))
gdk_pixbuf_loaderdir = join_paths(gdk_pixbuf_libdir, 'gdk-pixbuf-@0@/@1@/loaders'.format(gdk_pixbuf_api_version, gdk_pixbuf_binary_version))

# Dependencies
glib_req_version = '>= 2.38.0'
gio_dep = dependency('gio-2.0', version: glib_req_version)

# Configurations
gdk_pixbuf_conf = configuration_data()

check_headers = [
65
  'unistd.h',
66 67
  'sys/resource.h',
  'sys/time.h'
68 69 70 71 72 73 74 75
]

foreach h: check_headers
  if cc.has_header(h)
    gdk_pixbuf_conf.set('HAVE_' + h.underscorify().to_upper(), 1)
  endif
endforeach

76 77 78 79 80 81 82 83 84 85 86 87 88
# Look for the math library first, since we use it to test for round() and lrint()
mathlib_dep = cc.find_library('m', required: false)

# XXX: Remove the checks for round() and lrint() once GDK-Pixbuf is declared C99
if cc.has_function('round', dependencies: mathlib_dep)
  gdk_pixbuf_conf.set('HAVE_ROUND', 1)
endif

if cc.has_function('lrint', dependencies: mathlib_dep)
  gdk_pixbuf_conf.set('HAVE_LRINT', 1)
endif


89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
# We use links() because sigsetjmp() is often a macro hidden behind other macros
gdk_pixbuf_conf.set('HAVE_SIGSETJMP',
                    cc.links('''#define _POSIX_SOURCE
                                #include <setjmp.h>
                                int main (void) {
                                  sigjmp_buf env;
                                  sigsetjmp (env, 0);
                                  return 0;
                                }''', name: 'sigsetjmp'))

# Common compiler and linker flags
common_cflags = []
common_ldflags = []

if cc.get_id() == 'msvc'
104 105 106 107
  # For Visual Studio, just force-include msvc_reommended_pragmas.h
  # so that we silence unwanted noise and track potential issues
  test_cflags = []
  add_project_arguments([ '-FImsvc_recommended_pragmas.h' ], language: 'c')
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
elif cc.get_id() == 'gcc' or cc.get_id() == 'clang'
  test_cflags = [
    '-Wpointer-arith',
    '-Wformat=2',
    '-Wstrict-prototypes',
    '-Wnested-externs',
    '-Wold-style-definition',
    '-Wdeclaration-after-statement',
    '-Wunused',
    '-Wcast-align',
    '-Wmissing-noreturn',
    '-Wmissing-format-attribute',
    '-Wlogical-op',
    '-fno-strict-aliasing',
    '-Wno-int-conversion',
    '-Wno-uninitialized',
    '-Wno-discarded-qualifiers',
    '-Werror=implicit',
    '-Werror=nonnull',
    '-Werror=init-self',
    '-Werror=main',
    '-Werror=missing-braces',
    '-Werror=sequence-point',
    '-Werror=return-type',
    '-Werror=trigraphs',
    '-Werror=array-bounds',
    '-Werror=write-strings',
    '-Werror=address',
    '-Werror=int-to-pointer-cast',
    '-Werror=pointer-to-int-cast',
    '-Werror=empty-body',
  ]

  # Ensure we have the correct bit packing on Windows
  if host_system == 'windows'
    test_cflags += '-mms-bitfields'
  endif
else
  test_cflags = []
endif

# Symbol visibility
if get_option('default_library') != 'static'
  if host_system == 'windows'
    gdk_pixbuf_conf.set('DLL_EXPORT', true)
    gdk_pixbuf_conf.set('_GDK_PIXBUF_EXTERN', '__declspec(dllexport) extern')
    if cc.get_id() != 'msvc'
      test_cflags += ['-fvisibility=hidden']
    endif
  else
    gdk_pixbuf_conf.set('_GDK_PIXBUF_EXTERN', '__attribute__((visibility("default"))) extern')
    test_cflags += ['-fvisibility=hidden']
  endif
endif

163
common_cflags += cc.get_supported_arguments(test_cflags)
164 165 166

# Linker flags
if host_machine.system() == 'linux'
167 168 169 170 171 172
  test_ldflags = ['-Wl,-Bsymbolic', '-Wl,-z,relro', '-Wl,-z,now']
  if meson.version().version_compare('>= 0.46.0')
    common_ldflags += cc.get_supported_link_arguments(test_ldflags)
  else
    common_ldflags += test_ldflags
  endif
173 174 175 176 177 178 179 180 181 182 183 184
endif

# Maintain compatibility with autotools on macOS
if host_machine.system() == 'darwin'
  common_ldflags += [ '-compatibility_version 1', '-current_version 1.0', ]
endif

# Dependencies
gobject_dep = dependency('gobject-2.0', version: glib_req_version)
gmodule_dep = dependency('gmodule-no-export-2.0')
gio_dep = dependency('gio-2.0')

185 186
# On non-Windows/macOS systems we always required shared-mime-info and GIO
if host_system != 'windows' and host_system != 'darwin'
187 188 189 190 191 192
  shared_mime_dep = dependency('shared-mime-info')
  gdk_pixbuf_conf.set('GDK_PIXBUF_USE_GIO_MIME', 1)
else
  shared_mime_dep = []
endif

193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
# Check if medialib is available
medialib_dep = cc.find_library('mlib', required: false)
if medialib_dep.found()
  if cc.has_function('mlib_ImageSetStruct', dependencies: medialib_dep)
    gdk_pixbuf_conf.set('USE_MEDIALIB', 1)

    if cc.has_function('mlib_VideoColorRGBint_to_BGRAint', dependencies: medialib_dep)
      gdk_pixbuf_conf.set('USE_MEDIALIB25', 1)
    endif
  else
    medialib_dep = []
  endif
endif

gdk_pixbuf_deps = [ mathlib_dep, gobject_dep, gmodule_dep, gio_dep, shared_mime_dep, medialib_dep ]
208 209 210 211 212 213 214 215

# Check if we can build shared modules
build_modules = gmodule_dep.get_pkgconfig_variable('gmodule_supported') == 'true'
gdk_pixbuf_conf.set10('USE_GMODULE', build_modules)

# Check which loaders should be built into gdk-pixbuf
builtin_loaders = get_option('builtin_loaders').split(',')

216 217 218 219 220 221 222
# If 'all' is specified for builtin_loaders, build all
# buildable loaders into gdk-pixbuf
builtin_all_loaders = false
if builtin_loaders == [ 'all' ]
  builtin_all_loaders = true
endif

223 224 225 226
# Loader dependencies
enabled_loaders = []
loaders_deps = []

227
if get_option('png')
228
  # We have a vast selection of libpng versions to choose from
229
  foreach png: [ 'libpng16', 'libpng15', 'libpng14', 'libpng13', 'libpng12', 'libpng10' ]
230 231 232 233 234 235 236 237
    if not enabled_loaders.contains('png')
      png_dep = dependency(png, required: false)
      if png_dep.found()
        enabled_loaders += 'png'
        loaders_deps += png_dep
      endif
    endif
  endforeach
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265

  if not enabled_loaders.contains('png')
    if cc.get_id() == 'msvc' and cc.has_header('png.h')
      # MSVC: First look for the DLL + import .lib build of libpng,
      # which is normally libpngxx.lib, when libpng's pkg-config can't
      # be found, which is quite normal on MSVC.
      foreach png: [ 'libpng16', 'libpng15', 'libpng14', 'libpng12', 'libpng13', 'libpng10' ]
        if not enabled_loaders.contains('png')
          png_dep = cc.find_library(png, required: false)
          if png_dep.found()
            enabled_loaders += 'png'
            loaders_deps += png_dep
          endif
        endif
      endforeach

      # If we still can't find libpng, try looking for the static libpng.lib,
      # which means we need to ensure we have the static zlib .lib as well
      if not enabled_loaders.contains('png')
        png_dep = cc.find_library('libpng', required: false)
        zlib_dep = cc.find_library('zlib', required: false)
        if png_dep.found() and zlib_dep.found()
          enabled_loaders += 'png'
          loaders_deps += [ png_dep, zlib_dep ]
        endif
      endif
    endif
  endif
266 267
endif

268 269 270 271 272
# On Windows, check whether we are building the native Windows loaders
# (it is an "all-or-nothing" option for BMP, EMF, GIF, ICO, JPEG, TIFF and WMF)
# Note that we currently do not use the native Windows loaders to handle PNG and
# JPEG2000 images
if host_system == 'windows'
273
  native_windows_loaders = get_option('native_windows_loaders')
274
else
275
  native_windows_loaders = false
276 277
endif

278
if native_windows_loaders
279 280 281
  loaders_deps += cc.find_library('gdiplus')
  loaders_deps += cc.find_library('ole32')
  enabled_loaders += 'gdiplus'
282 283
endif

284 285
# Don't check and build the jpeg loader if native_windows_loaders is true
if get_option('jpeg') and not native_windows_loaders
286 287
  if cc.has_header('jpeglib.h')
    jpeg_dep = cc.find_library('jpeg', required: false)
288 289 290 291 292
    if cc.get_id() == 'msvc' and not jpeg_dep.found()
      # The IJG JPEG library builds the .lib file as libjpeg.lib in its MSVC build system,
      # so look for it as well when jpeg.lib cannot be found
      jpeg_dep = cc.find_library('libjpeg', required: false)
    endif
293 294 295 296 297 298 299 300 301 302
    if jpeg_dep.found() and cc.has_function('jpeg_destroy_decompress', dependencies: jpeg_dep)
      enabled_loaders += 'jpeg'
      loaders_deps += jpeg_dep

      gdk_pixbuf_conf.set('HAVE_PROGRESSIVE_JPEG',
                          cc.has_function('jpeg_simple_progression', dependencies: jpeg_dep))
    endif
  endif
endif

303 304
# Don't check and build the tiff loader if native_windows_loaders is true
if get_option('tiff') and not native_windows_loaders
305
  tiff_dep = dependency('libtiff-4', required: false)
306 307 308 309 310 311 312 313 314 315 316 317 318
  if not tiff_dep.found()
    # Fallback when no pkg-config file is found for libtiff on MSVC, which is quite normal
    if cc.get_id() == 'msvc' and cc.has_header('tiff.h')
      # First look for the DLL builds of libtiff, then the static builds
      tiff_dep = cc.find_library('libtiff_i', required: false)

      if not tiff_dep.found()
        # For the static lib, zlib and libjpeg .lib's have been looked for first, and
        # they are optional for libtiff
        tiff_dep = cc.find_library('libtiff', required: false)
      endif
    endif
  endif
319 320 321 322 323 324
  if tiff_dep.found()
    enabled_loaders += 'tiff'
    loaders_deps += tiff_dep
  endif
endif

325 326
jasper_extra_cflags = []

327
if get_option('jasper')
328 329 330 331 332 333 334 335 336 337 338 339
  has_jasper_header = false

  if cc.get_id() == 'msvc'
    # We must define JAS_WIN_MSVC_BUILD before including jasper/jasper.h on MSVC
    jasper_msvc_macro = 'JAS_WIN_MSVC_BUILD'
    has_jasper_header = cc.has_header('jasper/jasper.h', prefix: '#define @0@'.format(jasper_msvc_macro))
    jasper_extra_cflags = [ '-D@0@'.format(jasper_msvc_macro) ]
  else
    has_jasper_header = cc.has_header('jasper/jasper.h')
  endif

  if has_jasper_header
340
    jasper_dep = cc.find_library('jasper', required: false)
341 342 343 344 345 346 347
    if not jasper_dep.found()
      if cc.get_id() == 'msvc'
        # on MSVC, we need to look for libjasper.lib if jasper.lib is not found,
        # which corresponds to what libjasper's MSVC projects produce
        jasper_dep = cc.find_library('libjasper', required: false)
      endif
    endif
348 349 350 351 352 353 354
    if jasper_dep.found() and cc.has_function('jas_init', dependencies: jasper_dep)
      enabled_loaders += 'jasper'
      loaders_deps += jasper_dep
    endif
  endif
endif

355 356 357 358 359
# Determine whether we enable application bundle relocation support, and we use
# this always on Windows
if host_system == 'windows'
  relocatable = true
else
360
  relocatable = get_option('relocatable')
361 362 363 364 365 366
endif

if relocatable
  add_project_arguments([ '-DGDK_PIXBUF_RELOCATABLE' ], language: 'c')
endif

367 368 369 370 371 372
gdk_pixbuf_conf.set_quoted('GETTEXT_PACKAGE', meson.project_name())

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

root_inc = include_directories('.')

373 374 375 376 377
# Auxiliary scripts
gen_resources = find_program('build-aux/gen-resources.py')
gen_installed_test = find_program('build-aux/gen-installed-test.py')
gen_thumbnailer = find_program('build-aux/gen-thumbnailer.py')

378 379 380 381
gnome = import('gnome')

subdir('gdk-pixbuf')

382
gdkpixbuf_xlib_inc = []
383
if get_option('x11')
384
  x11_dep = cc.find_library('X11', required: false)
385 386 387
    if x11_dep.found()
      subdir('contrib/gdk-pixbuf-xlib')
    endif
388 389
endif

390 391 392 393
# i18n
subdir('po')

subdir('tests')
394
subdir('thumbnailer')
395 396

# Documentation
397
subdir('docs')
398 399 400 401 402 403 404

if not meson.is_cross_build()
  meson.add_install_script('build-aux/post-install.sh',
    gdk_pixbuf_libdir,
    gdk_pixbuf_binary_version,
  )
endif