From 89d0938e8974673bb75542da9d41b664e494ef97 Mon Sep 17 00:00:00 2001 From: scawful Date: Sun, 28 Sep 2025 20:02:36 -0400 Subject: [PATCH] Enhance CMake configuration for asset management across platforms - Updated `CMakeLists.txt` to configure asset deployment for macOS, Windows, and Linux, ensuring proper handling of resource files based on the target platform. - Added custom build steps in `app.cmake` to copy asset files (fonts, themes, layouts, libraries) to the output directory for Windows and Linux builds, improving the build process and asset accessibility. - Organized asset files into source groups for better project structure and clarity. --- src/CMakeLists.txt | 43 ++++++++++++++++++++++++--- src/app/app.cmake | 73 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 4 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1212337e..86e50cc6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -35,13 +35,25 @@ set(YAZE_RESOURCE_FILES file(GLOB YAZE_THEME_FILES "${CMAKE_SOURCE_DIR}/assets/themes/*.theme") list(APPEND YAZE_RESOURCE_FILES ${YAZE_THEME_FILES}) +# Configure assets for different platforms foreach (FILE ${YAZE_RESOURCE_FILES}) file(RELATIVE_PATH NEW_FILE "${CMAKE_SOURCE_DIR}/assets" ${FILE}) get_filename_component(NEW_FILE_PATH ${NEW_FILE} DIRECTORY) - set_source_files_properties(${FILE} - PROPERTIES - MACOSX_PACKAGE_LOCATION "Resources/${NEW_FILE_PATH}" - ) + + if (APPLE) + # macOS: Set bundle location + set_source_files_properties(${FILE} + PROPERTIES + MACOSX_PACKAGE_LOCATION "Resources/${NEW_FILE_PATH}" + ) + else() + # Windows/Linux: Copy to output directory + set_source_files_properties(${FILE} + PROPERTIES + VS_DEPLOYMENT_CONTENT 1 + VS_DEPLOYMENT_LOCATION "assets/${NEW_FILE_PATH}" + ) + endif() endforeach() # Conditionally add native file dialog (optional for CI builds) @@ -671,3 +683,26 @@ source_group("Platform\\iOS\\Assets" FILES source_group("Configuration" FILES yaze_config.h.in ) + +# Assets +source_group("Assets\\Fonts" FILES + ${CMAKE_SOURCE_DIR}/assets/font/Karla-Regular.ttf + ${CMAKE_SOURCE_DIR}/assets/font/Roboto-Medium.ttf + ${CMAKE_SOURCE_DIR}/assets/font/Cousine-Regular.ttf + ${CMAKE_SOURCE_DIR}/assets/font/DroidSans.ttf + ${CMAKE_SOURCE_DIR}/assets/font/NotoSansJP.ttf + ${CMAKE_SOURCE_DIR}/assets/font/IBMPlexSansJP-Bold.ttf + ${CMAKE_SOURCE_DIR}/assets/font/MaterialIcons-Regular.ttf +) + +source_group("Assets\\Themes" FILES + ${YAZE_THEME_FILES} +) + +source_group("Assets\\Layouts" FILES + ${CMAKE_SOURCE_DIR}/assets/layouts/ow_toolset.zeml +) + +source_group("Assets\\Library" FILES + ${CMAKE_SOURCE_DIR}/assets/lib/libasar.dll +) diff --git a/src/app/app.cmake b/src/app/app.cmake index 9bf81132..69adbf08 100644 --- a/src/app/app.cmake +++ b/src/app/app.cmake @@ -53,6 +53,25 @@ else() ${YAZE_GUI_SRC} ${IMGUI_SRC} ) + + # Add asset files for Windows/Linux builds + if(WIN32 OR LINUX) + target_sources(yaze PRIVATE ${YAZE_RESOURCE_FILES}) + + # Set up asset deployment for Visual Studio + if(WIN32) + foreach(ASSET_FILE ${YAZE_RESOURCE_FILES}) + file(RELATIVE_PATH ASSET_REL_PATH "${CMAKE_SOURCE_DIR}/assets" ${ASSET_FILE}) + get_filename_component(ASSET_DIR ${ASSET_REL_PATH} DIRECTORY) + + set_source_files_properties(${ASSET_FILE} + PROPERTIES + VS_DEPLOYMENT_CONTENT 1 + VS_DEPLOYMENT_LOCATION "assets/${ASSET_DIR}" + ) + endforeach() + endif() + endif() endif() target_include_directories( @@ -138,3 +157,57 @@ if (APPLE) target_link_libraries(yaze PUBLIC ${COCOA_LIBRARY}) endif() +# Post-build step to copy assets to output directory (Windows/Linux) +if(NOT APPLE) + # Create custom target for copying assets + add_custom_target(copy_assets ALL + COMMENT "Copying assets to output directory" + ) + + # Copy fonts + add_custom_command(TARGET copy_assets POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory + $/assets/font + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${CMAKE_SOURCE_DIR}/assets/font + $/assets/font + COMMENT "Copying font assets" + ) + + # Copy themes + add_custom_command(TARGET copy_assets POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory + $/assets/themes + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${CMAKE_SOURCE_DIR}/assets/themes + $/assets/themes + COMMENT "Copying theme assets" + ) + + # Copy other assets if they exist + if(EXISTS ${CMAKE_SOURCE_DIR}/assets/layouts) + add_custom_command(TARGET copy_assets POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory + $/assets/layouts + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${CMAKE_SOURCE_DIR}/assets/layouts + $/assets/layouts + COMMENT "Copying layout assets" + ) + endif() + + if(EXISTS ${CMAKE_SOURCE_DIR}/assets/lib) + add_custom_command(TARGET copy_assets POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory + $/assets/lib + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${CMAKE_SOURCE_DIR}/assets/lib + $/assets/lib + COMMENT "Copying library assets" + ) + endif() + + # Make the main target depend on asset copying + add_dependencies(yaze copy_assets) +endif() +