project(
  'driftwood',
  'rust',
  version: '0.1.0',
  license: 'CC0-1.0',
  meson_version: '>= 0.62.0',
)

i18n = import('i18n')
gnome = import('gnome')

app_id = 'app.driftwood.Driftwood'
prefix = get_option('prefix')
bindir = prefix / get_option('bindir')
datadir = prefix / get_option('datadir')
localedir = prefix / get_option('localedir')
iconsdir = datadir / 'icons'

# Install desktop file
install_data(
  'data' / app_id + '.desktop',
  install_dir: datadir / 'applications',
)

# Install AppStream metainfo
install_data(
  'data' / app_id + '.metainfo.xml',
  install_dir: datadir / 'metainfo',
)

# Install app icons
install_data(
  'data' / 'icons' / 'hicolor' / 'scalable' / 'apps' / app_id + '.svg',
  install_dir: iconsdir / 'hicolor' / 'scalable' / 'apps',
)
install_data(
  'data' / 'icons' / 'hicolor' / 'symbolic' / 'apps' / app_id + '-symbolic.svg',
  install_dir: iconsdir / 'hicolor' / 'symbolic' / 'apps',
)

# Compile and install GSettings schema
install_data(
  'data' / app_id + '.gschema.xml',
  install_dir: datadir / 'glib-2.0' / 'schemas',
)
gnome.post_install(
  glib_compile_schemas: true,
  gtk_update_icon_cache: true,
)

# Build the Rust binary via Cargo
cargo = find_program('cargo')
cargo_build_type = get_option('buildtype') == 'release' ? '--release' : ''

custom_target(
  'driftwood-binary',
  output: 'driftwood',
  command: [
    cargo, 'build',
    cargo_build_type,
    '--manifest-path', meson.project_source_root() / 'Cargo.toml',
    '--target-dir', meson.project_build_root() / 'cargo-target',
  ],
  env: {
    'LOCALEDIR': localedir,
    'GSETTINGS_SCHEMA_DIR': datadir / 'glib-2.0' / 'schemas',
  },
  build_by_default: true,
  install: false,
)

# Install the binary (from the cargo output directory)
cargo_profile = get_option('buildtype') == 'release' ? 'release' : 'debug'
install_data(
  meson.project_build_root() / 'cargo-target' / cargo_profile / 'driftwood',
  install_dir: bindir,
  install_mode: 'rwxr-xr-x',
)

# Translations
subdir('po')
