SOF/renderer/CMakeLists.txt

55 lines
1.9 KiB
CMake
Raw Normal View History

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 -O3 -fPIC")
add_library(sofrenderer SHARED
"src/logger.c"
"src/renderer.c"
"src/containers/darray.c"
"src/containers/dblist.c"
"src/containers/hashtable.c"
"src/containers/ringqueue.c")
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 glfw)
target_link_libraries(sofrenderer PRIVATE glfw)
# Vulkan
target_include_directories(sofrenderer PRIVATE ${Vulkan_INCLUDE_DIRS})
target_link_libraries(sofrenderer PRIVATE ${Vulkan_LIBRARIES})
# stb
target_include_directories(sofrenderer PRIVATE "${PROJECT_SOURCE_DIR}/../external/stb")
# freetype
add_subdirectory(../external/freetype freetype)
target_link_libraries(sofrenderer PRIVATE freetype)
# utf8.h
target_include_directories(sofrenderer PRIVATE "${PROJECT_SOURCE_DIR}/../external/utf8")