Created
August 8, 2016 21:00
-
-
Save evilactually/a0d191701cb48f157b05be7f74d79396 to your computer and use it in GitHub Desktop.
Compiling GLSL to SPIR-V from CMake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "AMD64") | |
set(GLSL_VALIDATOR "$ENV{VULKAN_SDK}/Bin/glslangValidator.exe") | |
else() | |
set(GLSL_VALIDATOR "$ENV{VULKAN_SDK}/Bin32/glslangValidator.exe") | |
endif() | |
file(GLOB_RECURSE GLSL_SOURCE_FILES | |
"shaders/*.frag" | |
"shaders/*.vert" | |
) | |
foreach(GLSL ${GLSL_SOURCE_FILES}) | |
get_filename_component(FILE_NAME ${GLSL} NAME) | |
set(SPIRV "${PROJECT_BINARY_DIR}/shaders/${FILE_NAME}.spv") | |
add_custom_command( | |
OUTPUT ${SPIRV} | |
COMMAND ${CMAKE_COMMAND} -E make_directory "${PROJECT_BINARY_DIR}/shaders/" | |
COMMAND ${GLSL_VALIDATOR} -V ${GLSL} -o ${SPIRV} | |
DEPENDS ${GLSL}) | |
list(APPEND SPIRV_BINARY_FILES ${SPIRV}) | |
endforeach(GLSL) | |
add_custom_target( | |
Shaders | |
DEPENDS ${SPIRV_BINARY_FILES} | |
) | |
add_dependencies(YourMainTarget Shaders) | |
add_custom_command(TARGET YourMainTarget POST_BUILD | |
COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_FILE_DIR:YourMainTarget>/shaders/" | |
COMMAND ${CMAKE_COMMAND} -E copy_directory | |
"${PROJECT_BINARY_DIR}/shaders" | |
"$<TARGET_FILE_DIR:YourMainTarget>/shaders" | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you, I learned something new today 🐔👍