# Copyright 2026, Jiri Eischmann <jiri@eischmann.cz> and the meshy contributors
# SPDX-License-Identifier: GPL-3.0-or-later

desktop_file = i18n.merge_file(
  input: 'page.codeberg.sesivany.Meshy.desktop.in',
  output: 'page.codeberg.sesivany.Meshy.desktop',
  type: 'desktop',
  po_dir: '../po',
  install: true,
  install_dir: get_option('datadir') / 'applications',
)

desktop_utils = find_program('desktop-file-validate', required: false)
if desktop_utils.found()
  test('Validate desktop file', desktop_utils, args: [desktop_file])
endif

appstream_file = i18n.merge_file(
  input: 'page.codeberg.sesivany.Meshy.metainfo.xml.in',
  output: 'page.codeberg.sesivany.Meshy.metainfo.xml',
  po_dir: '../po',
  install: true,
  install_dir: get_option('datadir') / 'metainfo',
)

appstreamcli = find_program('appstreamcli', required: false)
if appstreamcli.found()
  test('Validate appstream file', appstreamcli,
    args: ['validate', '--no-net', '--explain', appstream_file])
endif

install_data(
  'page.codeberg.sesivany.Meshy.gschema.xml',
  install_dir: get_option('datadir') / 'glib-2.0' / 'schemas',
)

compile_schemas = find_program('glib-compile-schemas', required: false)
if compile_schemas.found()
  test('Validate schema file',
    compile_schemas,
    args: ['--strict', '--dry-run', meson.current_source_dir()])
endif

gresource_conf = configuration_data()
if get_option('shortcuts_dialog')
  gresource_conf.set('HELP_OVERLAY_ENTRY',
    '<file preprocess="xml-stripblanks">gtk/help-overlay.ui</file>')
else
  gresource_conf.set('HELP_OVERLAY_ENTRY', '')
endif

gresource_xml = configure_file(
  input: 'page.codeberg.sesivany.Meshy.gresource.xml.in',
  output: 'page.codeberg.sesivany.Meshy.gresource.xml',
  configuration: gresource_conf,
)

gnome.compile_resources('meshy',
  gresource_xml,
  source_dir: meson.current_source_dir(),
  gresource_bundle: true,
  install: true,
  install_dir: pkgdatadir,
)

install_data(
  '60-meshy-serial.rules',
  install_dir: get_option('datadir') / 'meshy',
)

foreach size : ['512x512', '256x256', '128x128', '64x64', '48x48']
  install_data(
    'icons' / 'hicolor' / size / 'apps' / 'page.codeberg.sesivany.Meshy.png',
    install_dir: get_option('datadir') / 'icons' / 'hicolor' / size / 'apps',
  )
endforeach
