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.
This commit is contained in:
scawful
2025-09-28 20:02:36 -04:00
parent 2b50678cc5
commit 89d0938e89
2 changed files with 112 additions and 4 deletions

View File

@@ -35,13 +35,25 @@ set(YAZE_RESOURCE_FILES
file(GLOB YAZE_THEME_FILES "${CMAKE_SOURCE_DIR}/assets/themes/*.theme") file(GLOB YAZE_THEME_FILES "${CMAKE_SOURCE_DIR}/assets/themes/*.theme")
list(APPEND YAZE_RESOURCE_FILES ${YAZE_THEME_FILES}) list(APPEND YAZE_RESOURCE_FILES ${YAZE_THEME_FILES})
# Configure assets for different platforms
foreach (FILE ${YAZE_RESOURCE_FILES}) foreach (FILE ${YAZE_RESOURCE_FILES})
file(RELATIVE_PATH NEW_FILE "${CMAKE_SOURCE_DIR}/assets" ${FILE}) file(RELATIVE_PATH NEW_FILE "${CMAKE_SOURCE_DIR}/assets" ${FILE})
get_filename_component(NEW_FILE_PATH ${NEW_FILE} DIRECTORY) get_filename_component(NEW_FILE_PATH ${NEW_FILE} DIRECTORY)
set_source_files_properties(${FILE}
PROPERTIES if (APPLE)
MACOSX_PACKAGE_LOCATION "Resources/${NEW_FILE_PATH}" # 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() endforeach()
# Conditionally add native file dialog (optional for CI builds) # Conditionally add native file dialog (optional for CI builds)
@@ -671,3 +683,26 @@ source_group("Platform\\iOS\\Assets" FILES
source_group("Configuration" FILES source_group("Configuration" FILES
yaze_config.h.in 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
)

View File

@@ -53,6 +53,25 @@ else()
${YAZE_GUI_SRC} ${YAZE_GUI_SRC}
${IMGUI_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() endif()
target_include_directories( target_include_directories(
@@ -138,3 +157,57 @@ if (APPLE)
target_link_libraries(yaze PUBLIC ${COCOA_LIBRARY}) target_link_libraries(yaze PUBLIC ${COCOA_LIBRARY})
endif() 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
$<TARGET_FILE_DIR:yaze>/assets/font
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/assets/font
$<TARGET_FILE_DIR:yaze>/assets/font
COMMENT "Copying font assets"
)
# Copy themes
add_custom_command(TARGET copy_assets POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory
$<TARGET_FILE_DIR:yaze>/assets/themes
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/assets/themes
$<TARGET_FILE_DIR:yaze>/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
$<TARGET_FILE_DIR:yaze>/assets/layouts
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/assets/layouts
$<TARGET_FILE_DIR:yaze>/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
$<TARGET_FILE_DIR:yaze>/assets/lib
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/assets/lib
$<TARGET_FILE_DIR:yaze>/assets/lib
COMMENT "Copying library assets"
)
endif()
# Make the main target depend on asset copying
add_dependencies(yaze copy_assets)
endif()