Transform shader sources to header files

This commit is contained in:
Dane Johnson
2021-01-17 18:03:09 -06:00
parent 5e8d693758
commit 0f3dbdff64
8 changed files with 59 additions and 43 deletions

14
shaders/CMakeLists.txt Normal file
View 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
View 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;
}
}