Adds proper MacOS bundle and icons for Windows builds (#381)

* macos bundle

* windows icons

* MacOS bundle works when placed inside a carmageddon directory
This commit is contained in:
Dethrace Engineering Department 2024-07-05 09:12:19 +12:00 committed by GitHub
parent fdc37eff8f
commit 68360350e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 122 additions and 11 deletions

View File

@ -110,7 +110,11 @@ if(DETHRACE_INSTALL)
set(CPACK_PACKAGE_DIRECTORY dist)
if(MSVC)
if(APPLE)
set(CPACK_DMG_DISABLE_APPLICATIONS_SYMLINK "ON")
set(CPACK_GENERATOR "DragNDrop")
set(ext ".dmg")
elseif(MSVC)
set(CPACK_GENERATOR ZIP)
set(ext ".zip")
else()

BIN
packaging/icon_source.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 KiB

Binary file not shown.

View File

@ -0,0 +1,40 @@
#!/bin/sh
set -e
SOURCE_IMAGE=$1
TEMP_ICON_IMAGE=icon.png
# resize to 412x with black canvas
convert ${SOURCE_IMAGE} -resize 412x412 -background Black -gravity center -extent 412x412 ${TEMP_ICON_IMAGE}
# add rounded corners
convert ${TEMP_ICON_IMAGE} \
\( +clone -alpha extract \
-draw 'fill black polygon 0,0 0,50 50,0 fill white circle 50,50 50,0' \
\( +clone -flip \) -compose Multiply -composite \
\( +clone -flop \) -compose Multiply -composite \
\) -alpha off -compose CopyOpacity -composite ${TEMP_ICON_IMAGE}
# add margin
convert ${TEMP_ICON_IMAGE} -bordercolor transparent -border 40x40 ${TEMP_ICON_IMAGE}
# add drop shadow
convert ${TEMP_ICON_IMAGE} \
\( +clone -background black -shadow 100x5+0+0 \) +swap \
-background none -layers merge +repage ${TEMP_ICON_IMAGE}
rm -r dethrace.iconset || true
mkdir -p dethrace.iconset
sips -z 16 16 ${TEMP_ICON_IMAGE} --out dethrace.iconset/icon_16x16.png
sips -z 32 32 ${TEMP_ICON_IMAGE} --out dethrace.iconset/icon_16x16@2x.png
sips -z 32 32 ${TEMP_ICON_IMAGE} --out dethrace.iconset/icon_32x32.png
sips -z 64 64 ${TEMP_ICON_IMAGE} --out dethrace.iconset/icon_32x32@2x.png
sips -z 128 128 ${TEMP_ICON_IMAGE} --out dethrace.iconset/icon_128x128.png
sips -z 256 256 ${TEMP_ICON_IMAGE} --out dethrace.iconset/icon_128x128@2x.png
sips -z 256 256 ${TEMP_ICON_IMAGE} --out dethrace.iconset/icon_256x256.png
sips -z 512 512 ${TEMP_ICON_IMAGE} --out dethrace.iconset/icon_256x256@2x.png
sips -z 512 512 ${TEMP_ICON_IMAGE} --out dethrace.iconset/icon_512x512.png
sips -z 1024 1024 ${TEMP_ICON_IMAGE} --out dethrace.iconset/icon_512x512@2x.png
iconutil -c icns dethrace.iconset
rm -r dethrace.iconset ${TEMP_ICON_IMAGE}

Binary file not shown.

After

Width:  |  Height:  |  Size: 195 KiB

View File

@ -0,0 +1 @@
IDI_ICON1 ICON DISCARDABLE "dethrace.ico"

View File

@ -0,0 +1,12 @@
#!/bin/sh
set -e
SOURCE_IMAGE=$1
TEMP_ICON_IMAGE=icon.png
# resize to 412x with black canvas
convert ${SOURCE_IMAGE} -resize 412x412 -background Black -gravity center -extent 412x412 ${TEMP_ICON_IMAGE}
# convert to ico format
convert -background transparent ${TEMP_ICON_IMAGE} -define icon:auto-resize=16,24,32,48,64,72,96,128,256 "dethrace.ico"
rm ${TEMP_ICON_IMAGE}

View File

@ -16,7 +16,7 @@ target_include_directories(dethrace_obj
target_link_libraries(dethrace_obj PUBLIC SDL2::SDL2 smackw32 harness BRender::Full BRender::DDI s3)
if (CMAKE_C_COMPILER_ID MATCHES "MSVC")
if(MSVC)
target_compile_definitions(dethrace_obj PRIVATE -D_CRT_SECURE_NO_WARNINGS)
target_compile_options(dethrace_obj PRIVATE
/wd4101
@ -167,13 +167,16 @@ target_sources(dethrace_obj PRIVATE
)
# Create our main game binary.
add_executable(dethrace)
add_executable(dethrace
WIN32
${CMAKE_SOURCE_DIR}/packaging/macos/dethrace.icns
${CMAKE_SOURCE_DIR}/packaging/windows/dethrace.rc
)
target_link_libraries(dethrace PRIVATE dethrace_obj compile_with_werror)
target_sources(dethrace PRIVATE main.c)
if(NOT MSVC)
else()
if(MSVC)
target_link_libraries(dethrace PRIVATE dbghelp)
target_link_options(dethrace PRIVATE /subsystem:windows /ENTRY:mainCRTStartup)
target_compile_definitions(dethrace PRIVATE -D_CRT_SECURE_NO_WARNINGS -DSDL_MAIN_HANDLED -DWIN32_LEAN_AND_MEAN)
@ -193,18 +196,49 @@ if(DETHRACE_IDE_ARGUMENTS)
)
endif()
if (DETHRACE_INSTALL)
if(DETHRACE_INSTALL)
install(TARGETS dethrace
RUNTIME DESTINATION "."
BUNDLE DESTINATION . COMPONENT Runtime
RUNTIME DESTINATION . COMPONENT Runtime
)
if(APPLE)
set_target_properties(dethrace PROPERTIES
BUNDLE True
MACOSX_BUNDLE True
MACOSX_BUNDLE_DISPLAY_NAME "Deth Race"
OUTPUT_NAME "Deth Race"
MACOSX_BUNDLE_BUNDLE_VERSION ${DETHRACE_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${DETHRACE_VERSION}
MACOSX_BUNDLE_ICON_FILE dethrace.icns
)
set_source_files_properties(${CMAKE_SOURCE_DIR}/packaging/macos/dethrace.icns PROPERTIES
MACOSX_PACKAGE_LOCATION "Resources"
)
target_sources(dethrace_obj PRIVATE
${CMAKE_SOURCE_DIR}/packaging/macos/dethrace.icns
)
install(CODE "
include(BundleUtilities)
fixup_bundle(\"${CMAKE_BINARY_DIR}/Deth Race.app\" \"\" \"/Library/Frameworks\")
execute_process(COMMAND
codesign -s - -f \"${CMAKE_BINARY_DIR}/Deth Race.app/Contents/Frameworks/SDL2.framework\"
)
"
COMPONENT RUNTIME
)
endif()
if(MSVC)
INSTALL(FILES $<TARGET_PDB_FILE:dethrace>
install(FILES $<TARGET_PDB_FILE:dethrace>
DESTINATION "."
OPTIONAL
)
endif()
if(WIN32)
INSTALL(FILES $<TARGET_RUNTIME_DLLS:dethrace>
install(FILES $<TARGET_RUNTIME_DLLS:dethrace>
DESTINATION "."
OPTIONAL
)

View File

@ -175,7 +175,7 @@ void Harness_Init(int* argc, char* argv[]) {
if (root_dir != NULL) {
LOG_INFO("DETHRACE_ROOT_DIR is set to '%s'", root_dir);
} else {
root_dir = OS_Dirname(argv[0]);
root_dir = OS_GetWorkingDirectory(argv[0]);
}
// if root_dir is null or empty, no need to chdir
if (root_dir != NULL && root_dir[0] != '\0') {

View File

@ -34,4 +34,6 @@ char* OS_Dirname(const char* path);
char* OS_Basename(const char* path);
char* OS_GetWorkingDirectory(char* argv0);
#endif

View File

@ -319,3 +319,7 @@ char* OS_Basename(const char* path) {
strcpy(name_buf, path);
return basename(name_buf);
}
char* OS_GetWorkingDirectory(char* argv0) {
return OS_Dirname(argv0);
}

View File

@ -249,3 +249,13 @@ char* OS_Basename(const char* path) {
strcpy(name_buf, path);
return basename(name_buf);
}
char* OS_GetWorkingDirectory(char* argv0) {
// The application executable in a MacOS bundle is in <bundle.app>/Contents/MacOS/executable
// We strip off the bundle paths to get the path that the <bundle.app> is located in
char* bundlePath = strstr(argv0, ".app/Contents/MacOS");
if (bundlePath != NULL) {
*bundlePath = '\0';
}
return OS_Dirname(argv0);
}

View File

@ -185,3 +185,7 @@ char* OS_Basename(const char* path) {
_splitpath(path, NULL, NULL, fname_buf, NULL);
return fname_buf;
}
char* OS_GetWorkingDirectory(char* argv0) {
return OS_Dirname(argv0);
}