From 36c0af9953c7c00c0613a2126e203502cf69b941 Mon Sep 17 00:00:00 2001 From: veclavtalica Date: Sat, 8 Mar 2025 18:11:39 +0300 Subject: [PATCH] hopefully more portable way of packaging binary embeds --- CMakeLists.txt | 7 ++----- bin/prep-embed.sh | 8 ++++++++ 2 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 bin/prep-embed.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f8f21d..c3c452a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -364,11 +364,8 @@ target_link_libraries(${TWN_TARGET} PUBLIC add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/font.o WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMAND ${CMAKE_LINKER} --relocatable --format binary - --output ${CMAKE_CURRENT_BINARY_DIR}/font.o - share/assets/Dernyns256.ttf - DEPENDS share/assets/Dernyns256.ttf -) + COMMAND ${CMAKE_COMMAND} -E env CMAKE_CURRENT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR} sh bin/prep-embed.sh + DEPENDS share/assets/Dernyns256.ttf) add_custom_target(asset-compilation ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/font.o) diff --git a/bin/prep-embed.sh b/bin/prep-embed.sh new file mode 100644 index 0000000..60dda04 --- /dev/null +++ b/bin/prep-embed.sh @@ -0,0 +1,8 @@ +#!/bin/env sh +set -e +# packages embedded resources with objcopy, so that it is more portable +# ld.lld on windows doesn't recognize --format binary, sadly + +objdump=$(objdump -i) +bdfname=$(echo "$objdump" | sed -n 2p) +objcopy -I binary -O "$bdfname" share/assets/Dernyns256.ttf "$CMAKE_CURRENT_BINARY_DIR/font.o"