1
SET(WINDRES_EXECUTABLE ${CMAKE_RC_COMPILER})
3
# This macro is taken from kdelibs/cmake/modules/KDE4Macros.cmake.
5
# Copyright (c) 2006-2009 Alexander Neundorf, <neundorf@kde.org>
6
# Copyright (c) 2006, 2007, Laurent Montel, <montel@kde.org>
7
# Copyright (c) 2007 Matthias Kretz <kretz@kde.org>
9
# Redistribution and use is allowed according to the terms of the BSD license.
10
# For details see the accompanying COPYING-CMAKE-SCRIPTS file [in KDE repositories].
13
# adds application icon to target source list
14
# for detailed documentation see the top of FindKDE4Internal.cmake
15
macro (KDE4_ADD_APP_ICON appsources pattern)
16
set (_outfilename ${CMAKE_CURRENT_BINARY_DIR}/${appsources})
20
find_program(PNG2ICO_EXECUTABLE NAMES png2ico)
22
find_program(PNG2ICO_EXECUTABLE NAMES png2ico PATHS ${HOST_BINDIR} NO_DEFAULT_PATH )
24
find_program(WINDRES_EXECUTABLE NAMES windres)
26
set(WINDRES_EXECUTABLE TRUE)
28
if (PNG2ICO_EXECUTABLE AND WINDRES_EXECUTABLE)
29
string(REPLACE "*" "(.*)" pattern_rx "${pattern}")
30
file(GLOB files "${pattern}")
32
string(REGEX REPLACE "${pattern_rx}" "\\1" fn "${it}")
33
if (fn MATCHES ".*16.*" )
34
list (APPEND _icons ${it})
35
endif (fn MATCHES ".*16.*")
36
if (fn MATCHES ".*32.*" )
37
list (APPEND _icons ${it})
38
endif (fn MATCHES ".*32.*")
39
if (fn MATCHES ".*48.*" )
40
list (APPEND _icons ${it})
41
endif (fn MATCHES ".*48.*")
42
if (fn MATCHES ".*64.*" )
43
list (APPEND _icons ${it})
44
endif (fn MATCHES ".*64.*")
45
if (fn MATCHES ".*128.*" )
46
list (APPEND _icons ${it})
47
endif (fn MATCHES ".*128.*")
50
add_custom_command(OUTPUT ${_outfilename}.ico ${_outfilename}.rc
51
COMMAND ${PNG2ICO_EXECUTABLE} ARGS --rcfile ${_outfilename}.rc ${_outfilename}.ico ${_icons}
52
DEPENDS ${PNG2ICO_EXECUTABLE} ${_icons}
53
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
56
add_custom_command(OUTPUT ${_outfilename}_res.o
57
COMMAND ${WINDRES_EXECUTABLE} ARGS -i ${_outfilename}.rc -o ${_outfilename}_res.o --include-dir=${CMAKE_CURRENT_SOURCE_DIR}
58
DEPENDS ${WINDRES_EXECUTABLE} ${_outfilename}.rc
59
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
61
list(APPEND ${appsources} ${_outfilename}_res.o)
63
list(APPEND ${appsources} ${_outfilename}.rc)
66
message(STATUS "Unable to find a related icon that matches pattern ${pattern} for variable ${appsources} - application will not have an application icon!")
68
else(PNG2ICO_EXECUTABLE AND WINDRES_EXECUTABLE)
69
message(STATUS "Unable to find the png2ico or windres utilities - application will not have an application icon!")
70
endif(PNG2ICO_EXECUTABLE AND WINDRES_EXECUTABLE)
73
# first convert image to a tiff using the Mac OS X "sips" utility,
74
# then use tiff2icns to convert to an icon
75
find_program(SIPS_EXECUTABLE NAMES sips)
76
find_program(TIFF2ICNS_EXECUTABLE NAMES tiff2icns)
77
if (SIPS_EXECUTABLE AND TIFF2ICNS_EXECUTABLE)
78
file(GLOB_RECURSE files "${pattern}")
79
# we can only test for the 128-icon like that - we don't use patterns anymore
81
if (it MATCHES ".*128.*" )
83
endif (it MATCHES ".*128.*")
88
# first, get the basename of our app icon
89
add_custom_command(OUTPUT ${_outfilename}.icns ${outfilename}.tiff
90
COMMAND ${SIPS_EXECUTABLE} -s format tiff ${_icon} --out ${outfilename}.tiff
91
COMMAND ${TIFF2ICNS_EXECUTABLE} ${outfilename}.tiff ${_outfilename}.icns
95
# This will register the icon into the bundle
96
set(MACOSX_BUNDLE_ICON_FILE ${appsources}.icns)
98
# Append the icns file to the sources list so it will be a dependency to the
100
list(APPEND ${appsources} ${_outfilename}.icns)
102
# Install the icon into the Resources dir in the bundle
103
set_source_files_properties(${_outfilename}.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
106
# TODO - try to scale a non-128 icon...? Try to convert an SVG on the fly?
107
message(STATUS "Unable to find an 128x128 icon that matches pattern ${pattern} for variable ${appsources} - application will not have an application icon!")
110
else(SIPS_EXECUTABLE AND TIFF2ICNS_EXECUTABLE)
111
message(STATUS "Unable to find the sips and tiff2icns utilities - application will not have an application icon!")
112
endif(SIPS_EXECUTABLE AND TIFF2ICNS_EXECUTABLE)
114
endmacro (KDE4_ADD_APP_ICON)