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

project('meshy',
  version: '0.0.0',
  meson_version: '>= 0.62.0',
)

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

py_installation = python.find_installation('python3')

# Check required Python modules
_pip_names = {'Crypto': 'pycryptodome', 'serial': 'pyserial'}
_required_modules = ['Crypto', 'serial']
if get_option('qr_scanner')
  _required_modules += ['pyzbar']
endif
foreach mod : _required_modules
  if run_command(py_installation, '-c', 'import @0@'.format(mod), check: false).returncode() != 0
    _pip = _pip_names.get(mod, mod)
    warning('Python module "@0@" not found. Install it via pip: pip install @0@'.format(mod, _pip))
  endif
endforeach

APPLICATION_ID = 'page.codeberg.sesivany.Meshy'
pkgdatadir = get_option('prefix') / get_option('datadir') / 'meshy'

date_version = run_command('date', '+%Y%m%d', check: true).stdout().strip()

conf = configuration_data()
conf.set('PYTHON', py_installation.full_path())
conf.set('VERSION', date_version)
conf.set('APPLICATION_ID', APPLICATION_ID)
conf.set('pkgdatadir', pkgdatadir)
conf.set('localedir', get_option('prefix') / get_option('localedir'))
conf.set('QR_SCANNER_ENABLED', get_option('qr_scanner').to_string())
conf.set('SHORTCUTS_DIALOG_ENABLED', get_option('shortcuts_dialog').to_string())

subdir('data')
subdir('src')
subdir('po')

gnome.post_install(
  glib_compile_schemas: true,
  gtk_update_icon_cache: true,
  update_desktop_database: true,
)
