Transform shader sources to header files
This commit is contained in:
14
shaders/CMakeLists.txt
Normal file
14
shaders/CMakeLists.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
project(Couch)
|
||||
|
||||
file(GLOB shaders *.vert *.frag)
|
||||
list(
|
||||
TRANSFORM shaders
|
||||
APPEND .h
|
||||
OUTPUT_VARIABLE shader_header_files)
|
||||
|
||||
add_custom_target(shader_headers
|
||||
BYPRODUCTS ${shader_header_files}
|
||||
COMMAND perl "${CMAKE_CURRENT_SOURCE_DIR}/makeheaders.pl"
|
||||
DEPENDS ${shaders} ${CMAKE_CURRENT_SOURCE_DIR}/makeheaders.pl)
|
||||
|
||||
add_dependencies(couch shader_headers)
|
||||
33
shaders/makeheaders.pl
Normal file
33
shaders/makeheaders.pl
Normal file
@@ -0,0 +1,33 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub convert {
|
||||
my $filename = $1;
|
||||
|
||||
my $headerguard = "$filename.h";
|
||||
$headerguard =~ tr/a-z./A-Z_/;
|
||||
|
||||
my $constname = "$filename";
|
||||
$constname =~ tr/./_/;
|
||||
|
||||
open my $fin, '<', $filename;
|
||||
open my $fout, '>', "$filename.h";
|
||||
|
||||
print $fout "#ifndef $headerguard \n#define $headerguard\nconst char * $constname = \n";
|
||||
|
||||
while(my $line = <$fin>) {
|
||||
$line =~ s/\n/\\n/;
|
||||
print $fout "\"$line\"\n";
|
||||
}
|
||||
|
||||
print $fout ";\n#endif // $headerguard\n";
|
||||
close $fin;
|
||||
close $fout;
|
||||
}
|
||||
|
||||
opendir DIR, ".";
|
||||
while (readdir DIR) {
|
||||
if (/(.*\.(frag|vert))/) {
|
||||
convert;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user