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