| 1 | |
| 2 | # must define SHADER_COMP_HEADER SHADER_SRC |
| 3 | |
| 4 | file(READ ${SHADER_SRC} comp_data) |
| 5 | |
| 6 | # skip leading comment |
| 7 | string(FIND "${comp_data}" "#version" version_start) |
| 8 | if(NOT ${version_start} EQUAL -1) |
| 9 | string(SUBSTRING "${comp_data}" ${version_start} -1 comp_data) |
| 10 | endif() |
| 11 | |
| 12 | # remove whitespace |
| 13 | string(REGEX REPLACE "\n +" "\n" comp_data "${comp_data}") |
| 14 | |
| 15 | # remove empty line |
| 16 | string(REGEX REPLACE "\n\n" "\n" comp_data "${comp_data}") |
| 17 | |
| 18 | get_filename_component(SHADER_SRC_NAME_WE ${SHADER_SRC} NAME_WE) |
| 19 | |
| 20 | # text to hex |
| 21 | file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/layer/vulkan/shader/${SHADER_SRC_NAME_WE}.text2hex.txt "${comp_data}") |
| 22 | file(READ ${CMAKE_CURRENT_BINARY_DIR}/layer/vulkan/shader/${SHADER_SRC_NAME_WE}.text2hex.txt comp_data_hex HEX) |
| 23 | string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," comp_data_hex ${comp_data_hex}) |
| 24 | string(FIND "${comp_data_hex}" "," tail_comma REVERSE) |
| 25 | string(SUBSTRING "${comp_data_hex}" 0 ${tail_comma} comp_data_hex) |
| 26 | |
| 27 | file(WRITE ${SHADER_COMP_HEADER} "static const char ${SHADER_SRC_NAME_WE}_comp_data[] = {${comp_data_hex}};\n") |