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

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

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

# Platform detection
host_system = host_machine.system()
is_macos = host_system == 'darwin'
is_linux = host_system == 'linux'

py_installation = python.find_installation('python3')

# Check required Python modules
_pip_names = {'Crypto': 'pycryptodome', 'serial': 'pyserial'}
_required_modules = ['Crypto', 'serial']

# Platform-specific modules
if is_linux and get_option('qr_scanner')
  _required_modules += ['pyzbar']
endif

if is_macos
  _macos_modules = ['objc', 'CoreBluetooth', 'CoreLocation']
  if get_option('qr_scanner')
    _macos_modules += ['AVFoundation', 'Vision', 'libdispatch']
  endif
  _required_modules += _macos_modules
  _pip_names += {'objc': 'pyobjc', 'CoreBluetooth': 'pyobjc-framework-CoreBluetooth', 'CoreLocation': 'pyobjc-framework-CoreLocation', 'AVFoundation': 'pyobjc-framework-AVFoundation', 'Vision': 'pyobjc-framework-Vision', 'libdispatch': 'pyobjc-framework-libdispatch'}
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 @1@'.format(mod, _pip))
  endif
endforeach

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

conf = configuration_data()
conf.set('PYTHON', py_installation.full_path())
conf.set('VERSION', meson.project_version())
conf.set('APPLICATION_ID', APPLICATION_ID)
conf.set('localedir', get_option('prefix') / get_option('localedir'))
conf.set('pkgdatadir', pkgdatadir)
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,
)
