Skip to content

Commit

Permalink
cmake_xxd: fix build on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
a.borisov committed Dec 29, 2021
1 parent 92a8edd commit 0ccd97d
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions CMakeXxdImpl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
# INPUT_FILE_NAME - file name
# FILE_TYPE - "TEXT" or "BIN"

if("${TMP_DIR}" STREQUAL "")
set(XXD_TMP_DIR ".")
else()
set(XXD_TMP_DIR "${TMP_DIR}")
endif()


get_filename_component(INPUT_SRC ${INPUT_FILE_NAME} ABSOLUTE)
get_filename_component(INPUT_DIR ${INPUT_SRC} DIRECTORY)
get_filename_component(INPUT_NAME ${INPUT_FILE_NAME} NAME)
Expand All @@ -25,18 +32,18 @@ endif()
string(REGEX MATCHALL "([^,;]*,)([^,;]*,)?([^,;]*,)?([^,;]*,)?([^,;]*,)?([^,;]*,)?([^,;]*,)?([^,;]*,)?"
SEPARATED_LINES "${FORMATTED_HEX}, ")
list(JOIN SEPARATED_LINES "\n" FORMATTED_HEX)
file(WRITE ${TMP_DIR}/${INPUT_NAME}.inc.temp "static unsigned char ${CPP_STR_CONST_NAME}[] = {\n${FORMATTED_HEX}\n};\n")
file(READ ${TMP_DIR}/${INPUT_NAME}.inc.temp TEMP_CONTENT HEX)
file(WRITE ${XXD_TMP_DIR}/${INPUT_NAME}.inc.temp "static unsigned char ${CPP_STR_CONST_NAME}[] = {\n${FORMATTED_HEX}\n};\n")
file(READ ${XXD_TMP_DIR}/${INPUT_NAME}.inc.temp TEMP_CONTENT HEX)
if(EXISTS ${INPUT_DIR}/${INPUT_NAME}.inc)
file(READ ${INPUT_DIR}/${INPUT_NAME}.inc DEST_CONTENT HEX)
else()
set(DEST_CONTENT "")
endif()
if(NOT "${TEMP_CONTENT}" STREQUAL "${DEST_CONTENT}")
file(REMOVE ${INPUT_DIR}/${INPUT_NAME}.inc)
file(RENAME ${TMP_DIR}/${INPUT_NAME}.inc.temp ${INPUT_DIR}/${INPUT_NAME}.inc)
file(RENAME ${XXD_TMP_DIR}/${INPUT_NAME}.inc.temp ${INPUT_DIR}/${INPUT_NAME}.inc)
message(STATUS "File ${INPUT_FILE_NAME} converted to C-array ${INPUT_DIR}/${INPUT_NAME}.inc")
else()
file(REMOVE ${TMP_DIR}/${INPUT_NAME}.inc.temp)
file(REMOVE ${XXD_TMP_DIR}/${INPUT_NAME}.inc.temp)
message(STATUS "File is not changed. Generation skipped.")
endif()

0 comments on commit 0ccd97d

Please sign in to comment.