project('skunkworks', 'c',
	default_options: [
		'buildtype=release',
		'strip=true',
		'debug=false'
	]
)

cmake = import('cmake')

opt = cmake.subproject_options()
#opt.add_cmake_defines({'MSVC': true})
libz = cmake.subproject('zlib-1.2.13', options: opt).dependency('zlibstatic')

opt = cmake.subproject_options()
opt.add_cmake_defines({
	'ZLIB_INCLUDE_DIRS': 'subprojects/zlib-1.2.13',
	'PNG_BUILD_ZLIB': true,
	'PNG_SHARED': false,
	'PNG_STATIC': true,
	'PNG_EXECUTABLES': false,
	'PNG_TESTS': false,
	'BUILD_SHARED_LIBS': false,
	'SKIP_INSTALL_ALL': true
})
opt.append_compile_args('c', '-I../subprojects/zlib-1.2.13', '-Isubprojects/zlib-1.2.13/__CMake_build')
libpng = cmake.subproject('lpng1639', options: opt).dependency('png_static')

opt = cmake.subproject_options()
opt.add_cmake_defines({'GLFW_BUILD_DOCS': false})


if host_machine.system() == 'emscripten'
   #libglfw = meson.get_compiler('c').find_library('glfw')
   deps = [libz, libpng]
else
	libglfw = cmake.subproject('glfw-3.3.8', options: opt).dependency('glfw')
	libglew = subproject('glew-2.1.0').get_variable('libglew_dep')
	deps = [libz, libpng, libglew, libglfw]
endif

skunk_sources = [
	'src/color32.c',
	'src/error.c',
	'src/file.c',
	'src/framebuffer.c',
	'src/gsa.c',
	'src/image32.c',
	'src/image8.c',
	'src/scaler.c',
	'src/shader.c',
	'src/shaders.c',
	'src/skunkworks.c',
	'src/types.c',
	'src/vec2i.c',
	'src/window.c'
]

xxd = find_program('xxd')
embed_gfx = custom_target('embed-gfx', input: ['gfx.png'], output: ['embed_gfx.h'],
		  command: [xxd, '-i', '@INPUT@', '@OUTPUT@'])

add_project_arguments('-D_CRT_SECURE_NO_WARNINGS', language : 'c')
add_project_arguments('-Wall', language : 'c')
add_project_arguments('-Wextra', language : 'c')
add_project_arguments('-Werror', language : 'c')

lib = static_library('skunkworks', skunk_sources, include_directories: 'include', dependencies: deps)

if host_machine.system() == 'emscripten'
   executable('skunktest', link_with: lib, include_directories: 'include', dependencies: deps, link_args: ['-lglfw', '-lGL', '-s', 'USE_GLFW=3'], name_suffix: 'html')
	executable('gsa', 'examples/gsa_simple.c', embed_gfx, link_with: lib, include_directories: 'include', dependencies: deps, link_args: ['-lglfw', '-lGL', '-s', 'USE_GLFW=3', '-s', 'ALLOW_MEMORY_GROWTH', '-s', 'FULL_ES3'], name_suffix: 'html')
else
	executable('skunktest', 'src/test.c', link_with: lib, include_directories: 'include', dependencies: deps)
	executable('gsa', 'examples/gsa_simple.c', embed_gfx, link_with: lib, include_directories: 'include', dependencies: deps)
endif