project('rssuper-linux', 'vala', 'c',
  version: '0.1.0',
  default_options: [
    'c_std=c11',
    'warning_level=3',
    'werror=false',
  ]
)

vala = find_program('valac')
meson_version_check = run_command(vala, '--version', check: true)

# Dependencies
glib_dep = dependency('glib-2.0', version: '>= 2.58')
gio_dep = dependency('gio-2.0', version: '>= 2.58')
json_dep = dependency('json-glib-1.0', version: '>= 1.4')
sqlite_dep = dependency('sqlite3', version: '>= 3.0')
gobject_dep = dependency('gobject-2.0', version: '>= 2.58')
xml_dep = dependency('libxml-2.0', version: '>= 2.0')

# Source files
models = files(
  'src/models/feed-item.vala',
  'src/models/feed.vala',
  'src/models/feed-subscription.vala',
  'src/models/search-result.vala',
  'src/models/search-filters.vala',
  'src/models/notification-preferences.vala',
  'src/models/reading-preferences.vala',
)

# Database files
database = files(
  'src/database/db-error.vala',
  'src/database/database.vala',
  'src/database/subscription-store.vala',
  'src/database/feed-item-store.vala',
  'src/database/search-history-store.vala',
)

# Parser files
parser = files(
  'src/parser/feed-type.vala',
  'src/parser/parse-result.vala',
  'src/parser/rss-parser.vala',
  'src/parser/atom-parser.vala',
  'src/parser/feed-parser.vala',
)

# Main library
models_lib = library('rssuper-models', models,
  dependencies: [glib_dep, gio_dep, json_dep],
  install: false
)

# Database library
database_lib = library('rssuper-database', database,
  dependencies: [glib_dep, gio_dep, json_dep, sqlite_dep, gobject_dep],
  link_with: [models_lib],
  install: false,
  vala_args: ['--vapidir', 'src/database', '--pkg', 'sqlite3']
)

# Parser library
parser_lib = library('rssuper-parser', parser,
  dependencies: [glib_dep, gio_dep, json_dep, xml_dep],
  link_with: [models_lib],
  install: false,
  vala_args: ['--vapidir', 'src/parser', '--pkg', 'libxml-2.0']
)

# Test executable
test_exe = executable('database-tests',
  'src/tests/database-tests.vala',
  dependencies: [glib_dep, gio_dep, json_dep, sqlite_dep, gobject_dep, xml_dep],
  link_with: [models_lib, database_lib, parser_lib],
  vala_args: ['--vapidir', '.', '--pkg', 'sqlite3', '--pkg', 'libxml-2.0'],
  install: false
)

# Parser test executable
parser_test_exe = executable('parser-tests',
  'src/tests/parser-tests.vala',
  dependencies: [glib_dep, gio_dep, json_dep, xml_dep],
  link_with: [models_lib, parser_lib],
  vala_args: ['--vapidir', '.', '--pkg', 'libxml-2.0'],
  install: false
)

# Test definitions
test('database tests', test_exe)
test('parser tests', parser_test_exe)
