cmake_minimum_required(VERSION 3.25)
project(skunkworks_c C)

#cmake_policy(SET CMP0074 NEW)
#set(CMAKE_POLICY_DEFAULT_CMP0074 NEW)

cmake_policy(SET CMP0091 NEW)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

set(CMAKE_C_STANDARD 90)

SET_TARGET_PROPERTIES(${skunkworks_c} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:zlib.lib")

add_subdirectory(subprojects/glew-2.1.0/build/cmake)
include_directories(subprojects/glew-2.1.0/include)

set(GLFW_BUILD_EXAMPLES OFF)

add_subdirectory(subprojects/glfw-3.3.8)
include_directories(subprojects/glfw-3.3.8/include)

set(PNG_SHARED OFF)
set(PNG_BUILD_ZLIB ON)

add_subdirectory(subprojects/zlib-1.2.13)
include_directories(subprojects/zlib-1.2.13 "${CMAKE_BINARY_DIR}/subprojects/zlib-1.2.13")

#set(ZLIB_ROOT subprojects/zlib-1.2.13)
set(ZLIB_INCLUDE_DIR subprojects/zlib-1.2.13 "${CMAKE_BINARY_DIR}/subprojects/zlib-1.2.13")
#set(ZLIB_LIBRARY zlib)

add_subdirectory(subprojects/lpng1639)
include_directories(subprojects/lpng1639 "${CMAKE_BINARY_DIR}/subprojects/lpng1639")


include_directories(include)
include_directories(src)

add_library(skunkworks STATIC
        include/net/http_client.h
        include/color32.h
        include/color8.h
        include/error.h
        include/file.h
        include/framebuffer.h
        include/gamepad.h
        include/gsa.h
        include/gsa_input.h
        include/gsa_map.h
        include/gsa_text.h
        include/image32.h
        include/image8.h
        include/msvc.h
        include/renderer.h
        include/renderer2d.h
        include/scaler.h
        include/shader.h
        include/shaders.h
        include/skip.h
        include/skunkworks.h
        include/str.h
        include/types.h
        include/vec2i.h
        include/vertex_buffer.h
        include/window.h
        src/net/http_client.c
        src/color32.c
        src/error.c
        src/file.c
        src/framebuffer.c
        src/gamepad.c
        src/gl.h
        src/gsa.c
        src/gsa_input.c
        src/gsa_map.c
        src/gsa_text.c
        src/image32.c
        src/image8.c
        src/renderer.c
        src/renderer2d.c
        src/scaler.c
        src/shader.c
        src/shaders.c
        src/skip.c
        src/skunkworks.c
        src/str.c
        src/types.c
        src/vec2i.c
        src/vertex_buffer.c
        src/window.c)

add_executable(skip
        tools/skip.c)

target_link_libraries(skip skunkworks)

add_executable(simple
        examples/simple.c)

add_custom_command(TARGET simple POST_BUILD
        COMMAND "copy" "src\\*.glsl" "example_data"
        COMMAND skip "ca1" "example_data" $<TARGET_FILE:simple>
        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
        COMMENT "attaching data to simple.exe")

target_link_libraries(simple skunkworks glew_s glfw)

add_executable(gsa_simple
        examples/gsa_simple.c)

add_custom_command(TARGET gsa_simple POST_BUILD
        COMMAND "copy" "src\\*.glsl" "example_data"
        COMMAND skip "ca1" "example_data" $<TARGET_FILE:gsa_simple>
        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
        COMMENT "attaching data to gsa_simple.exe")

target_link_libraries(gsa_simple skunkworks glew_s glfw zlibstatic png_static)
