# SPDX-FileCopyrightText: 2018-2020 Bruce Cowan
# SPDX-License-Identifier: CC0-1.0

project('stdlib', 'c',
  default_options: ['warning_level=3', 'c_std=gnu99'],
  meson_version: '>=0.50.0')

cc = meson.get_compiler('c')
libm = cc.find_library('m')

glib_dep = dependency('glib-2.0', version: '>= 2.16', required: false)
openmp_dep = dependency('openmp', required: false)
thread_dep = dependency('threads', required: false)

conf_data = configuration_data()

if cc.has_function('reallocarray', prefix: '#define _GNU_SOURCE\n#include <stdlib.h>')
  conf_data.set('HAVE_REALLOCARRAY', 1)
endif

attrs = ['alloc_size', 'malloc', 'warn_unused_result']
foreach attr: attrs
  if cc.has_function_attribute(attr)
    conf_data.set('HAVE_ATTR_' + attr.to_upper(), 1)
  endif
endforeach

if cc.has_header('endian.h')
  has_endian_h = true
endif

config_h = declare_dependency(
  sources: configure_file(
    output: 'config.h',
    configuration: conf_data,
  ),
  include_directories: '.',
)

if host_machine.system() == 'windows'
  socket_deps = [cc.find_library('ws2_32')]
else
  socket_deps = []
endif

subdir('lib')
subdir('src')

if glib_dep.found()
  subdir('test')
endif