Skip to content

Commit

Permalink
Packed resources
Browse files Browse the repository at this point in the history
Dynamically load packed resources from a separate file. This
reduces amount of main memory required for linking stage.
  • Loading branch information
mymedia2 committed Jan 17, 2022
1 parent ba0f27e commit 90e1c25
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
7 changes: 7 additions & 0 deletions options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ if (DESKTOP_APP_USE_PACKAGED_RLOTTIE)
)
endif()

if (DESKTOP_APP_USE_PACKED_RESOURCES)
target_compile_definitions(common_options
INTERFACE
DESKTOP_APP_USE_PACKED_RESOURCES
)
endif()

if (NOT DESKTOP_APP_SPECIAL_TARGET STREQUAL "")
target_compile_definitions(common_options
INTERFACE
Expand Down
16 changes: 11 additions & 5 deletions target_prepare_qrc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# https://github.com/desktop-app/legal/blob/master/LEGAL

function(target_add_resource target_name)
set(list ${ARGV})
list(REMOVE_AT list 0)
set(list ${ARGN})

target_sources(${target_name} PRIVATE ${list})
get_target_property(existing_resources ${target_name} RESOURCE)
if (NOT "${existing_resources}" STREQUAL "existing_resources-NOTFOUND")
Expand All @@ -18,7 +18,13 @@ function(target_add_resource target_name)
endfunction()

function(target_prepare_qrc target_name)
if (NOT APPLE)
if (ARGC GREATER 1)
set(rcc_file ${ARGV1})
else()
set(rcc_file ${target_name}.rcc)
endif()

if (NOT DESKTOP_APP_USE_PACKED_RESOURCES)
set_target_properties(${target_name} PROPERTIES AUTORCC ON)
else()
set(rcc_flags --binary "$<TARGET_PROPERTY:${target_name},AUTORCC_OPTIONS>")
Expand All @@ -31,17 +37,17 @@ function(target_prepare_qrc target_name)
elseif (LINUX)
set(qrc_files "$<FILTER:${qrc_files_all},EXCLUDE,(win|mac|darwin|osx)\\.>")
endif()
set(rcc_file ${target_name}.rcc)
set(rcc_path "${CMAKE_BINARY_DIR}/${rcc_file}")
source_group(TREE ${CMAKE_BINARY_DIR} PREFIX Resources FILES ${rcc_path})
if (DESKTOP_APP_QT6)
set(rcc_binary Qt6::rcc)
else()
set(rcc_binary Qt5::rcc)
endif()
set(cmd_run "$<IF:$<BOOL:${qrc_files}>,,true>") # do nothing if qrc_files are empty
add_custom_command(OUTPUT ${rcc_path}
DEPENDS ${qrc_files}
COMMAND ${rcc_binary} ${rcc_flags} -o ${rcc_path} ${qrc_files}
COMMAND ${cmd_run} ${rcc_binary} ${rcc_flags} -o ${rcc_path} ${qrc_files}
COMMAND_EXPAND_LISTS VERBATIM
)
target_add_resource(${target_name} ${rcc_path})
Expand Down
1 change: 1 addition & 0 deletions variables.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ option(DESKTOP_APP_USE_ALLOCATION_TRACER "Use simple allocation tracer (Linux on
option(DESKTOP_APP_USE_PACKAGED_LAZY "Bundle recommended Qt plugins for self-contained packages. (Linux only)" OFF)
option(DESKTOP_APP_USE_PACKAGED_FONTS "Use preinstalled fonts instead of bundled patched ones." OFF)
option(DESKTOP_APP_USE_PACKAGED_RLOTTIE "Find rlottie using CMake instead of bundled patched one." OFF)
option(DESKTOP_APP_USE_PACKED_RESOURCES "Whether to pack resources into a separate archive." ${APPLE})
option(DESKTOP_APP_DISABLE_SPELLCHECK "Disable spellcheck library." OFF)
option(DESKTOP_APP_DISABLE_CRASH_REPORTS "Disable crash report generation." ${no_special_target})
option(DESKTOP_APP_DISABLE_AUTOUPDATE "Disable autoupdate." ${disable_autoupdate})
Expand Down

0 comments on commit 90e1c25

Please sign in to comment.