cmake: fix non portable code
This commit is contained in:
parent
0a1ddc2eff
commit
7359d51d56
|
@ -28,6 +28,19 @@
|
||||||
|
|
||||||
set(GENERATED_SOURCES "")
|
set(GENERATED_SOURCES "")
|
||||||
|
|
||||||
|
set(GENERATOR "${CMAKE_CURRENT_BINARY_DIR}/blocks_generator.cmake")
|
||||||
|
file(GENERATE OUTPUT ${GENERATOR} CONTENT [=[
|
||||||
|
file(READ "${INPUT_DAT_FILE}" DATA HEX)
|
||||||
|
string(REGEX REPLACE "[0-9a-fA-F][0-9a-fA-F]" "0x\\0," DATA "${DATA}")
|
||||||
|
file(WRITE "${OUTPUT_C_SOURCE}" "
|
||||||
|
#include <stddef.h>
|
||||||
|
const unsigned char ${BLOB_NAME}[]={
|
||||||
|
${DATA}
|
||||||
|
};
|
||||||
|
const size_t ${BLOB_NAME}_len = sizeof(${BLOB_NAME});
|
||||||
|
"
|
||||||
|
)
|
||||||
|
]=])
|
||||||
foreach(BLOB_NAME checkpoints testnet_blocks stagenet_blocks)
|
foreach(BLOB_NAME checkpoints testnet_blocks stagenet_blocks)
|
||||||
set(OUTPUT_C_SOURCE "generated_${BLOB_NAME}.c")
|
set(OUTPUT_C_SOURCE "generated_${BLOB_NAME}.c")
|
||||||
list(APPEND GENERATED_SOURCES ${OUTPUT_C_SOURCE})
|
list(APPEND GENERATED_SOURCES ${OUTPUT_C_SOURCE})
|
||||||
|
@ -35,13 +48,12 @@ foreach(BLOB_NAME checkpoints testnet_blocks stagenet_blocks)
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${OUTPUT_C_SOURCE}
|
OUTPUT ${OUTPUT_C_SOURCE}
|
||||||
MAIN_DEPENDENCY ${INPUT_DAT_FILE}
|
MAIN_DEPENDENCY ${INPUT_DAT_FILE}
|
||||||
COMMAND
|
DEPENDS ${GENERATOR}
|
||||||
cd ${CMAKE_CURRENT_BINARY_DIR} &&
|
COMMAND ${CMAKE_COMMAND}
|
||||||
echo "'#include\t<stddef.h>'" > ${OUTPUT_C_SOURCE} &&
|
"-DINPUT_DAT_FILE=${CMAKE_CURRENT_SOURCE_DIR}/${INPUT_DAT_FILE}"
|
||||||
echo "'const\tunsigned\tchar\t${BLOB_NAME}[]={'" >> ${OUTPUT_C_SOURCE} &&
|
"-DBLOB_NAME=${BLOB_NAME}"
|
||||||
od -v -An -tx1 ${CMAKE_CURRENT_SOURCE_DIR}/${INPUT_DAT_FILE} | sed -e "'s/[0-9a-fA-F]\\{1,\\}/0x&,/g'" -e "'$$s/.$$//'" >> ${OUTPUT_C_SOURCE} &&
|
"-DOUTPUT_C_SOURCE=${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_C_SOURCE}"
|
||||||
echo "'};'" >> ${OUTPUT_C_SOURCE} &&
|
"-P${GENERATOR}"
|
||||||
echo "'const\tsize_t\t${BLOB_NAME}_len\t=\tsizeof(${BLOB_NAME});'" >> ${OUTPUT_C_SOURCE}
|
|
||||||
)
|
)
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue