Skip to content

Commit 60849b7

Browse files
CMake: move convert_shaders_to_headers from FX
1 parent 6d04ee5 commit 60849b7

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

BuildTools/CMake/BuildUtils.cmake

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,3 +583,51 @@ function(target_link_whole_archive tgt lib)
583583
endif()
584584
endif()
585585
endfunction()
586+
587+
588+
# Converts shaders to headers and generates master header with the list of all files
589+
function(convert_shaders_to_headers _SHADERS _SHADER_OUTPUT_DIR _SHADERS_LIST_FILE _SHADERS_INC_LIST)
590+
if(NOT FILE2STRING_PATH STREQUAL "")
591+
find_package(Python3 REQUIRED)
592+
593+
file(MAKE_DIRECTORY ${_SHADER_OUTPUT_DIR})
594+
595+
file(WRITE ${_SHADERS_LIST_FILE}
596+
"static const MemoryShaderSourceFileInfo g_Shaders[] =\n"
597+
"{"
598+
)
599+
600+
foreach(FILE ${_SHADERS})
601+
get_filename_component(FILE_NAME ${FILE} NAME)
602+
set(CONVERTED_FILE ${_SHADER_OUTPUT_DIR}/${FILE_NAME}.h)
603+
add_custom_command(OUTPUT ${CONVERTED_FILE}
604+
COMMAND ${Python3_EXECUTABLE} ${FILE2STRING_PATH} ${FILE} ${CONVERTED_FILE} --strip-comments
605+
DEPENDS ${FILE}
606+
COMMENT "Processing shader ${FILE}"
607+
VERBATIM)
608+
609+
string(REPLACE "." "_" VAR_NAME "${FILE_NAME}")
610+
file(APPEND ${_SHADERS_LIST_FILE}
611+
"\n {"
612+
"\n \"${FILE_NAME}\","
613+
"\n #include \"${FILE_NAME}.h\""
614+
"\n },"
615+
)
616+
617+
list(APPEND SHADERS_INC_LIST ${CONVERTED_FILE})
618+
endforeach()
619+
620+
file(APPEND ${_SHADERS_LIST_FILE}
621+
"\n};\n"
622+
)
623+
624+
set_source_files_properties(
625+
${SHADERS_INC_LIST}
626+
PROPERTIES GENERATED TRUE
627+
)
628+
629+
set(${_SHADERS_INC_LIST} ${SHADERS_INC_LIST} PARENT_SCOPE)
630+
else()
631+
message(WARNING "File2String utility is currently unavailable on this host system. This is not an issues unless you modify shaders")
632+
endif()
633+
endfunction()

0 commit comments

Comments
 (0)