Skip to content

Commit

Permalink
Examples: Add app icons
Browse files Browse the repository at this point in the history
  • Loading branch information
brackeen committed Feb 24, 2024
1 parent 733bed6 commit a6d80aa
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 2 deletions.
10 changes: 8 additions & 2 deletions examples/cmake/GLFMAppTarget.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
# If you change this section, test archiving too.
set(CMAKE_MACOSX_BUNDLE YES)

add_executable(${GLFM_APP_TARGET_NAME} ${GLFM_APP_SRC} ${GLFM_APP_ASSETS})
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${GLFM_APP_TARGET_NAME}.icns
COMMAND bash -c "${CMAKE_CURRENT_SOURCE_DIR}/icons/gen_icns.sh ${GLFM_APP_TARGET_NAME} ${CMAKE_CURRENT_BINARY_DIR}"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/icons)

add_executable(${GLFM_APP_TARGET_NAME} ${GLFM_APP_SRC} ${GLFM_APP_ASSETS} ${CMAKE_CURRENT_BINARY_DIR}/${GLFM_APP_TARGET_NAME}.icns)

set_target_properties(${GLFM_APP_TARGET_NAME} PROPERTIES
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_BINARY_DIR}/CMake-Info.plist.in
Expand All @@ -83,7 +87,7 @@ elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set_target_properties(${GLFM_APP_TARGET_NAME} PROPERTIES
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer")
endif()
set_source_files_properties(${GLFM_APP_ASSETS} LaunchScreen.storyboard PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
set_source_files_properties(${GLFM_APP_ASSETS} LaunchScreen.storyboard ${GLFM_APP_TARGET_NAME}.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
set_source_files_properties(${GLFM_APP_ASSETS} PROPERTIES XCODE_LAST_KNOWN_FILE_TYPE YES)
target_compile_definitions(${GLFM_APP_TARGET_NAME} PRIVATE GLES_SILENCE_DEPRECATION)

Expand Down Expand Up @@ -173,6 +177,8 @@ elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
" <string>UIInterfaceOrientationLandscapeLeft</string>\n"
" <string>UIInterfaceOrientationLandscapeRight</string>\n"
" </array>\n"
" <key>CFBundleIconFile</key>\n"
" <string>$(EXECUTABLE_NAME).icns</string>\n"
"</dict>\n"
"</plist>\n"
)
Expand Down
30 changes: 30 additions & 0 deletions examples/icons/gen_icns.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#/bin/bash
# This script generates an icns file (for iOS and macOS) from a png file.
# Requires macOS (sips and iconutil)

if [ -z "$1" || -z $2 ]; then
echo "Usage: $0 <icon_name> <output_dir>"
exit 1
fi

if ! [ -f "$1.png" ]; then
echo "Error: $1.png does not exist"
exit 2
fi

mkdir -p $1.iconset
mkdir -p $2

sips -z 16 16 $1.png --out $1.iconset/icon_16x16.png
sips -z 32 32 $1.png --out $1.iconset/icon_16x16@2x.png
sips -z 32 32 $1.png --out $1.iconset/icon_32x32.png
sips -z 64 64 $1.png --out $1.iconset/icon_32x32@2x.png
sips -z 128 128 $1.png --out $1.iconset/icon_128x128.png
sips -z 256 256 $1.png --out $1.iconset/icon_128x128@2x.png
sips -z 256 256 $1.png --out $1.iconset/icon_256x256.png
sips -z 512 512 $1.png --out $1.iconset/icon_256x256@2x.png
sips -z 512 512 $1.png --out $1.iconset/icon_512x512.png
sips -z 1024 1024 $1.png --out $1.iconset/icon_512x512@2x.png

iconutil -c icns --output $2/$1.icns $1.iconset
rm -R $1.iconset
Binary file added examples/icons/glfm_compass.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/icons/glfm_heightmap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/icons/glfm_shader_toy.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/icons/glfm_test_pattern.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/icons/glfm_touch.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/icons/glfm_triangle.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/icons/glfm_typing.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a6d80aa

Please sign in to comment.