Skip to content

Commit

Permalink
hello_imgui_bundle_assets_from_folder desktop: copy at build time
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Jan 7, 2024
1 parent 49d39b9 commit b2499bc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion hello_imgui_cmake/assets/him_assets_apple_bundle.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function(hello_imgui_apple_bundle_add_files_from_folder app_name assets_folder l
foreach(asset ${assets})
file(RELATIVE_PATH asset_relative ${assets_folder} ${asset})
get_filename_component(asset_dir ${asset_relative} DIRECTORY)
set_source_files_properties (
set_source_files_properties(
${asset}
PROPERTIES
MACOSX_PACKAGE_LOCATION ${location_in_bundle}/${asset_dir}
Expand Down
24 changes: 20 additions & 4 deletions hello_imgui_cmake/assets/him_assets_desktop.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
# - set the debugger working directory to the output directory (for Win32)


function(_do_copy_asset app_name src dst)
function(_do_install_asset app_name src dst)
hello_imgui_get_real_output_directory(${app_name} real_output_directory)

FILE(COPY "${src}" DESTINATION "${real_output_directory}/${dst}")
message(VERBOSE "_do_copy_asset=> FILE(COPY ${src} DESTINATION ${real_output_directory}/${dst})")
# # Copy at configure time
# FILE(COPY "${src}" DESTINATION "${real_output_directory}/${dst}")
# message(VERBOSE "_do_copy_asset=> FILE(COPY ${src} DESTINATION ${real_output_directory}/${dst})")

# Copy at install time
if (HELLOIMGUI_ADD_APP_WITH_INSTALL)
if (IS_DIRECTORY ${src})
install(DIRECTORY "${src}" DESTINATION "${CMAKE_INSTALL_PREFIX}/${dst}")
Expand All @@ -29,9 +31,23 @@ function(hello_imgui_bundle_assets_from_folder app_name assets_folder)
message(VERBOSE "hello_imgui_bundle_assets_from_folder ${app_name} ${assets_folder}")
FILE(GLOB children ${assets_folder}/*)
foreach(child ${children})
_do_copy_asset(${app_name} ${child} assets/)
# Will copy install time
_do_install_asset(${app_name} ${child} assets/)
endforeach()

# Copy at build time
if (true)
FILE(GLOB_RECURSE children_files_only LIST_DIRECTORIES false RELATIVE ${assets_folder} ${assets_folder}/*)
hello_imgui_get_real_output_directory(${app_name} real_output_directory)
set(dst_folder "${real_output_directory}/assets")
foreach(child ${children_files_only})
add_custom_command(TARGET ${app_name} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${assets_folder}/${child}"
"${dst_folder}/${child}")
endforeach ()
endif()

if (WIN32)
# Fix msvc quirk: set the debugger working dir to the exe dir!
hello_imgui_get_real_output_directory(${app_name} app_output_dir)
Expand Down
2 changes: 1 addition & 1 deletion src/hello_imgui/hello_imgui_font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ namespace HelloImGui
{
AssetFileData fontData = LoadAssetFileData(fontFilename.c_str());
font = ImGui_SensibleFont::AddFontFromMemoryTTF_2_KeepOwnership(
fontData.data, fontData.dataSize, fontSize, &params.fontConfig, glyphRangesImVector);
fontData.data, (int)fontData.dataSize, fontSize, &params.fontConfig, glyphRangesImVector);
FreeAssetFileData(&fontData);
}
else
Expand Down

0 comments on commit b2499bc

Please sign in to comment.