From 5b3e80f4fcd1f5f34699b295c62a8ad5d6bf8579 Mon Sep 17 00:00:00 2001 From: zhenyan121 <3367366583@qq.com> Date: Thu, 11 Dec 2025 16:49:18 +0800 Subject: [PATCH] Added functionality to automatically copy the assets folder to the output directory after build --- CMakeLists.txt | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 87d9de9..0dda1fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,11 @@ set(SOURCE_FILES src/graphics/GameRenderer.cpp src/graphics/CoordinateConverter.cpp src/utils/CoordinateTools.cpp + src/graphics/font/FontManager.cpp + src/graphics/font/TextRenderer.cpp + src/ui/components/Button.cpp + src/ui/managers/GameUIManager.cpp + src/graphics/ui/UIRenderer.cpp ) @@ -87,4 +92,32 @@ if (WIN32) $ COMMENT "Copying SDL3 runtime DLLs" ) + + + + +# ========== 仅复制修改过的 assets ========== +set(ASSETS_SRC_DIR "${CMAKE_SOURCE_DIR}/assets") +set(ASSETS_DST_DIR "$/assets") + +# 收集所有 asset 文件 +file(GLOB_RECURSE ASSET_FILES + "${ASSETS_SRC_DIR}/*" +) + +# 为每个文件生成复制规则 +foreach(ASSET_FILE ${ASSET_FILES}) + # 计算目标路径 + file(RELATIVE_PATH REL_PATH "${ASSETS_SRC_DIR}" "${ASSET_FILE}") + set(OUT_FILE "${ASSETS_DST_DIR}/${REL_PATH}") + + add_custom_command( + TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory + "$/assets" + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "${ASSET_FILE}" "${OUT_FILE}" + COMMENT "Copying changed asset: ${REL_PATH}" + ) +endforeach() endif()