Skip to content

Commit fb9e39f

Browse files
committed
EmbedText make possible to chose between TEXT and BINARY formats when embedding files
1 parent 10f1524 commit fb9e39f

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ if (BUILD_CLIENT)
928928
)
929929

930930
# Generate GLSL include files.
931-
daemon_embed_files("EngineShaders" "GLSL" "client-objects")
931+
daemon_embed_files("EngineShaders" "GLSL" "TEXT" "client-objects")
932932
endif()
933933

934934
if (BUILD_SERVER)

cmake/DaemonSourceGenerator.cmake

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

cmake/EmbedText.cmake

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
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+
elseif("${FILE_FORMAT}" STREQUAL "BINARY")
15+
string(REGEX REPLACE "(..)" "0x\\1," contents "${contents}")
16+
else()
17+
message(FATAL_ERROR "Unknown file format: ${FILE_FORMAT}")
18+
endif()
19+
820
file(WRITE ${OUTPUT_FILE} "const unsigned char ${VARIABLE_NAME}[] = {${contents}};\n")

0 commit comments

Comments
 (0)