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 8594c00d614..4652ec8b116 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 548c37b7746..8c5c14feaf6 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 77fbce16758..c23a6743ccd 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 b5d2162f9de..af736e83a81 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 b0bfcabee30..f650c97402d 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 0c39433507b..079b7a521a4 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 8d1a5038e2e..46a832c0444 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 3de7c9cfb58..ebe134863ff 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 6f304b18c1d..3926bbd5dc3 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 54f5ea70aa6..62212cda369 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 6756afb18c9..382e023c3be 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 73e2196ca73..713845c80ee 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 c0f9a05e6b0..8d2b46e217b 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 6c71842cd36..99e1da46533 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 ea0054dc7b1..f41922655a5 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 bf078096cd0..ee2e4d2323f 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 c3a97c0886e..a9b6c9747b1 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 897a77f287e..e43a95aace2 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 e66d652f0ab..94ca0e1f3ea 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 67bf67fc910..db3461d10ad 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 6a600aa7897..ee06d91d3f7 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 355a874673b..aa0e948d6a7 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 315b7f5216b..10342de6008 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 2469b40a09f..a210b1aa777 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 c63ce34e61e..5f2d4bca8f4 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 389e625d1e7..bc90a5e3083 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 0b58e1c7af8..6f8acee97ce 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 936f8a168b4..2c4e42046dc 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 27d473c687c..6f78d59f91d 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 cadfd75f4fd..dd980cec995 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 a5d78d7ae6f..1cb7b951403 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 2b92309c76e..d48b1e7bcf4 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 b13e635f074..d26284ea20c 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 cc49d6ee4c2..54415eeb95a 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 e50f100ad26..466227edb69 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 39560740ef0..ebd8962f946 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 c40e284ad4c..d542cd4eadb 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 e61f9e3bfb7..4a9d4e6c712 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 00000000000..05aa4431176 --- /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