From 39364bdda43d307af8836743227d278d4bb7525e Mon Sep 17 00:00:00 2001 From: William Marlow Date: Sun, 20 Dec 2020 18:26:09 +0000 Subject: [PATCH] Build: Embed application icons directly in the executables. New serenity_app() targets can be defined which allows application icons to be emedded directly into the executable. The embedded icons will then be used when creating an icon for that file in LibGUI. --- Applications/Browser/CMakeLists.txt | 2 +- Applications/Calculator/CMakeLists.txt | 2 +- Applications/Calendar/CMakeLists.txt | 2 +- Applications/DisplaySettings/CMakeLists.txt | 2 +- Applications/FileManager/CMakeLists.txt | 2 +- Applications/FontEditor/CMakeLists.txt | 2 +- Applications/Help/CMakeLists.txt | 2 +- Applications/HexEditor/CMakeLists.txt | 2 +- Applications/IRCClient/CMakeLists.txt | 2 +- Applications/KeyboardSettings/CMakeLists.txt | 2 +- Applications/Piano/CMakeLists.txt | 2 +- Applications/PixelPaint/CMakeLists.txt | 2 +- Applications/QuickShow/CMakeLists.txt | 2 +- Applications/SoundPlayer/CMakeLists.txt | 2 +- Applications/Spreadsheet/CMakeLists.txt | 2 +- Applications/SystemMonitor/CMakeLists.txt | 2 +- Applications/Terminal/CMakeLists.txt | 2 +- Applications/TextEditor/CMakeLists.txt | 2 +- Applications/ThemeEditor/CMakeLists.txt | 2 +- CMakeLists.txt | 30 ++++++++++++++++++++ Demos/Cube/CMakeLists.txt | 2 +- Demos/Eyes/CMakeLists.txt | 2 +- Demos/Fire/CMakeLists.txt | 2 +- Demos/HelloWorld/CMakeLists.txt | 2 +- Demos/LibGfxDemo/CMakeLists.txt | 2 +- Demos/Mouse/CMakeLists.txt | 2 +- Demos/Screensaver/CMakeLists.txt | 2 +- Demos/WidgetGallery/CMakeLists.txt | 2 +- DevTools/HackStudio/CMakeLists.txt | 2 +- DevTools/Inspector/CMakeLists.txt | 2 +- DevTools/Profiler/CMakeLists.txt | 2 +- Games/2048/CMakeLists.txt | 2 +- Games/Breakout/CMakeLists.txt | 2 +- Games/Chess/CMakeLists.txt | 2 +- Games/Minesweeper/CMakeLists.txt | 2 +- Games/Pong/CMakeLists.txt | 2 +- Games/Snake/CMakeLists.txt | 2 +- Games/Solitaire/CMakeLists.txt | 2 +- Meta/generate-embedded-resource-assembly.sh | 27 ++++++++++++++++++ 39 files changed, 94 insertions(+), 37 deletions(-) create mode 100755 Meta/generate-embedded-resource-assembly.sh diff --git a/Applications/Browser/CMakeLists.txt b/Applications/Browser/CMakeLists.txt index 8594c00d61..4652ec8b11 100644 --- a/Applications/Browser/CMakeLists.txt +++ b/Applications/Browser/CMakeLists.txt @@ -15,5 +15,5 @@ set(SOURCES TabGML.h ) -serenity_bin(Browser) +serenity_app(Browser ICON app-browser) target_link_libraries(Browser LibWeb LibProtocol LibGUI LibDesktop) diff --git a/Applications/Calculator/CMakeLists.txt b/Applications/Calculator/CMakeLists.txt index 548c37b774..8c5c14feaf 100644 --- a/Applications/Calculator/CMakeLists.txt +++ b/Applications/Calculator/CMakeLists.txt @@ -5,5 +5,5 @@ set(SOURCES Keypad.cpp ) -serenity_bin(Calculator) +serenity_app(Calculator ICON app-calculator) target_link_libraries(Calculator LibGUI) diff --git a/Applications/Calendar/CMakeLists.txt b/Applications/Calendar/CMakeLists.txt index 77fbce1675..c23a6743cc 100644 --- a/Applications/Calendar/CMakeLists.txt +++ b/Applications/Calendar/CMakeLists.txt @@ -3,5 +3,5 @@ set(SOURCES main.cpp ) -serenity_bin(Calendar) +serenity_app(Calendar ICON app-calendar) target_link_libraries(Calendar LibGUI) diff --git a/Applications/DisplaySettings/CMakeLists.txt b/Applications/DisplaySettings/CMakeLists.txt index b5d2162f9d..af736e83a8 100644 --- a/Applications/DisplaySettings/CMakeLists.txt +++ b/Applications/DisplaySettings/CMakeLists.txt @@ -4,5 +4,5 @@ set(SOURCES MonitorWidget.cpp ) -serenity_bin(DisplaySettings) +serenity_app(DisplaySettings ICON app-display-settings) target_link_libraries(DisplaySettings LibGUI) diff --git a/Applications/FileManager/CMakeLists.txt b/Applications/FileManager/CMakeLists.txt index b0bfcabee3..f650c97402 100644 --- a/Applications/FileManager/CMakeLists.txt +++ b/Applications/FileManager/CMakeLists.txt @@ -9,5 +9,5 @@ set(SOURCES PropertiesDialog.cpp ) -serenity_bin(FileManager) +serenity_app(FileManager ICON filetype-folder) target_link_libraries(FileManager LibGUI LibDesktop) diff --git a/Applications/FontEditor/CMakeLists.txt b/Applications/FontEditor/CMakeLists.txt index 0c39433507..079b7a521a 100644 --- a/Applications/FontEditor/CMakeLists.txt +++ b/Applications/FontEditor/CMakeLists.txt @@ -7,5 +7,5 @@ set(SOURCES main.cpp ) -serenity_bin(FontEditor) +serenity_app(FontEditor ICON app-font-editor) target_link_libraries(FontEditor LibGUI LibGfx) diff --git a/Applications/Help/CMakeLists.txt b/Applications/Help/CMakeLists.txt index 8d1a5038e2..46a832c044 100644 --- a/Applications/Help/CMakeLists.txt +++ b/Applications/Help/CMakeLists.txt @@ -6,5 +6,5 @@ set(SOURCES ManualSectionNode.cpp ) -serenity_bin(Help) +serenity_app(Help ICON app-help) target_link_libraries(Help LibWeb LibMarkdown LibGUI LibDesktop) diff --git a/Applications/HexEditor/CMakeLists.txt b/Applications/HexEditor/CMakeLists.txt index 3de7c9cfb5..ebe134863f 100644 --- a/Applications/HexEditor/CMakeLists.txt +++ b/Applications/HexEditor/CMakeLists.txt @@ -4,5 +4,5 @@ set(SOURCES main.cpp ) -serenity_bin(HexEditor) +serenity_app(HexEditor ICON app-hexeditor) target_link_libraries(HexEditor LibGUI) diff --git a/Applications/IRCClient/CMakeLists.txt b/Applications/IRCClient/CMakeLists.txt index 6f304b18c1..3926bbd5dc 100644 --- a/Applications/IRCClient/CMakeLists.txt +++ b/Applications/IRCClient/CMakeLists.txt @@ -10,5 +10,5 @@ set(SOURCES main.cpp ) -serenity_bin(IRCClient) +serenity_app(IRCClient ICON app-irc-client) target_link_libraries(IRCClient LibWeb LibGUI) diff --git a/Applications/KeyboardSettings/CMakeLists.txt b/Applications/KeyboardSettings/CMakeLists.txt index 54f5ea70aa..62212cda36 100644 --- a/Applications/KeyboardSettings/CMakeLists.txt +++ b/Applications/KeyboardSettings/CMakeLists.txt @@ -2,5 +2,5 @@ set(SOURCES main.cpp ) -serenity_bin(KeyboardSettings) +serenity_app(KeyboardSettings ICON app-keyboard-settings) target_link_libraries(KeyboardSettings LibGUI LibKeyboard) diff --git a/Applications/Piano/CMakeLists.txt b/Applications/Piano/CMakeLists.txt index 6756afb18c..382e023c3b 100644 --- a/Applications/Piano/CMakeLists.txt +++ b/Applications/Piano/CMakeLists.txt @@ -10,5 +10,5 @@ set(SOURCES WaveWidget.cpp ) -serenity_bin(Piano) +serenity_app(Piano ICON app-piano) target_link_libraries(Piano LibAudio LibGUI) diff --git a/Applications/PixelPaint/CMakeLists.txt b/Applications/PixelPaint/CMakeLists.txt index 73e2196ca7..713845c80e 100644 --- a/Applications/PixelPaint/CMakeLists.txt +++ b/Applications/PixelPaint/CMakeLists.txt @@ -23,5 +23,5 @@ set(SOURCES Tool.cpp ) -serenity_bin(PixelPaint) +serenity_app(PixelPaint ICON app-pixel-paint) target_link_libraries(PixelPaint LibGUI LibGfx) diff --git a/Applications/QuickShow/CMakeLists.txt b/Applications/QuickShow/CMakeLists.txt index c0f9a05e6b..8d2b46e217 100644 --- a/Applications/QuickShow/CMakeLists.txt +++ b/Applications/QuickShow/CMakeLists.txt @@ -3,5 +3,5 @@ set(SOURCES QSWidget.cpp ) -serenity_bin(QuickShow) +serenity_app(QuickShow ICON filetype-image) target_link_libraries(QuickShow LibGUI LibGfx) diff --git a/Applications/SoundPlayer/CMakeLists.txt b/Applications/SoundPlayer/CMakeLists.txt index 6c71842cd3..99e1da4653 100644 --- a/Applications/SoundPlayer/CMakeLists.txt +++ b/Applications/SoundPlayer/CMakeLists.txt @@ -5,5 +5,5 @@ set(SOURCES SoundPlayerWidget.cpp ) -serenity_bin(SoundPlayer) +serenity_app(SoundPlayer ICON app-sound-player) target_link_libraries(SoundPlayer LibAudio LibGUI) diff --git a/Applications/Spreadsheet/CMakeLists.txt b/Applications/Spreadsheet/CMakeLists.txt index ea0054dc7b..f41922655a 100644 --- a/Applications/Spreadsheet/CMakeLists.txt +++ b/Applications/Spreadsheet/CMakeLists.txt @@ -24,5 +24,5 @@ set(SOURCES main.cpp ) -serenity_bin(Spreadsheet) +serenity_app(Spreadsheet ICON app-spreadsheet) target_link_libraries(Spreadsheet LibGUI LibJS LibWeb) diff --git a/Applications/SystemMonitor/CMakeLists.txt b/Applications/SystemMonitor/CMakeLists.txt index bf078096cd..ee2e4d2323 100644 --- a/Applications/SystemMonitor/CMakeLists.txt +++ b/Applications/SystemMonitor/CMakeLists.txt @@ -12,5 +12,5 @@ set(SOURCES ThreadStackWidget.cpp ) -serenity_bin(SystemMonitor) +serenity_app(SystemMonitor ICON app-system-monitor) target_link_libraries(SystemMonitor LibGUI LibPCIDB) diff --git a/Applications/Terminal/CMakeLists.txt b/Applications/Terminal/CMakeLists.txt index c3a97c0886..a9b6c9747b 100644 --- a/Applications/Terminal/CMakeLists.txt +++ b/Applications/Terminal/CMakeLists.txt @@ -2,5 +2,5 @@ set(SOURCES main.cpp ) -serenity_bin(Terminal) +serenity_app(Terminal ICON app-terminal) target_link_libraries(Terminal LibGUI LibVT) diff --git a/Applications/TextEditor/CMakeLists.txt b/Applications/TextEditor/CMakeLists.txt index 897a77f287..e43a95aace 100644 --- a/Applications/TextEditor/CMakeLists.txt +++ b/Applications/TextEditor/CMakeLists.txt @@ -6,5 +6,5 @@ set(SOURCES MainWindowGML.h ) -serenity_bin(TextEditor) +serenity_app(TextEditor ICON app-text-editor) target_link_libraries(TextEditor LibWeb LibMarkdown LibGUI LibShell LibRegex LibDesktop) diff --git a/Applications/ThemeEditor/CMakeLists.txt b/Applications/ThemeEditor/CMakeLists.txt index e66d652f0a..94ca0e1f3e 100644 --- a/Applications/ThemeEditor/CMakeLists.txt +++ b/Applications/ThemeEditor/CMakeLists.txt @@ -3,5 +3,5 @@ set(SOURCES main.cpp ) -serenity_bin(ThemeEditor) +serenity_app(ThemeEditor ICON app-theme-editor) target_link_libraries(ThemeEditor LibGUI) diff --git a/CMakeLists.txt b/CMakeLists.txt index 67bf67fc91..db3461d10a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -164,6 +164,23 @@ function(serenity_bin target_name) serenity_generated_sources(${target_name}) endfunction() +function(serenity_app target_name) + cmake_parse_arguments(SERENITY_APP "" "ICON" "" ${ARGN}) + + serenity_bin("${target_name}") + set(small_icon "${CMAKE_SOURCE_DIR}/Base/res/icons/16x16/${SERENITY_APP_ICON}.png") + set(medium_icon "${CMAKE_SOURCE_DIR}/Base/res/icons/32x32/${SERENITY_APP_ICON}.png") + + if (EXISTS "${small_icon}") + embed_resource("${target_name}" serenity_icon_s "${small_icon}") + endif() + if (EXISTS "${medium_icon}") + embed_resource("${target_name}" serenity_icon_m "${medium_icon}") + endif() + + # TODO: Issue warnings if the app icons don't exist +endfunction() + function(compile_gml source output string_name) set(source ${CMAKE_CURRENT_SOURCE_DIR}/${source}) add_custom_command( @@ -191,6 +208,19 @@ function(compile_ipc source output) add_custom_target(generate_${output_name} DEPENDS ${output}) endfunction() +function(embed_resource target section file) + get_filename_component(asm_file "${file}" NAME) + set(asm_file "${CMAKE_CURRENT_BINARY_DIR}/${target}-${section}.s") + get_filename_component(input_file "${file}" ABSOLUTE) + add_custom_command( + OUTPUT "${asm_file}" + COMMAND "${CMAKE_SOURCE_DIR}/Meta/generate-embedded-resource-assembly.sh" "${asm_file}" "${section}" "${input_file}" + DEPENDS "${input_file}" "${CMAKE_SOURCE_DIR}/Meta/generate-embedded-resource-assembly.sh" + COMMENT "Generating ${asm_file}" + ) + target_sources("${target}" PRIVATE "${asm_file}") +endfunction() + find_program(CCACHE_PROGRAM ccache) if(CCACHE_PROGRAM) set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}") diff --git a/Demos/Cube/CMakeLists.txt b/Demos/Cube/CMakeLists.txt index 6a600aa789..ee06d91d3f 100644 --- a/Demos/Cube/CMakeLists.txt +++ b/Demos/Cube/CMakeLists.txt @@ -2,5 +2,5 @@ set(SOURCES Cube.cpp ) -serenity_bin(Cube) +serenity_app(Cube ICON app-cube) target_link_libraries(Cube LibGUI) diff --git a/Demos/Eyes/CMakeLists.txt b/Demos/Eyes/CMakeLists.txt index 355a874673..aa0e948d6a 100644 --- a/Demos/Eyes/CMakeLists.txt +++ b/Demos/Eyes/CMakeLists.txt @@ -3,5 +3,5 @@ set(SOURCES EyesWidget.cpp ) -serenity_bin(Eyes) +serenity_app(Eyes ICON app-eyes) target_link_libraries(Eyes LibGUI LibGfx) diff --git a/Demos/Fire/CMakeLists.txt b/Demos/Fire/CMakeLists.txt index 315b7f5216..10342de600 100644 --- a/Demos/Fire/CMakeLists.txt +++ b/Demos/Fire/CMakeLists.txt @@ -2,5 +2,5 @@ set(SOURCES Fire.cpp ) -serenity_bin(Fire) +serenity_app(Fire ICON app-fire) target_link_libraries(Fire LibGUI LibCore LibGfx) diff --git a/Demos/HelloWorld/CMakeLists.txt b/Demos/HelloWorld/CMakeLists.txt index 2469b40a09..a210b1aa77 100644 --- a/Demos/HelloWorld/CMakeLists.txt +++ b/Demos/HelloWorld/CMakeLists.txt @@ -2,5 +2,5 @@ set(SOURCES main.cpp ) -serenity_bin(HelloWorld) +serenity_app(HelloWorld ICON app-hello-world) target_link_libraries(HelloWorld LibGUI) diff --git a/Demos/LibGfxDemo/CMakeLists.txt b/Demos/LibGfxDemo/CMakeLists.txt index c63ce34e61..5f2d4bca8f 100644 --- a/Demos/LibGfxDemo/CMakeLists.txt +++ b/Demos/LibGfxDemo/CMakeLists.txt @@ -2,5 +2,5 @@ set(SOURCES main.cpp ) -serenity_bin(LibGfxDemo) +serenity_app(LibGfxDemo ICON app-libgfx-demo) target_link_libraries(LibGfxDemo LibGUI LibIPC LibGfx LibCore) diff --git a/Demos/Mouse/CMakeLists.txt b/Demos/Mouse/CMakeLists.txt index 389e625d1e..bc90a5e308 100644 --- a/Demos/Mouse/CMakeLists.txt +++ b/Demos/Mouse/CMakeLists.txt @@ -2,5 +2,5 @@ set(SOURCES main.cpp ) -serenity_bin(Mouse) +serenity_app(Mouse ICON app-mouse) target_link_libraries(Mouse LibGUI LibGfx) diff --git a/Demos/Screensaver/CMakeLists.txt b/Demos/Screensaver/CMakeLists.txt index 0b58e1c7af..6f8acee97c 100644 --- a/Demos/Screensaver/CMakeLists.txt +++ b/Demos/Screensaver/CMakeLists.txt @@ -2,5 +2,5 @@ set(SOURCES Screensaver.cpp ) -serenity_bin(Screensaver) +serenity_app(Screensaver ICON app-screensaver) target_link_libraries(Screensaver LibGUI LibCore LibGfx) diff --git a/Demos/WidgetGallery/CMakeLists.txt b/Demos/WidgetGallery/CMakeLists.txt index 936f8a168b..2c4e42046d 100644 --- a/Demos/WidgetGallery/CMakeLists.txt +++ b/Demos/WidgetGallery/CMakeLists.txt @@ -2,5 +2,5 @@ set(SOURCES main.cpp ) -serenity_bin(WidgetGallery) +serenity_app(WidgetGallery ICON app-widget-gallery) target_link_libraries(WidgetGallery LibGUI) diff --git a/DevTools/HackStudio/CMakeLists.txt b/DevTools/HackStudio/CMakeLists.txt index 27d473c687..6f78d59f91 100644 --- a/DevTools/HackStudio/CMakeLists.txt +++ b/DevTools/HackStudio/CMakeLists.txt @@ -33,6 +33,6 @@ set(SOURCES main.cpp ) -serenity_bin(HackStudio) +serenity_app(HackStudio ICON app-hack-studio) target_link_libraries(HackStudio LibWeb LibMarkdown LibGUI LibGfx LibCore LibVT LibDebug LibX86 LibDiff LibShell) add_dependencies(HackStudio CppLanguageServer) diff --git a/DevTools/Inspector/CMakeLists.txt b/DevTools/Inspector/CMakeLists.txt index cadfd75f4f..dd980cec99 100644 --- a/DevTools/Inspector/CMakeLists.txt +++ b/DevTools/Inspector/CMakeLists.txt @@ -6,5 +6,5 @@ set(SOURCES RemoteProcess.cpp ) -serenity_bin(Inspector) +serenity_app(Inspector ICON app-inspector) target_link_libraries(Inspector LibGUI) diff --git a/DevTools/Profiler/CMakeLists.txt b/DevTools/Profiler/CMakeLists.txt index a5d78d7ae6..1cb7b95140 100644 --- a/DevTools/Profiler/CMakeLists.txt +++ b/DevTools/Profiler/CMakeLists.txt @@ -6,5 +6,5 @@ set(SOURCES ProfileTimelineWidget.cpp ) -serenity_bin(Profiler) +serenity_app(Profiler ICON app-profiler) target_link_libraries(Profiler LibGUI LibX86 LibCoreDump) diff --git a/Games/2048/CMakeLists.txt b/Games/2048/CMakeLists.txt index 2b92309c76..d48b1e7bcf 100644 --- a/Games/2048/CMakeLists.txt +++ b/Games/2048/CMakeLists.txt @@ -5,5 +5,5 @@ set(SOURCES main.cpp ) -serenity_bin(2048) +serenity_app(2048 ICON app-2048) target_link_libraries(2048 LibGUI) diff --git a/Games/Breakout/CMakeLists.txt b/Games/Breakout/CMakeLists.txt index b13e635f07..d26284ea20 100644 --- a/Games/Breakout/CMakeLists.txt +++ b/Games/Breakout/CMakeLists.txt @@ -4,5 +4,5 @@ set(SOURCES LevelSelectDialog.cpp ) -serenity_bin(Breakout) +serenity_app(Breakout ICON app-breakout) target_link_libraries(Breakout LibGUI) diff --git a/Games/Chess/CMakeLists.txt b/Games/Chess/CMakeLists.txt index cc49d6ee4c..54415eeb95 100644 --- a/Games/Chess/CMakeLists.txt +++ b/Games/Chess/CMakeLists.txt @@ -5,5 +5,5 @@ set(SOURCES Engine.cpp ) -serenity_bin(Chess) +serenity_app(Chess ICON app-chess) target_link_libraries(Chess LibChess LibGUI LibCore) diff --git a/Games/Minesweeper/CMakeLists.txt b/Games/Minesweeper/CMakeLists.txt index e50f100ad2..466227edb6 100644 --- a/Games/Minesweeper/CMakeLists.txt +++ b/Games/Minesweeper/CMakeLists.txt @@ -3,5 +3,5 @@ set(SOURCES main.cpp ) -serenity_bin(Minesweeper) +serenity_app(Minesweeper ICON app-minesweeper) target_link_libraries(Minesweeper LibGUI) diff --git a/Games/Pong/CMakeLists.txt b/Games/Pong/CMakeLists.txt index 39560740ef..ebd8962f94 100644 --- a/Games/Pong/CMakeLists.txt +++ b/Games/Pong/CMakeLists.txt @@ -3,5 +3,5 @@ set(SOURCES Game.cpp ) -serenity_bin(Pong) +serenity_app(Pong ICON app-pong) target_link_libraries(Pong LibGUI) diff --git a/Games/Snake/CMakeLists.txt b/Games/Snake/CMakeLists.txt index c40e284ad4..d542cd4ead 100644 --- a/Games/Snake/CMakeLists.txt +++ b/Games/Snake/CMakeLists.txt @@ -3,5 +3,5 @@ set(SOURCES SnakeGame.cpp ) -serenity_bin(Snake) +serenity_app(Snake ICON app-snake) target_link_libraries(Snake LibGUI) diff --git a/Games/Solitaire/CMakeLists.txt b/Games/Solitaire/CMakeLists.txt index e61f9e3bfb..4a9d4e6c71 100644 --- a/Games/Solitaire/CMakeLists.txt +++ b/Games/Solitaire/CMakeLists.txt @@ -5,5 +5,5 @@ set(SOURCES SolitaireWidget.cpp ) -serenity_bin(Solitaire) +serenity_app(Solitaire ICON app-solitaire) target_link_libraries(Solitaire LibGUI LibGfx LibCore) diff --git a/Meta/generate-embedded-resource-assembly.sh b/Meta/generate-embedded-resource-assembly.sh new file mode 100755 index 0000000000..05aa443117 --- /dev/null +++ b/Meta/generate-embedded-resource-assembly.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +set -e + +if [ -z "$1" ]; then + echo "ERROR: No output file specified" + exit 1 +fi + +OUTPUT_FILE="$1" +shift + +rm -f "${OUTPUT_FILE}" + +while (( "$#" >= 2)); do + SECTION_NAME="$1" + INPUT_FILE="$2" + + { + printf ' .section %s\n' "${SECTION_NAME}" + printf ' .type %s, @object\n' "${SECTION_NAME}" + printf ' .align 4\n' + printf ' .incbin "%s"\n' "${INPUT_FILE}" + printf '\n' + } >> "${OUTPUT_FILE}" + shift 2 +done