if platform_osx
  add_project_arguments('-ObjC', language : 'c')
endif

pikaversion = configure_file(
  input : 'pikaversion.h.in',
  output: 'pikaversion.h',
  configuration: versionconfig,
)

stamp_base_enums = custom_target('stamp-pikabaseenums.h',
  input : [
    files(
      'pikabaseenums.h'
    ),
  ],
  output: [ 'stamp-pikabaseenums.h', ],
  command: [
    mkenums_wrap, perl,
    meson.project_source_root(), meson.current_source_dir(),
    meson.current_build_dir(),
    'pikabase',
    '#include <glib-object.h>\n'       +
    '#undef PIKA_DISABLE_DEPRECATED\n' +
    '#include "pikabasetypes.h"\n'     +
    '#include "libpika/libpika-intl.h"\n',
    '',
    libpika_mkenums_dtails
  ],
  build_by_default: true
)

stamp_compat_enums = custom_target('stamp-pikacompatenums.h',
  input : [
    files(
      'pikacompatenums.h'
    ),
  ],
  output: [ 'stamp-pikacompatenums.h', ],
  command: [
    mkenums_wrap, perl,
    meson.project_source_root(), meson.current_source_dir(), meson.current_build_dir(),
    'pikacompat',
    '#include <glib-object.h>\n'       +
    '#include "pikabasetypes.h"\n',
    '#include "libpika/libpika-intl.h"',
  ],
  build_by_default: true
)

libpikabase_sources_introspectable = files(
  'pikabasetypes.c',
  'pikachecks.c',
  'pikachoice.c',
  'pikacpuaccel.c',
  'pikaenv.c',
  'pikamemsize.c',
  'pikametadata.c',
  'pikaparamspecs.c',
  'pikaparasite.c',
  'pikaparasiteio.c',
  'pikarectangle.c',
  'pikasignal.c',
  'pikaunit.c',
  'pikautils.c',
  'pikavaluearray.c',
)

libpikabase_sources = [
  libpikabase_sources_introspectable,
  'pikabase-private.c',
  'pikaprotocol.c',
  'pikareloc.c',
  'pikawire.c',

  'pikabaseenums.c',
  stamp_base_enums,

  'pikacompatenums.c',
  stamp_compat_enums
]

libpikabase_headers_introspectable = files(
  'pikabaseenums.h',
  'pikabasetypes.h',
  'pikachecks.h',
  'pikacpuaccel.h',
  'pikaenv.h',
  'pikalimits.h',
  'pikamemsize.h',
  'pikametadata.h',
  'pikaparamspecs.h',
  'pikaparasite.h',
  'pikaparasiteio.h',
  'pikarectangle.h',
  'pikasignal.h',
  'pikaunit.h',
  'pikautils.h',
  'pikavaluearray.h',
) + [
  pikaversion,
]

libpikabase_headers = [
  libpikabase_headers_introspectable,
  'pikabase.h',
  pikaversion,
]

libpikabase_introspectable = [
  libpikabase_sources_introspectable,
  libpikabase_headers_introspectable,
]

libpikabase = library('pikabase-' + pika_api_version,
  libpikabase_sources,
  include_directories: rootInclude,
  dependencies: [
    gexiv2, gio, math,
    # optionally depend on libexecinfo on platforms where it is not
    # internal to the libc.
    opt_execinfo,
  ],
  c_args: [
    '-DG_LOG_DOMAIN="LibPikaBase"',
    '-DPIKA_BASE_COMPILATION',
  ],
  vs_module_defs: 'pikabase.def',
  install: true,
  version: so_version,
)

install_headers(
  libpikabase_headers,
  subdir: pika_api_name / 'libpikabase',
)

# Test program, not installed
executable('test-cpu-accel',
  'test-cpu-accel.c',
  include_directories: rootInclude,
  dependencies: [
    glib,
  ],
  c_args: [
    '-DG_LOG_DOMAIN="LibPikaBase"',
    '-DPIKA_BASE_COMPILATION',
  ],
  link_with: [
    libpikabase,
  ],
  install: false,
)
