Skip to content

Commit 2c24a63

Browse files
committed
EmbedText make possible to chose between TEXT and BINARY formats when embedding files
1 parent 2ebdaaa commit 2c24a63

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ if (BUILD_CLIENT)
10381038
)
10391039

10401040
# Generate GLSL include files.
1041-
daemon_embed_files("EngineShaders" "GLSL" "client-objects")
1041+
daemon_embed_files("EngineShaders" "GLSL" "TEXT" "client-objects")
10421042
endif()
10431043

10441044
if (BUILD_SERVER)

cmake/DaemonSourceGenerator.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ macro(daemon_embed_files BASENAME SLUG FORMAT TARGETNAME)
7979
COMMAND ${CMAKE_COMMAND}
8080
"-DINPUT_FILE=${inpath}"
8181
"-DOUTPUT_FILE=${outpath}"
82+
"-DFILE_FORMAT=${FORMAT}"
8283
"-DVARIABLE_NAME=${filename_symbol}"
8384
-P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/EmbedText.cmake"
8485
MAIN_DEPENDENCY ${inpath}

cmake/EmbedText.cmake

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
# Converts a text file into a C-language char array definition.
22
# For use in CMake script mode (cmake -P).
3-
# Required definitions on command line: INPUT_FILE, OUTPUT_FILE, VARIABLE_NAME
3+
# Required definitions on command line:
4+
# INPUT_FILE, OUTPUT_FILE, FILE_FORMAT, VARIABLE_NAME
5+
6+
# Inspired by:
7+
# https://stackoverflow.com/questions/11813271/embed-resources-eg-shader-code-images-into-executable-library-with-cmake/27206982#27206982
48

5-
# Inspired by https://stackoverflow.com/questions/11813271/embed-resources-eg-shader-code-images-into-executable-library-with-cmake/27206982#27206982
69
file(READ ${INPUT_FILE} contents HEX)
7-
string(REGEX REPLACE "(0d)?(..)" "0x\\2," contents ${contents}) # Strip \r for consistency
10+
11+
if ("${FILE_FORMAT}" STREQUAL "TEXT")
12+
# Strip \r for consistency
13+
string(REGEX REPLACE "(0d)?(..)" "0x\\2," contents ${contents})
14+
else()
15+
string(REGEX REPLACE "(..)" "0x\\1," contents ${contents})
16+
endif()
17+
818
file(WRITE ${OUTPUT_FILE} "const unsigned char ${VARIABLE_NAME}[] = {${contents}};\n")

0 commit comments

Comments
 (0)