project('restc-cpp', 'cpp',
  version: '0.9.2',
  meson_version: '>=0.55.0',
  default_options: ['cpp_std=gnu++17'],
)

config_template = files('config.h.template')
if get_option('restc_cpp_with_zlib')
  zipreaderimpl = files('src/ZipReaderImpl.cpp')
endif
compiler_opts = ['-DBOOST_COROUTINE_NO_DEPRECATION_WARNING=1']

boost_modules = [
  'system', 'program_options', 'filesystem', 'date_time',
  'context', 'coroutine', 'chrono'
]
if get_option('restc_cpp_log_with_boost_log')
  boost_modules += ['log']
endif

thread_dep = dependency('threads')
boost_dep = dependency('boost', modules: boost_modules)
rapidjson_dep = dependency('RapidJSON')

if not get_option('embedded_restc_cpp')
  if get_option('restc_cpp_with_zlib')
	zlib_dep = dependency('zlib')
  endif
  if get_option('restc_cpp_with_tls')
	tls_dep = dependency('OpenSSL')
  endif
endif

pvt_incdir = include_directories('src')
pub_incdir = include_directories('include', 'include')

boost_test_dep = dependency('boost', modules: ['log'], required: get_option('tests'))

subdir('include/restc-cpp')

restc_cpp_target = library(meson.project_name(),
  'src/ChunkedReaderImpl.cpp',
  'src/ChunkedWriterImpl.cpp',
  'src/IoReaderImpl.cpp',
  'src/IoWriterImpl.cpp',
  'src/PlainReaderImpl.cpp',
  'src/PlainWriterImpl.cpp',
  'src/NoBodyReaderImpl.cpp',
  'src/DataReaderStream.cpp',
  'src/RestClientImpl.cpp',
  'src/RequestImpl.cpp',
  'src/ReplyImpl.cpp',
  'src/ConnectionPoolImpl.cpp',
  'src/Url.cpp',
  'src/RequestBodyStringImpl.cpp',
  'src/RequestBodyFileImpl.cpp',
  'src/url_encode.cpp',
  zipreaderimpl,
  install: true,
  include_directories: [pvt_incdir, pub_incdir],
  dependencies: [
	zlib_dep,
	tls_dep,
	thread_dep,
	boost_dep,
	rapidjson_dep,
  ],
  cpp_args: compiler_opts,
)

restc_cpp_dep = declare_dependency(
  link_with: restc_cpp_target,
  include_directories: pub_incdir,
  compile_args: compiler_opts,
  dependencies: [tls_dep, thread_dep, boost_dep],
)

subdir('tests', if_found: boost_test_dep)
