project('EMPER', 'c', 'cpp',
		version: '0.0.1-alpha1-SNAPSHOT',
		default_options : [
		  'warning_level=3',
		  'c_std=gnu11',
		  'cpp_std=c++2a',
		  'b_ndebug=if-release',
		  'werror=true',
		])

# TODO: Re-enable that warning.
add_project_arguments('-Wno-non-virtual-dtor', language: 'cpp')

thread_dep = dependency('threads')
uring_dep = dependency('liburing')
emper_dependencies = [thread_dep, uring_dep]

run_target('iwyu',
		   command: 'tools/check-iwyu')

conf_data = configuration_data()
option_urcu = get_option('userspace_rcu')
conf_data.set('EMPER_LIBURCU', option_urcu)
if option_urcu
	liburcu_dep = dependency('liburcu')
	emper_dependencies += [liburcu_dep]
endif

conf_data.set('EMPER_WORKER_SLEEP', get_option('worker_sleep'))
conf_data.set('EMPER_WORKER_WAKEUP_STRATEGY', get_option('worker_wakeup_strategy'))
conf_data.set('EMPER_LOCKED_WS_QUEUE', get_option('locked_ws_queue'))
conf_data.set('EMPER_OVERFLOW_QUEUE', get_option('overflow_queue'))
conf_data.set('EMPER_LOCKED_MPSC_QUEUE', get_option('locked_mpsc_queue'))
conf_data.set('EMPER_STATS', get_option('stats'))
conf_data.set('EMPER_OVERFLOW_QUEUE', get_option('overflow_queue'))
conf_data.set('EMPER_BLOCKED_CONTEXT_SET', get_option('blocked_context_set'))

default_scheduling_strategy = get_option('default_scheduling_strategy')
conf_data.set('EMPER_DEFAULT_SCHEDULING_STRATEGY_' + default_scheduling_strategy.to_upper(), true)

log_level = get_option('log_level')
if log_level == 'automatic'
	# output only error messages in release builds
	log_level = get_option('buildtype') == 'release' ? 'Error' : 'ALL'
# turn logging of during compilation
elif log_level == 'OFF'
	conf_data.set('EMPER_LOG_OFF', true)
endif
conf_data.set('EMPER_LOG_LEVEL', log_level)
conf_data.set('EMPER_LOG_TIMESTAMP', get_option('log_timestamp'))

option_io =  get_option('io')
if option_io
	conf_data.set('EMPER_IO', true)
endif

io_bool_options = [
	'uring_sqpoll',
	'uring_shared_wq',
]

io_raw_options = [
	'worker_uring_entries',
]

foreach option : io_bool_options
	value = get_option('io_' + option)
	if value == true and not option_io
		error('io_' + option + ' defined without io')
	endif
	conf_data.set('EMPER_IO_' + option.to_upper(), value)
endforeach

foreach option : io_raw_options
	conf_data.set('EMPER_IO_' + option.to_upper(), get_option('io_' + option))
endforeach

subdir('emper')
subdir('tests')
subdir('apps')
subdir('eval')
subdir('doc')