project(
  'ahfail',
  ['c', 'rust'],
  version: '0.1.0',
  meson_version: '>=1.3.0',
  default_options: ['warning_level=3', 'c_std=c11']
)

ahfail_inc = include_directories('include')
cc = meson.get_compiler('c')
m_dep = cc.find_library('m', required : false)
gtk_dep = dependency('gtk+-3.0')
gstplayer_dep = dependency('gstreamer-player-1.0')
gnome = import('gnome')

resources = gnome.compile_resources(
  'ahfail-resources',
  'assets/ahfail.gresource.xml',
  source_dir: 'assets',
  c_name: 'ahfail'
)

cargo_target = custom_target(
  'ahfail-cargo-build',
  input: ['crates/ahfail-gtklock/src/lib.rs', 'Cargo.toml'],
  output: ['libahfail_module.a'],
  command: [
    'sh', '-c', 'cargo build --release -p ahfail-gtklock --target-dir "@OUTDIR@/target" && cp "@OUTDIR@/target/release/libahfail_module.a" "@OUTPUT@"'
  ],
  build_by_default: true
)

libahfail = shared_library(
  'ahfail-module',
  resources,
  link_args: ['-Wl,--whole-archive', meson.current_build_dir() / 'libahfail_module.a', '-Wl,--no-whole-archive'],
  link_depends: cargo_target,
  include_directories: ahfail_inc,
  dependencies: [gtk_dep, gstplayer_dep, m_dep],
  install: true,
  install_dir: get_option('libdir') / 'gtklock',
  name_prefix: ''
)

smoke = executable(
  'module_smoke_test',
  'tests/module_test.c',
  include_directories: ahfail_inc,
  link_with: libahfail,
  dependencies: [gtk_dep, gstplayer_dep]
)

test('module symbols', smoke)
