Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support icotool in ECMAddAppIcon macro #6511

Merged
merged 5 commits into from
May 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions appveyor.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Command=craft
UseCache = True
CreateCache = False
QtVersion = 5.10.1
OpenSslVersion = 1.1.0g
CacheVersion = Qt_${Variables:QtVersion}
OpenSslVersion = 1.1.0h
CacheVersion = Qt_${Variables:QtVersion}-1

# Settings applicable for all Crafts matrices
# Settings are Category/key=value
Expand Down
100 changes: 75 additions & 25 deletions cmake/modules/ECMAddAppIcon.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,18 @@ function(ecm_add_app_icon appsources)
endif()


set(windows_icons ${icons_at_16px}
${icons_at_32px}
${icons_at_48px}
${icons_at_64px}
${icons_at_128px})
if (NOT windows_icons)
set(windows_icons_classic ${icons_at_16px}
${icons_at_24px}
${icons_at_32px}
${icons_at_48px}
${icons_at_64px}
${icons_at_128px})
set(windows_icons_modern ${windows_icons_classic}
${icons_at_256px}
${icons_at_512px}
${icons_at_1024px})

if (NOT (windows_icons_modern OR windows_icons_classic))
message(AUTHOR_WARNING "No icons suitable for use on Windows provided")
endif()

Expand All @@ -180,30 +186,19 @@ function(ecm_add_app_icon appsources)
endif()
set (_outfilename "${CMAKE_CURRENT_BINARY_DIR}/${_outfilebasename}")

if (WIN32 AND windows_icons)
if (WIN32 AND (windows_icons_modern OR windows_icons_classic))
set(saved_CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_FIND_MODULE_DIR})
find_package(Png2Ico)
find_package(IcoTool)
set(CMAKE_MODULE_PATH "${saved_CMAKE_MODULE_PATH}")

if (Png2Ico_FOUND)
if (Png2Ico_HAS_RCFILE_ARGUMENT)
add_custom_command(
OUTPUT "${_outfilename}.rc" "${_outfilename}.ico"
COMMAND Png2Ico::Png2Ico
ARGS
--rcfile "${_outfilename}.rc"
"${_outfilename}.ico"
${windows_icons}
DEPENDS ${windows_icons}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)
else()
function(create_windows_icon_and_rc command args deps)
add_custom_command(
OUTPUT "${_outfilename}.ico"
COMMAND Png2Ico::Png2Ico
ARGS "${_outfilename}.ico" ${windows_icons}
DEPENDS ${windows_icons}
COMMAND ${command}
ARGS ${args}
DEPENDS ${deps}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)
# this bit's a little hacky to make the dependency stuff work
Expand All @@ -215,10 +210,65 @@ function(ecm_add_app_icon appsources)
DEPENDS "${_outfilename}.ico"
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
)
endif()
endfunction()

if (IcoTool_FOUND)
set(icotool_args "-c -o \"${_outfilename}.ico\"")

# According to https://stackoverflow.com/a/40851713/2886832
# Windows always chooses the first icon above 255px, all other ones will be ignored
set(maxSize 0)
foreach(size 256 512 1024)
if(icons_at_${size}px)
set(maxSize "${size}")
endif()
endforeach()

foreach(size 16 32 48 64 128 ${maxSize})
if(NOT icons_at_${size}px)
continue()
endif()

set(icotool_icon_arg "")
if(size STREQUAL "${maxSize}")
# maxSize icon needs to be included as raw png
list(APPEND icotool_args "-r")
endif()

foreach(icon ${icons_at_${size}px})
list(APPEND icotool_args "${icons_at_${size}px}")
endforeach()
endforeach()

create_windows_icon_and_rc(IcoTool::IcoTool "${icotool_args}" "${windows_icons_modern}")
set(${appsources} "${${appsources}};${_outfilename}.rc" PARENT_SCOPE)

# standard png2ico has no rcfile argument
elseif(Png2Ico_FOUND AND NOT Png2Ico_HAS_RCFILE_ARGUMENT AND windows_icons_classic)
set(png2ico_args)
list(APPEND png2ico_args "${_outfilename}.ico")
list(APPEND png2ico_args "${windows_icons_classic}")

create_windows_icon_and_rc(Png2Ico::Png2Ico "${png2ico_args}" "${windows_icons_classic}")
set(${appsources} "${${appsources}};${_outfilename}.rc" PARENT_SCOPE)

# png2ico from kdewin provides rcfile argument
elseif(Png2Ico_FOUND AND windows_icons_classic)
add_custom_command(
OUTPUT "${_outfilename}.rc" "${_outfilename}.ico"
COMMAND Png2Ico::Png2Ico
ARGS
--rcfile "${_outfilename}.rc"
"${_outfilename}.ico"
${windows_icons_classic}
DEPENDS ${windows_icons_classic}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)

set(${appsources} "${${appsources}};${_outfilename}.rc" PARENT_SCOPE)
# else none of the supported tools was found
else()
message(WARNING "Unable to find the png2ico utility - application will not have an application icon!")
message(WARNING "Unable to find the png2ico or icotool utilities or icons in matching sizes - application will not have an application icon!")
endif()
elseif (APPLE AND mac_icons)
# first generate .iconset directory structure, then convert to .icns format using the Mac OS X "iconutil" utility,
Expand Down
27 changes: 27 additions & 0 deletions cmake/modules/FindIcoTool.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2017 Vincent Pinon <vpinon@kde.org>
include(${CMAKE_CURRENT_LIST_DIR}/ECMFindModuleHelpersStub.cmake)
ecm_find_package_version_check(IcoTool)
find_program(IcoTool_EXECUTABLE NAMES icotool)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(IcoTool
FOUND_VAR
IcoTool_FOUND
REQUIRED_VARS
IcoTool_EXECUTABLE
)
mark_as_advanced(IcoTool_EXECUTABLE)

if (IcoTool_FOUND)
if (NOT TARGET IcoTool::IcoTool)
add_executable(IcoTool::IcoTool IMPORTED)
set_target_properties(IcoTool::IcoTool PROPERTIES
IMPORTED_LOCATION "${IcoTool_EXECUTABLE}"
)
endif()
endif()

include(FeatureSummary)
set_package_properties(IcoTool PROPERTIES
URL "http://www.nongnu.org/icoutils/"
DESCRIPTION "Executable that converts a collection of PNG files into a Windows icon file"
)