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