project('glslang', 'cpp',
    version : run_command('git', 'describe', '--dirty').stdout().strip(),
    meson_version : '>=0.47.0',
    default_options : [
        'cpp_std=c++11',
    ]
)

cxx = meson.get_compiler('cpp')
add_project_arguments(cxx.get_supported_arguments('-fpermissive'), language : 'cpp')

threads_dep = dependency('threads')
spvtools_dep = dependency('SPIRV-Tools', required : get_option('enable_opt'), fallback : ['SPIRV-Tools', 'spirv_tools_opt_dep'])

if not get_option('enable_amd_exts').disabled()
    add_project_arguments('-DAMD_EXTENSIONS', language : 'cpp')
endif

if not get_option('enable_nv_exts').disabled()
    add_project_arguments('-DNV_EXTENSIONS', language : 'cpp')
endif

if not get_option('enable_hlsl').disabled()
    add_project_arguments('-DENABLE_HLSL', language : 'cpp')
endif

if spvtools_dep.found()
    add_project_arguments('-DENABLE_OPT=1', language : 'cpp')
else
    add_project_arguments('-DENABLE_OPT=0', language : 'cpp')

    if not get_option('enable_hlsl').disabled()
        message('SPIRV-Tools not linked - illegal SPIRV may be generated for HLSL')
    endif
endif

if host_machine.system() == 'windows'
    add_project_arguments('-DGLSLANG_OSINCLUDE_WIN32', language : 'cpp')
else
    add_project_arguments('-DGLSLANG_OSINCLUDE_UNIX', language : 'cpp')
endif

subdir('SPIRV')
subdir('OGLCompilersDLL')

if not get_option('enable_hlsl').disabled()
    subdir('hlsl')
endif

subdir('glslang')

glslang_dep = declare_dependency(
    link_with : libglslang,
    include_directories : include_directories('.'),
)
