project(
  'phosphor-host-postd',
  'cpp',
  default_options: [
    'warning_level=3',
    'werror=true',
    'cpp_std=c++20'
  ],
  license: 'Apache-2.0',
  version: '1.0',
  meson_version: '>=0.58.0',
)

build_tests = get_option('tests')

postd_headers = include_directories('.')

phosphor_dbus_interfaces = dependency('phosphor-dbus-interfaces')
sdbusplus = dependency('sdbusplus')
sdeventplus = dependency('sdeventplus')
systemd = dependency('systemd')
libgpiodcxx = dependency('libgpiodcxx')

conf_data = configuration_data()
conf_data.set('bindir', get_option('prefix') / get_option('bindir'))
conf_data.set('SYSTEMD_TARGET', get_option('systemd-target'))

snoopd_args = '-b ' + get_option('post-code-bytes').to_string()
if not get_option('snoop').disabled()
    add_project_arguments('-DENABLE_IPMI_SNOOP',language:'cpp')
    snoopd_args += ' -h "' + get_option('host-instances') + '"'
endif

if get_option('snoop-device') != ''
  snoopd_args += ' -d /dev/' + get_option('snoop-device')
endif
conf_data.set('SNOOPD_ARGS', snoopd_args)

configure_file(
  input: 'lpcsnoop.service.in',
  output: 'lpcsnoop.service',
  configuration: conf_data,
  install: true,
  install_dir: systemd.get_variable('systemdsystemunitdir'))

executable(
  'snoopd',
  'main.cpp',
  dependencies: [
    sdbusplus,
    sdeventplus,
    phosphor_dbus_interfaces,
    libgpiodcxx,
  ],
  install: true,
)

executable(
  'snooper',
  'example.cpp',
  dependencies: [
    sdbusplus,
    sdeventplus,
    phosphor_dbus_interfaces,
  ],
  install: true,
)

if not get_option('7seg').disabled()
  udevdir = dependency('udev', required : false).get_variable('udevdir')
  assert(udevdir != '', 'Cannot find udevdir')
  install_data(['80-7seg.rules'], install_dir : udevdir)

  install_data(
    ['postcode-7seg@.service'],
    install_dir: systemd.get_variable('systemdsystemunitdir')
  )

  executable(
    'postcode_7seg',
    '7seg.cpp',
    dependencies: [
      sdbusplus,
      phosphor_dbus_interfaces,
    ],
    install: true,
  )
endif

install_headers(
  'lpcsnoop/snoop.hpp',
  'lpcsnoop/snoop_listen.hpp',
  subdir: 'lpcsnoop')

if not build_tests.disabled()
  subdir('test')
endif