From 1aba9f5f6f0782a978ae4177eae6028a77082617 Mon Sep 17 00:00:00 2001 From: Martchus Date: Thu, 22 Dec 2022 23:28:05 +0100 Subject: [PATCH] Allow setting Windows/MacOS icon paths to avoid conversion This makes it possible to have an own version of the icon for those platforms instead of relying on an automatic conversion from the generic PNG icon. --- cmake/modules/AppTarget.cmake | 4 +++- cmake/modules/WindowsResources.cmake | 29 +++++++++++++++------------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/cmake/modules/AppTarget.cmake b/cmake/modules/AppTarget.cmake index 13e76c1..a0d9af9 100644 --- a/cmake/modules/AppTarget.cmake +++ b/cmake/modules/AppTarget.cmake @@ -73,7 +73,9 @@ if (GUI_TYPE STREQUAL "MACOSX_BUNDLE") MACOSX_BUNDLE_BUNDLE_VERSION "${META_APP_VERSION}" MACOSX_BUNDLE_LONG_VERSION_STRING "${META_APP_VERSION}" MACOSX_BUNDLE_SHORT_VERSION_STRING "${META_APP_VERSION}") - if (PNG_ICON_PATH) + if (MACOSX_ICON_PATH) + target_sources(${META_TARGET_NAME} PRIVATE "${MACOSX_ICON_PATH}") + elseif (PNG_ICON_PATH) find_program(PNG2ICNS_BIN png2icns) if (PNG2ICNS_BIN) set(RESOURCES_DIR "${CMAKE_CURRENT_BINARY_DIR}/${META_TARGET_NAME}.app/Contents/Resources") diff --git a/cmake/modules/WindowsResources.cmake b/cmake/modules/WindowsResources.cmake index 81c8d62..43bfc66 100644 --- a/cmake/modules/WindowsResources.cmake +++ b/cmake/modules/WindowsResources.cmake @@ -23,22 +23,25 @@ set(WINDOWS_RC_FILE_CFG "${CMAKE_CURRENT_BINARY_DIR}/resources/windows.rc.config set(WINDOWS_RC_FILE "${CMAKE_CURRENT_BINARY_DIR}/resources/windows") # create Windows icon from png with ffmpeg if available -unset(WINDOWS_ICON_PATH) unset(WINDOWS_ICON_RC_ENTRY) -if (WINDOWS_ICON_ENABLED AND PNG_ICON_PATH) - find_program(FFMPEG_BIN ffmpeg avconv) - if (FFMPEG_BIN) - set(WINDOWS_ICON_PATH "${CMAKE_CURRENT_BINARY_DIR}/resources/${META_PROJECT_NAME}.ico") +if (WINDOWS_ICON_ENABLED) + if (NOT WINDOWS_ICON_PATH AND PNG_ICON_PATH) + find_program(FFMPEG_BIN ffmpeg avconv) + if (FFMPEG_BIN) + set(WINDOWS_ICON_PATH "${CMAKE_CURRENT_BINARY_DIR}/resources/${META_PROJECT_NAME}.ico") + add_custom_command( + COMMENT "Generating icon for Windows executable" + OUTPUT "${WINDOWS_ICON_PATH}" + COMMAND ${FFMPEG_BIN} -y -i "${PNG_ICON_PATH}" "${WINDOWS_ICON_PATH}" + DEPENDS "${PNG_ICON_PATH}") + message(STATUS "Generating Windows icon from \"${PNG_ICON_PATH}\" via ${FFMPEG_BIN}.") + else () + message(STATUS "Unable to find ffmpeg, not creating a Windows icon") + endif () + endif () + if (WINDOWS_ICON_PATH) set(WINDOWS_ICON_RC_ENTRY "IDI_ICON1 ICON DISCARDABLE \"${WINDOWS_ICON_PATH}\"") - add_custom_command( - COMMENT "Generating icon for Windows executable" - OUTPUT "${WINDOWS_ICON_PATH}" - COMMAND ${FFMPEG_BIN} -y -i "${PNG_ICON_PATH}" "${WINDOWS_ICON_PATH}" - DEPENDS "${PNG_ICON_PATH}") set_source_files_properties("${WINDOWS_RC_FILE}" PROPERTIES OBJECT_DEPENDS "${WINDOWS_ICON_PATH}") - message(STATUS "Generating Windows icon from \"${PNG_ICON_PATH}\" via ${FFMPEG_BIN}.") - else () - message(STATUS "Unable to find ffmpeg, not creating a Windows icon") endif () endif ()