cmake_minimum_required(VERSION 3.30)
project(vulkan_test)

set(CMAKE_CXX_STANDARD 26)
set(GLFW_USE_WAYLAND ON)

find_package(Vulkan REQUIRED)
find_package(glfw3 3.3 REQUIRED)

find_program(GLSLC glslc)
if(NOT GLSLC)
    message(FATAL_ERROR "glslc compiler not found. Please install the Vulkan SDK.")
endif()

# Copy textures into cmake output
file(GLOB TEXTURE_FILES
        "${CMAKE_CURRENT_SOURCE_DIR}/textures/*"
)
foreach(TEXTURE ${TEXTURE_FILES})
    file(COPY ${TEXTURE_FILES} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/textures/")
endforeach()

# Copy shaders into cmake output
file(GLOB SHADER_FILES
        "${CMAKE_CURRENT_SOURCE_DIR}/shaders/*.vert"
        "${CMAKE_CURRENT_SOURCE_DIR}/shaders/*.frag"
)

foreach(SHADER ${SHADER_FILES})
    get_filename_component(SHADER_NAME ${SHADER} NAME)
    set(SPIRV "${CMAKE_CURRENT_BINARY_DIR}/shaders/${SHADER_NAME}.spv")

    add_custom_command(
            OUTPUT ${SPIRV}
            COMMAND ${GLSLC} ${SHADER} -o ${SPIRV}
            DEPENDS ${SHADER}
            COMMENT "Compiling ${SHADER_NAME}"
    )

    list(APPEND SPIRV_SHADERS ${SPIRV})
endforeach()

add_custom_target(compile_shaders ALL DEPENDS ${SPIRV_SHADERS})

add_executable(vulkan_test
        main.cpp
        vulkan/vulkan_app.cpp
        vulkan/vulkan_app.hpp
)

target_link_libraries(vulkan_test PRIVATE Vulkan::Vulkan glfw)

add_dependencies(vulkan_test compile_shaders)
