project('gamingcore', 'cpp', default_options : ['default_library=static', 'cpp_std=c++17'])

src = [
    'io/ImageReader.cpp',
    'math/Math.cpp',
    'math/Box.cpp',
    'math/Frustum.cpp',
    'math/View.cpp',
    'math/Matrix.cpp',
    'math/Plane.cpp',
    'math/Quaternion.cpp',
    'math/Vector.cpp',
    'network/Client.cpp',
    'network/ENet.cpp',
    'network/Packet.cpp',
    'network/Server.cpp',
    'rendering/Shader.cpp',
    'rendering/Texture.cpp',
    'rendering/VertexBuffer.cpp',
    'rendering/Window.cpp',
    'rendering/GL.cpp',
    'data/BitArray.cpp',
    'utils/Buffer.cpp',
    'utils/Clock.cpp',
    'utils/Error.cpp',
    'utils/Logger.cpp',
    'utils/Random.cpp',
    'utils/Utility.cpp',
]

src_tests = [
    'Main.cpp',
    'tests/ArrayListTests.cpp',
    'tests/ArrayTests.cpp',
    'tests/BitArrayTests.cpp',
    'tests/BufferTests.cpp',
    'tests/BufferedValueTests.cpp',
    'tests/BoxTests.cpp',
    'tests/ClockTests.cpp',
    'tests/ColorTests.cpp',
    'tests/FrustumTests.cpp',
    'tests/HashMapTests.cpp',
    'tests/ListTests.cpp',
    'tests/MatrixStackTests.cpp',
    'tests/MatrixTests.cpp',
    'tests/NetworkTests.cpp',
    'tests/ImageReaderTests.cpp',
    'tests/PlaneTests.cpp',
    'tests/QuaternionTests.cpp',
    'tests/RandomTests.cpp',
    'tests/RingBufferTests.cpp',
    'tests/SplitStringTests.cpp',
    'tests/StackTests.cpp',
    'tests/StringBufferTests.cpp',
    'tests/Test.cpp',
    'tests/TypedBufferTests.cpp',
    'tests/UniquePointerTests.cpp',
    'tests/MathTests.cpp',
    'tests/VectorTests.cpp',
    'tests/ViewTests.cpp',
    'tests/ComponentsTests.cpp',
]

compiler = meson.get_compiler('cpp')
error_args = compiler.get_supported_arguments([
    '-Wcast-align=strict', '-pedantic', '-Wmissing-declarations', '-Wdate-time', 
    '-Winit-self', '-Woverlength-strings', '-Wsign-promo', '-Wnon-virtual-dtor', 
    '-Wconversion', '-Woverloaded-virtual', '-Wdeprecated-enum-enum-conversion', 
    '-Wdisabled-optimization', '-Winvalid-imported-macros', '-Wduplicated-cond', 
    '-Wdeprecated-enum-float-conversion', '-Wduplicated-branches', '-Wformat=2', 
    '-Wmissing-braces', '-Wsuggest-override', '-Wcast-qual', '-Wbidi-chars=any', 
    '-Wzero-as-null-pointer-constant', '-pedantic-errors', '-Wnull-dereference', 
    '-Wformat-signedness', '-Wfloat-equal', '-Wvolatile', '-Wctor-dtor-privacy', 
    '-Winfinite-recursion', '-Wshift-overflow=2', '-Wmultichar', '-Walloc-zero', 
    '-Wcomma-subscript', '-Wold-style-cast', '-Wwrite-strings', '-Wswitch-enum', 
    '-Wredundant-decls', '-Werror', '-Wsign-conversion', '-Walloca', '-Wshadow',
    '-Winvalid-pch', '-Wdeprecated-copy-dtor', '-Wundef', '-Wdouble-promotion',
    '-Warith-conversion', '-Wextra', '-Wtrivial-auto-var-init', '-Wlogical-op', 
    '-Wall', '-Wenum-conversion'
])
compile_args = compiler.get_supported_arguments([
    '-nostdinc++', '-fno-exceptions', '-fno-rtti', '-fno-threadsafe-statics'
])
link_args = compiler.get_supported_arguments([
    '-nodefaultlibs', '-lc', '-lm'
])

add_global_arguments('-DLODEPNG_NO_COMPILE_CPP', language : 'cpp')

cmake = import('cmake')
glfw_proj = cmake.subproject('glfw')
glfw_includes = glfw_proj.include_directories('glfw')
glfw_dep = glfw_proj.dependency('glfw')

glew_proj = subproject('glew', default_options: 'default_library=static')
glew_includes = glew_proj.get_variable('glew_include')
glew_dep = glew_proj.get_variable('glew_dep')

thread_dep = dependency('threads', static: true)
gl_dep = dependency('GL')

ws2_32_dep = compiler.find_library('ws2_32', required: false)
winmm_dep = compiler.find_library('winmm', required: false)
glu_dep = compiler.find_library('glu32', required: false)
dl_dep = compiler.find_library('dl', required: false)

gamingcore_include = [include_directories('.'), glfw_includes, glew_includes]

lodepng = static_library('lodepng', 
    sources: 'libs/lodepng/lodepng.cpp',
    cpp_args: compile_args,
    link_args: link_args)
lodepng_dep = declare_dependency(link_with: lodepng)

gamingcore = static_library('gamingcore', 
    sources: src,
    include_directories: gamingcore_include,
    dependencies: [thread_dep, glfw_dep, glew_dep, gl_dep, ws2_32_dep, winmm_dep, glu_dep, dl_dep, glu_dep, lodepng_dep],
    cpp_args: error_args + compile_args,
    link_args: link_args)

gamingcore_dep = declare_dependency(
    include_directories: gamingcore_include,
    link_with: gamingcore)

executable('tests', 
    sources: src_tests,
    dependencies: gamingcore_dep,
    cpp_args: error_args + compile_args + ['-DLOG_LEVEL=4'],
    link_args: link_args)