Skip to content

Instantly share code, notes, and snippets.

@christophercrouzet
Created August 5, 2014 13:00
Show Gist options
  • Save christophercrouzet/67de1b021e0c471c7c3b to your computer and use it in GitHub Desktop.
Save christophercrouzet/67de1b021e0c471c7c3b to your computer and use it in GitHub Desktop.
Command to format GLSL shaders with CMake for inclusion in C++
separate_arguments(FILES)
foreach (file ${FILES})
if (LOAD_SHADERS_DYNAMICALLY)
file(
COPY ${SOURCE_DIR}/${file}
DESTINATION ${DESTINATION_DIR}
)
else()
set(filename ${SOURCE_DIR}/${file})
get_filename_component(name ${filename} NAME_WE)
get_filename_component(extension ${filename} EXT)
set(source "")
file(STRINGS ${filename} lines)
foreach (line ${lines})
set(source "${source} \"${line}\\n\"\n")
endforeach()
file(
WRITE ${DESTINATION_DIR}/${file}
"static const GLchar *${name}ShaderSource[] = {\n"
"${source}"
"};\n"
)
endif()
endforeach()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment