2024-05-03 13:01:33 -04:00
|
|
|
cmake_minimum_required(VERSION 3.25)
|
|
|
|
project(SofRenderer C)
|
|
|
|
|
|
|
|
option(DEBUG_BUILD "Build the library in debug mode." OFF)
|
|
|
|
if (DEBUG_BUILD)
|
|
|
|
add_compile_definitions(RENDERER_DEBUG)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
find_package(Vulkan REQUIRED)
|
|
|
|
|
|
|
|
# compile shaders
|
|
|
|
file(GLOB_RECURSE SHADER_FILES "${PROJECT_SOURCE_DIR}/shaders/*.frag" "${PROJECT_SOURCE_DIR}/shaders/*.vert")
|
|
|
|
foreach(SHADER_FILE ${SHADER_FILES})
|
|
|
|
cmake_path(GET SHADER_FILE FILENAME SHADER_FILE_NAME)
|
|
|
|
message(STATUS "Configuring \"${SHADER_FILE_NAME}\" to compile with "${Vulkan_GLSLANG_VALIDATOR_EXECUTABLE}" ...")
|
|
|
|
set(SHADER_SPIRV "${PROJECT_SOURCE_DIR}/shaders/${SHADER_FILE_NAME}.spv")
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT "${SHADER_SPIRV}"
|
|
|
|
COMMAND "${Vulkan_GLSLANG_VALIDATOR_EXECUTABLE}" -V "${PROJECT_SOURCE_DIR}/shaders/${SHADER_FILE_NAME}" -o "${SHADER_SPIRV}"
|
|
|
|
DEPENDS "${PROJECT_SOURCE_DIR}/shaders/${SHADER_FILE_NAME}")
|
|
|
|
list(APPEND SHADER_SPIRV_BINARIES ${SHADER_SPIRV})
|
|
|
|
endforeach()
|
|
|
|
add_custom_target(shaders ALL DEPENDS ${SHADER_SPIRV_BINARIES})
|
|
|
|
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
|
|
|
|
add_library(sofrenderer SHARED
|
|
|
|
"src/logger.c"
|
|
|
|
"src/renderer.c"
|
|
|
|
"src/containers/darray.c"
|
|
|
|
"src/containers/dblist.c"
|
2024-05-13 20:05:28 -04:00
|
|
|
"src/containers/hashtable.c"
|
|
|
|
"src/containers/ringqueue.c")
|
2024-05-03 13:01:33 -04:00
|
|
|
target_include_directories(sofrenderer PRIVATE "${PROJECT_SOURCE_DIR}/src")
|
|
|
|
set_target_properties(sofrenderer PROPERTIES
|
|
|
|
C_STANDARD 99
|
|
|
|
LIBRARY_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/lib")
|
|
|
|
|
|
|
|
# GLFW
|
|
|
|
add_subdirectory(../external/glfw build)
|
|
|
|
target_include_directories(sofrenderer PRIVATE "${PROJECT_SOURCE_DIR}/../external/glfw/include")
|
|
|
|
target_link_directories(sofrenderer PRIVATE "${PROJECT_SOURCE_DIR}/../external/glfw")
|
|
|
|
target_link_libraries(sofrenderer PRIVATE glfw)
|
|
|
|
|
|
|
|
# Vulkan
|
|
|
|
target_include_directories(sofrenderer PRIVATE ${Vulkan_INCLUDE_DIRS})
|
|
|
|
target_link_libraries(sofrenderer PRIVATE ${Vulkan_LIBRARIES})
|
2024-05-22 10:57:13 -04:00
|
|
|
|
|
|
|
# stb
|
|
|
|
target_include_directories(sofrenderer PRIVATE "${PROJECT_SOURCE_DIR}/../external/stb")
|