Changeset View
Changeset View
Standalone View
Standalone View
modules/ECMAddAppIcon.cmake
1 | #.rst: | 1 | #.rst: | ||
---|---|---|---|---|---|
2 | # ECMAddAppIcon | 2 | # ECMAddAppIcon | ||
3 | # ------------- | 3 | # ------------- | ||
4 | # | 4 | # | ||
5 | # Add icons to executable files and packages. | 5 | # Add icons to executable files and packages. | ||
6 | # | 6 | # | ||
7 | # :: | 7 | # :: | ||
8 | # | 8 | # | ||
9 | # ecm_add_app_icon(<sources_var> | 9 | # ecm_add_app_icon(<sources_var> | ||
10 | # ICONS <icon> [<icon> [...]]) | 10 | # ICONS <icon> [<icon> [...]] | ||
11 | # [SIDEBAR_ICONS <icon> [<icon> [...]] # Since 5.48 | ||||
12 | # [OUTFILE_BASENAME <name>]) # Since 5.48 | ||||
krop: 5.48 | |||||
13 | # ) | ||||
11 | # | 14 | # | ||
12 | # The given icons, whose names must match the pattern:: | 15 | # The given icons, whose names must match the pattern:: | ||
13 | # | 16 | # | ||
14 | # <size>-<other_text>.png | 17 | # <size>-<other_text>.png | ||
15 | # | 18 | # | ||
16 | # will be added to the executable target whose sources are specified by | 19 | # will be added to the executable target whose sources are specified by | ||
17 | # ``<sources_var>`` on platforms that support it (Windows and Mac OS X). | 20 | # ``<sources_var>`` on platforms that support it (Windows and Mac OS X). | ||
18 | # Other icon files are ignored but on Mac SVG files can be supported and | 21 | # Other icon files are ignored but on Mac SVG files can be supported and | ||
19 | # it is thus possible to mix those with png files in a single macro call. | 22 | # it is thus possible to mix those with png files in a single macro call. | ||
20 | # | 23 | # | ||
21 | # ``<size>`` is a numeric pixel size (typically 16, 32, 48, 64, 128 or 256). | 24 | # ``<size>`` is a numeric pixel size (typically 16, 32, 48, 64, 128 or 256). | ||
22 | # ``<other_text>`` can be any other text. See the platform notes below for any | 25 | # ``<other_text>`` can be any other text. See the platform notes below for any | ||
23 | # recommendations about icon sizes. | 26 | # recommendations about icon sizes. | ||
24 | # | 27 | # | ||
28 | # ``SIDEBAR_ICONS`` can be used to add Mac OS X sidebar | ||||
29 | # icons to the generated iconset. They are used when a folder monitored by the | ||||
30 | # application is dragged into Finder's sidebar. Since 5.48. | ||||
krop: 5.48 | |||||
31 | # | ||||
32 | # ``OUTFILE_BASENAME`` will be used as the basename for the icon file. If | ||||
33 | # you specify it, the icon file will be called ``<OUTFILE_BASENAME>.icns`` on Mac OS X | ||||
34 | # and ``<OUTFILE_BASENAME>.ico`` on Windows. If you don't specify it, it defaults | ||||
35 | # to ``<sources_var>.<ext>``. Since 5.48. | ||||
krop: 5.48 | |||||
36 | # | ||||
37 | # | ||||
25 | # Windows notes | 38 | # Windows notes | ||
26 | # * Icons are compiled into the executable using a resource file. | 39 | # * Icons are compiled into the executable using a resource file. | ||
27 | # * Icons may not show up in Windows Explorer if the executable | 40 | # * Icons may not show up in Windows Explorer if the executable | ||
28 | # target does not have the ``WIN32_EXECUTABLE`` property set. | 41 | # target does not have the ``WIN32_EXECUTABLE`` property set. | ||
29 | # * The tool png2ico is required. See :find-module:`FindPng2Ico`. | 42 | # * One of the tools png2ico (See :find-module:`FindPng2Ico`) or | ||
30 | # * Supported sizes: 16, 32, 48, 64, 128. | 43 | # icotool (see :find-module:`FindIcoTool`) is required. | ||
44 | # * Supported sizes: 16, 24, 32, 48, 64, 128, 256, 512 and 1024. | ||||
31 | # | 45 | # | ||
32 | # Mac OS X notes | 46 | # Mac OS X notes | ||
33 | # * The executable target must have the ``MACOSX_BUNDLE`` property set. | 47 | # * The executable target must have the ``MACOSX_BUNDLE`` property set. | ||
34 | # * Icons are added to the bundle. | 48 | # * Icons are added to the bundle. | ||
35 | # * If the ksvg2icns tool from KIconThemes is available, .svg and .svgz | 49 | # * If the ksvg2icns tool from KIconThemes is available, .svg and .svgz | ||
36 | # files are accepted; the first that is converted successfully to .icns | 50 | # files are accepted; the first that is converted successfully to .icns | ||
37 | # will provide the application icon. SVG files are ignored otherwise. | 51 | # will provide the application icon. SVG files are ignored otherwise. | ||
38 | # * The tool iconutil (provided by Apple) is required for bitmap icons. | 52 | # * The tool iconutil (provided by Apple) is required for bitmap icons. | ||
39 | # * Supported sizes: 16, 32, 64, 128, 256 (and 512, 1024 after OS X 10.9). | 53 | # * Supported sizes: 16, 32, 64, 128, 256 (and 512, 1024 after OS X 10.9). | ||
40 | # * At least a 128x128px (or an SVG) icon is required. | 54 | # * At least a 128x128px (or an SVG) icon is required. | ||
41 | # * Larger sizes are automatically used to substitute for smaller sizes on | 55 | # * Larger sizes are automatically used to substitute for smaller sizes on | ||
42 | # "Retina" (high-resolution) displays. For example, a 32px icon, if | 56 | # "Retina" (high-resolution) displays. For example, a 32px icon, if | ||
43 | # provided, will be used as a 32px icon on standard-resolution displays, | 57 | # provided, will be used as a 32px icon on standard-resolution displays, | ||
44 | # and as a 16px-equivalent icon (with an "@2x" tag) on high-resolution | 58 | # and as a 16px-equivalent icon (with an "@2x" tag) on high-resolution | ||
45 | # displays. ksvg2icns handles this internally. | 59 | # displays. That is why you should provide 64px and 1024px icons although | ||
60 | # they are not supported anymore directly. Instead they will be used as | ||||
61 | # 32px@2x and 512px@2x. ksvg2icns handles this internally. | ||||
46 | # * This function sets the ``MACOSX_BUNDLE_ICON_FILE`` variable to the name | 62 | # * This function sets the ``MACOSX_BUNDLE_ICON_FILE`` variable to the name | ||
47 | # of the generated icns file, so that it will be used as the | 63 | # of the generated icns file, so that it will be used as the | ||
48 | # ``MACOSX_BUNDLE_ICON_FILE`` target property when you call | 64 | # ``MACOSX_BUNDLE_ICON_FILE`` target property when you call | ||
49 | # ``add_executable``. | 65 | # ``add_executable``. | ||
66 | # * Sidebar icons should typically provided in 16, 32, 64, 128 and 256px. | ||||
50 | # | 67 | # | ||
51 | # Since 1.7.0. | 68 | # Since 1.7.0. | ||
52 | 69 | | |||
70 | | ||||
krop: extra line that shouldn't be there | |||||
53 | #============================================================================= | 71 | #============================================================================= | ||
54 | # Copyright 2014 Alex Merry <alex.merry@kde.org> | 72 | # Copyright 2014 Alex Merry <alex.merry@kde.org> | ||
55 | # Copyright 2014 Ralf Habacker <ralf.habacker@freenet.de> | 73 | # Copyright 2014 Ralf Habacker <ralf.habacker@freenet.de> | ||
56 | # Copyright 2006-2009 Alexander Neundorf, <neundorf@kde.org> | 74 | # Copyright 2006-2009 Alexander Neundorf, <neundorf@kde.org> | ||
57 | # Copyright 2006, 2007, Laurent Montel, <montel@kde.org> | 75 | # Copyright 2006, 2007, Laurent Montel, <montel@kde.org> | ||
58 | # Copyright 2007 Matthias Kretz <kretz@kde.org> | 76 | # Copyright 2007 Matthias Kretz <kretz@kde.org> | ||
59 | # | 77 | # | ||
60 | # Redistribution and use in source and binary forms, with or without | 78 | # Redistribution and use in source and binary forms, with or without | ||
Show All 18 Lines | |||||
79 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 97 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
80 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 98 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
81 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 99 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
82 | 100 | | |||
83 | include(CMakeParseArguments) | 101 | include(CMakeParseArguments) | ||
84 | 102 | | |||
85 | function(ecm_add_app_icon appsources) | 103 | function(ecm_add_app_icon appsources) | ||
86 | set(options) | 104 | set(options) | ||
87 | set(oneValueArgs) | 105 | set(oneValueArgs OUTFILE_BASENAME) | ||
88 | set(multiValueArgs ICONS) | 106 | set(multiValueArgs ICONS SIDEBAR_ICONS) | ||
89 | cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) | 107 | cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) | ||
ECMAddAppIcon has an unit test in tests/ECMAddAppIconTest/ krop: ECMAddAppIcon has an unit test in tests/ECMAddAppIconTest/
Please check if you can test the new… | |||||
Added a test for OUTFILE_BASENAME and WIP for SIDEBAR_ICONS. Need to get my hands on a macOS system to test further... dschmidt: Added a test for OUTFILE_BASENAME and WIP for SIDEBAR_ICONS.
Need to get my hands on a macOS… | |||||
90 | 108 | | |||
91 | if(NOT ARG_ICONS) | 109 | if(NOT ARG_ICONS) | ||
92 | message(FATAL_ERROR "No ICONS argument given to ecm_add_app_icon") | 110 | message(FATAL_ERROR "No ICONS argument given to ecm_add_app_icon") | ||
93 | endif() | 111 | endif() | ||
94 | if(ARG_UNPARSED_ARGUMENTS) | 112 | if(ARG_UNPARSED_ARGUMENTS) | ||
95 | message(FATAL_ERROR "Unexpected arguments to ecm_add_app_icon: ${ARG_UNPARSED_ARGUMENTS}") | 113 | message(FATAL_ERROR "Unexpected arguments to ecm_add_app_icon: ${ARG_UNPARSED_ARGUMENTS}") | ||
96 | endif() | 114 | endif() | ||
97 | 115 | | |||
Show All 17 Lines | 128 | else() | |||
115 | set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${icon_name}.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources) | 133 | set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${icon_name}.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources) | ||
116 | # we're done now | 134 | # we're done now | ||
117 | return() | 135 | return() | ||
118 | endif() | 136 | endif() | ||
119 | endif() | 137 | endif() | ||
120 | endforeach() | 138 | endforeach() | ||
121 | endif() | 139 | endif() | ||
122 | 140 | | |||
123 | set(known_sizes 16 32 48 64 128 256 512 1024) | | |||
124 | foreach(size ${known_sizes}) | | |||
125 | set(icons_at_${size}px) | | |||
126 | endforeach() | | |||
127 | 141 | | |||
128 | foreach(icon ${ARG_ICONS}) | 142 | _ecm_add_app_icon_categorize_icons("${ARG_ICONS}" "icons" "16;24;32;48;64;128;256;512;1024") | ||
129 | get_filename_component(icon_full ${icon} ABSOLUTE) | 143 | if(ARG_SIDEBAR_ICONS) | ||
130 | if (NOT EXISTS "${icon_full}") | 144 | _ecm_add_app_icon_categorize_icons("${ARG_SIDEBAR_ICONS}" "sidebar_icons" "16;32;64;128;256") | ||
131 | message(AUTHOR_WARNING "${icon_full} does not exist, ignoring") | | |||
132 | else() | | |||
133 | get_filename_component(icon_name ${icon} NAME) | | |||
134 | string(REGEX MATCH "([0-9]+)\\-[^/]+\\.([a-z]+)$" | | |||
135 | _dummy "${icon_name}") | | |||
136 | set(size "${CMAKE_MATCH_1}") | | |||
137 | set(ext "${CMAKE_MATCH_2}") | | |||
138 | if (NOT (ext STREQUAL "svg" OR ext STREQUAL "svgz")) | | |||
139 | if (NOT size) | | |||
140 | message(AUTHOR_WARNING "${icon_full} is not named correctly for ecm_add_app_icon - ignoring") | | |||
141 | elseif (NOT ext STREQUAL "png") | | |||
142 | message(AUTHOR_WARNING "${icon_full} is not a png file - ignoring") | | |||
143 | else() | | |||
144 | list(FIND known_sizes "${size}" offset) | | |||
145 | if (offset GREATER -1) | | |||
146 | list(APPEND icons_at_${size}px "${icon_full}") | | |||
147 | endif() | | |||
148 | endif() | | |||
149 | endif() | 145 | endif() | ||
krop: 24 is mentioned in the doc but unused here. Is it expected? | |||||
150 | endif() | | |||
151 | endforeach() | | |||
152 | 146 | | |||
153 | set(mac_icons ${icons_at_16px} | 147 | set(mac_icons | ||
148 | # Icons: https://developer.apple.com/library/content/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Optimizing/Optimizing.html#//apple_ref/doc/uid/TP40012302-CH7-SW4 | ||||
149 | ${icons_at_16px} | ||||
154 | ${icons_at_32px} | 150 | ${icons_at_32px} | ||
155 | ${icons_at_64px} | 151 | ${icons_at_64px} | ||
156 | ${icons_at_128px} | 152 | ${icons_at_128px} | ||
157 | ${icons_at_256px} | 153 | ${icons_at_256px} | ||
158 | ${icons_at_512px} | 154 | ${icons_at_512px} | ||
159 | ${icons_at_1024px}) | 155 | ${icons_at_1024px}) | ||
160 | if (NOT icons_at_128px) | 156 | | ||
161 | message(AUTHOR_WARNING "No 128px icon provided; this will not work on Mac OS X") | 157 | set(mac_sidebar_icons | ||
158 | # Sidebar Icons: https://developer.apple.com/library/content/documentation/General/Conceptual/ExtensibilityPG/Finder.html#//apple_ref/doc/uid/TP40014214-CH15-SW15 | ||||
159 | ${sidebar_icons_at_16px} | ||||
160 | ${sidebar_icons_at_32px} | ||||
161 | ${sidebar_icons_at_64px} | ||||
krop: 36? It's not mentioned in the doc. | |||||
Good catch, I forgot to update this part after I fixed the resolutions in a different place.. The resolutions I copied from the original ownCloud macro were wrong in the first place, maybe because Apple changed the rules/resolutions at some point. dschmidt: Good catch, I forgot to update this part after I fixed the resolutions in a different place.. | |||||
162 | ${sidebar_icons_at_128px} | ||||
163 | ${sidebar_icons_at_256px}) | ||||
164 | | ||||
165 | if (NOT (mac_icons OR mac_sidebar_icons)) | ||||
166 | message(AUTHOR_WARNING "No icons suitable for use on macOS provided") | ||||
162 | endif() | 167 | endif() | ||
163 | 168 | | |||
164 | set(windows_icons ${icons_at_16px} | 169 | | ||
170 | set(windows_icons_classic ${icons_at_16px} | ||||
171 | ${icons_at_24px} | ||||
165 | ${icons_at_32px} | 172 | ${icons_at_32px} | ||
166 | ${icons_at_48px} | 173 | ${icons_at_48px} | ||
167 | ${icons_at_64px} | 174 | ${icons_at_64px} | ||
168 | ${icons_at_128px}) | 175 | ${icons_at_128px}) | ||
169 | if (NOT windows_icons) | 176 | set(windows_icons_modern ${windows_icons_classic} | ||
177 | ${icons_at_256px} | ||||
178 | ${icons_at_512px} | ||||
179 | ${icons_at_1024px}) | ||||
180 | | ||||
181 | if (NOT (windows_icons_modern OR windows_icons_classic)) | ||||
170 | message(AUTHOR_WARNING "No icons suitable for use on Windows provided") | 182 | message(AUTHOR_WARNING "No icons suitable for use on Windows provided") | ||
171 | endif() | 183 | endif() | ||
172 | 184 | | |||
173 | set (_outfilename "${CMAKE_CURRENT_BINARY_DIR}/${appsources}") | 185 | if (ARG_OUTFILE_BASENAME) | ||
186 | set (_outfilebasename "${ARG_OUTFILE_BASENAME}") | ||||
187 | else() | ||||
188 | set (_outfilebasename "${appsources}") | ||||
189 | endif() | ||||
190 | set (_outfilename "${CMAKE_CURRENT_BINARY_DIR}/${_outfilebasename}") | ||||
174 | 191 | | |||
175 | if (WIN32 AND windows_icons) | 192 | if (WIN32 AND (windows_icons_modern OR windows_icons_classic)) | ||
176 | set(saved_CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}") | 193 | set(saved_CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}") | ||
177 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_FIND_MODULE_DIR}) | 194 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_FIND_MODULE_DIR}) | ||
178 | find_package(Png2Ico) | 195 | find_package(Png2Ico) | ||
196 | find_package(IcoTool) | ||||
179 | set(CMAKE_MODULE_PATH "${saved_CMAKE_MODULE_PATH}") | 197 | set(CMAKE_MODULE_PATH "${saved_CMAKE_MODULE_PATH}") | ||
180 | 198 | | |||
181 | if (Png2Ico_FOUND) | 199 | function(create_windows_icon_and_rc command args deps) | ||
182 | if (Png2Ico_HAS_RCFILE_ARGUMENT) | | |||
183 | add_custom_command( | | |||
184 | OUTPUT "${_outfilename}.rc" "${_outfilename}.ico" | | |||
185 | COMMAND Png2Ico::Png2Ico | | |||
186 | ARGS | | |||
187 | --rcfile "${_outfilename}.rc" | | |||
188 | "${_outfilename}.ico" | | |||
189 | ${windows_icons} | | |||
190 | DEPENDS ${windows_icons} | | |||
191 | WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" | | |||
192 | ) | | |||
193 | else() | | |||
194 | add_custom_command( | 200 | add_custom_command( | ||
195 | OUTPUT "${_outfilename}.ico" | 201 | OUTPUT "${_outfilename}.ico" | ||
196 | COMMAND Png2Ico::Png2Ico | 202 | COMMAND ${command} | ||
197 | ARGS "${_outfilename}.ico" ${windows_icons} | 203 | ARGS ${args} | ||
198 | DEPENDS ${windows_icons} | 204 | DEPENDS ${deps} | ||
199 | WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" | 205 | WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" | ||
200 | ) | 206 | ) | ||
201 | # this bit's a little hacky to make the dependency stuff work | 207 | # this bit's a little hacky to make the dependency stuff work | ||
202 | file(WRITE "${_outfilename}.rc.in" "IDI_ICON1 ICON DISCARDABLE \"${_outfilename}.ico\"\n") | 208 | file(WRITE "${_outfilename}.rc.in" "IDI_ICON1 ICON DISCARDABLE \"${_outfilename}.ico\"\n") | ||
203 | add_custom_command( | 209 | add_custom_command( | ||
204 | OUTPUT "${_outfilename}.rc" | 210 | OUTPUT "${_outfilename}.rc" | ||
205 | COMMAND ${CMAKE_COMMAND} | 211 | COMMAND ${CMAKE_COMMAND} | ||
206 | ARGS -E copy "${_outfilename}.rc.in" "${_outfilename}.rc" | 212 | ARGS -E copy "${_outfilename}.rc.in" "${_outfilename}.rc" | ||
207 | DEPENDS "${_outfilename}.ico" | 213 | DEPENDS "${_outfilename}.ico" | ||
208 | WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" | 214 | WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" | ||
209 | ) | 215 | ) | ||
216 | endfunction() | ||||
217 | | ||||
218 | if (IcoTool_FOUND) | ||||
219 | list(APPEND icotool_args "-c" "-o" "${_outfilename}.ico") | ||||
220 | | ||||
221 | # According to https://stackoverflow.com/a/40851713/2886832 | ||||
222 | # Windows always chooses the first icon above 255px, all other ones will be ignored | ||||
223 | set(maxSize 0) | ||||
224 | foreach(size 256 512 1024) | ||||
225 | if(icons_at_${size}px) | ||||
226 | set(maxSize "${size}") | ||||
210 | endif() | 227 | endif() | ||
228 | endforeach() | ||||
229 | | ||||
230 | foreach(size 16 24 32 48 64 128 ${maxSize}) | ||||
krop: not 24 ? | |||||
231 | if(NOT icons_at_${size}px) | ||||
232 | continue() | ||||
233 | endif() | ||||
234 | | ||||
235 | set(icotool_icon_arg "") | ||||
236 | if(size STREQUAL "${maxSize}") | ||||
237 | # maxSize icon needs to be included as raw png | ||||
238 | list(APPEND icotool_args "-r") | ||||
239 | endif() | ||||
240 | | ||||
241 | foreach(icon ${icons_at_${size}px}) | ||||
242 | list(APPEND icotool_args "${icons_at_${size}px}") | ||||
243 | endforeach() | ||||
244 | endforeach() | ||||
245 | | ||||
246 | create_windows_icon_and_rc(IcoTool::IcoTool "${icotool_args}" "${windows_icons_modern}") | ||||
211 | set(${appsources} "${${appsources}};${_outfilename}.rc" PARENT_SCOPE) | 247 | set(${appsources} "${${appsources}};${_outfilename}.rc" PARENT_SCOPE) | ||
248 | | ||||
249 | # standard png2ico has no rcfile argument | ||||
250 | elseif(Png2Ico_FOUND AND NOT Png2Ico_HAS_RCFILE_ARGUMENT AND windows_icons_classic) | ||||
251 | set(png2ico_args) | ||||
252 | list(APPEND png2ico_args "${_outfilename}.ico") | ||||
253 | list(APPEND png2ico_args "${windows_icons_classic}") | ||||
254 | | ||||
255 | create_windows_icon_and_rc(Png2Ico::Png2Ico "${png2ico_args}" "${windows_icons_classic}") | ||||
256 | set(${appsources} "${${appsources}};${_outfilename}.rc" PARENT_SCOPE) | ||||
257 | | ||||
258 | # png2ico from kdewin provides rcfile argument | ||||
259 | elseif(Png2Ico_FOUND AND windows_icons_classic) | ||||
260 | add_custom_command( | ||||
261 | OUTPUT "${_outfilename}.rc" "${_outfilename}.ico" | ||||
262 | COMMAND Png2Ico::Png2Ico | ||||
263 | ARGS | ||||
264 | --rcfile "${_outfilename}.rc" | ||||
265 | "${_outfilename}.ico" | ||||
266 | ${windows_icons_classic} | ||||
267 | DEPENDS ${windows_icons_classic} | ||||
268 | WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" | ||||
269 | ) | ||||
270 | | ||||
271 | set(${appsources} "${${appsources}};${_outfilename}.rc" PARENT_SCOPE) | ||||
272 | # else none of the supported tools was found | ||||
212 | else() | 273 | else() | ||
213 | message(WARNING "Unable to find the png2ico utility - application will not have an application icon!") | 274 | message(WARNING "Unable to find the png2ico or icotool utilities or icons in matching sizes - application will not have an application icon!") | ||
214 | endif() | 275 | endif() | ||
215 | elseif (APPLE AND mac_icons) | 276 | elseif (APPLE AND (mac_icons OR mac_sidebar_icons)) | ||
216 | # first generate .iconset directory structure, then convert to .icns format using the Mac OS X "iconutil" utility, | 277 | # first generate .iconset directory structure, then convert to .icns format using the Mac OS X "iconutil" utility, | ||
217 | # to create retina compatible icon, you need png source files in pixel resolution 16x16, 32x32, 64x64, 128x128, | 278 | # to create retina compatible icon, you need png source files in pixel resolution 16x16, 32x32, 64x64, 128x128, | ||
218 | # 256x256, 512x512, 1024x1024 | 279 | # 256x256, 512x512, 1024x1024 | ||
219 | find_program(ICONUTIL_EXECUTABLE NAMES iconutil) | 280 | find_program(ICONUTIL_EXECUTABLE NAMES iconutil) | ||
220 | if (ICONUTIL_EXECUTABLE) | 281 | if (ICONUTIL_EXECUTABLE) | ||
221 | add_custom_command( | 282 | add_custom_command( | ||
222 | OUTPUT "${_outfilename}.iconset" | 283 | OUTPUT "${_outfilename}.iconset" | ||
223 | COMMAND ${CMAKE_COMMAND} | 284 | COMMAND ${CMAKE_COMMAND} | ||
224 | ARGS -E make_directory "${_outfilename}.iconset" | 285 | ARGS -E make_directory "${_outfilename}.iconset" | ||
225 | ) | 286 | ) | ||
226 | set(iconset_icons) | 287 | set(iconset_icons) | ||
227 | macro(copy_icon filename sizename) | 288 | macro(copy_icon filename sizename type) | ||
228 | add_custom_command( | 289 | add_custom_command( | ||
229 | OUTPUT "${_outfilename}.iconset/icon_${sizename}.png" | 290 | OUTPUT "${_outfilename}.iconset/${type}_${sizename}.png" | ||
230 | COMMAND ${CMAKE_COMMAND} | 291 | COMMAND ${CMAKE_COMMAND} | ||
231 | ARGS -E copy | 292 | ARGS -E copy | ||
232 | "${filename}" | 293 | "${filename}" | ||
233 | "${_outfilename}.iconset/icon_${sizename}.png" | 294 | "${_outfilename}.iconset/${type}_${sizename}.png" | ||
234 | DEPENDS | 295 | DEPENDS | ||
235 | "${_outfilename}.iconset" | 296 | "${_outfilename}.iconset" | ||
236 | "${filename}" | 297 | "${filename}" | ||
237 | WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" | 298 | WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" | ||
238 | ) | 299 | ) | ||
239 | list(APPEND iconset_icons | 300 | list(APPEND iconset_icons | ||
240 | "${_outfilename}.iconset/icon_${sizename}.png") | 301 | "${_outfilename}.iconset/${type}_${sizename}.png") | ||
241 | endmacro() | 302 | endmacro() | ||
242 | foreach(size 16 32 64 128 256 512) | 303 | | ||
304 | # List of supported sizes and filenames taken from: | ||||
305 | # https://developer.apple.com/library/content/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Optimizing/Optimizing.html#//apple_ref/doc/uid/TP40012302-CH7-SW4 | ||||
306 | foreach(size 16 32 128 256 512) | ||||
243 | math(EXPR double_size "2 * ${size}") | 307 | math(EXPR double_size "2 * ${size}") | ||
244 | foreach(file ${icons_at_${size}px}) | 308 | foreach(file ${icons_at_${size}px}) | ||
245 | copy_icon("${file}" "${size}x${size}") | 309 | copy_icon("${file}" "${size}x${size}" "icon") | ||
246 | endforeach() | 310 | endforeach() | ||
247 | foreach(file ${icons_at_${double_size}px}) | 311 | foreach(file ${icons_at_${double_size}px}) | ||
248 | copy_icon("${file}" "${size}x${size}@2x") | 312 | copy_icon("${file}" "${size}x${size}@2x" "icon") | ||
249 | endforeach() | 313 | endforeach() | ||
250 | endforeach() | 314 | endforeach() | ||
251 | 315 | | |||
316 | # List of supported sizes and filenames taken from: | ||||
317 | # https://developer.apple.com/library/content/documentation/General/Conceptual/ExtensibilityPG/Finder.html#//apple_ref/doc/uid/TP40014214-CH15-SW15 | ||||
318 | foreach(file ${sidebar_icons_at_16px}) | ||||
319 | copy_icon("${file}" "16x16" "sidebar") | ||||
320 | endforeach() | ||||
321 | foreach(file ${sidebar_icons_at_32px}) | ||||
322 | copy_icon("${file}" "16x16@2x" "sidebar") | ||||
323 | endforeach() | ||||
324 | foreach(file ${sidebar_icons_at_32px}) | ||||
325 | copy_icon("${file}" "18x18" "sidebar") | ||||
326 | endforeach() | ||||
327 | foreach(file ${sidebar_icons_at_64px}) | ||||
328 | copy_icon("${file}" "18x18@2x" "sidebar") | ||||
329 | endforeach() | ||||
330 | foreach(file ${sidebar_icons_at_128px}) | ||||
331 | copy_icon("${file}" "32x32" "sidebar") | ||||
332 | endforeach() | ||||
333 | foreach(file ${sidebar_icons_at_256px}) | ||||
334 | copy_icon("${file}" "32x32@2x" "sidebar") | ||||
335 | endforeach() | ||||
336 | | ||||
252 | # generate .icns icon file | 337 | # generate .icns icon file | ||
253 | add_custom_command( | 338 | add_custom_command( | ||
254 | OUTPUT "${_outfilename}.icns" | 339 | OUTPUT "${_outfilename}.icns" | ||
255 | COMMAND ${ICONUTIL_EXECUTABLE} | 340 | COMMAND ${ICONUTIL_EXECUTABLE} | ||
256 | ARGS | 341 | ARGS | ||
257 | --convert icns | 342 | --convert icns | ||
258 | --output "${_outfilename}.icns" | 343 | --output "${_outfilename}.icns" | ||
259 | "${_outfilename}.iconset" | 344 | "${_outfilename}.iconset" | ||
260 | DEPENDS ${iconset_icons} | 345 | DEPENDS "${iconset_icons}" | ||
261 | WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" | 346 | WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" | ||
262 | ) | 347 | ) | ||
263 | # This will register the icon into the bundle | 348 | # This will register the icon into the bundle | ||
264 | set(MACOSX_BUNDLE_ICON_FILE ${appsources}.icns PARENT_SCOPE) | 349 | set(MACOSX_BUNDLE_ICON_FILE "${_outfilebasename}.icns" PARENT_SCOPE) | ||
265 | 350 | | |||
266 | # Append the icns file to the sources list so it will be a dependency to the | 351 | # Append the icns file to the sources list so it will be a dependency to the | ||
267 | # main target | 352 | # main target | ||
268 | set(${appsources} "${${appsources}};${_outfilename}.icns" PARENT_SCOPE) | 353 | set(${appsources} "${${appsources}};${_outfilename}.icns" PARENT_SCOPE) | ||
269 | 354 | | |||
270 | # Install the icon into the Resources dir in the bundle | 355 | # Install the icon into the Resources dir in the bundle | ||
271 | set_source_files_properties(${_outfilename}.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources) | 356 | set_source_files_properties("${_outfilename}.icns" PROPERTIES MACOSX_PACKAGE_LOCATION Resources) | ||
272 | else() | 357 | else() | ||
273 | message(STATUS "Unable to find the iconutil utility - application will not have an application icon!") | 358 | message(STATUS "Unable to find the iconutil utility - application will not have an application icon!") | ||
274 | endif() | 359 | endif() | ||
275 | endif() | 360 | endif() | ||
276 | endfunction() | 361 | endfunction() | ||
362 | | ||||
363 | macro(_ecm_add_app_icon_categorize_icons icons type known_sizes) | ||||
364 | set(_${type}_known_sizes) | ||||
365 | foreach(size ${known_sizes}) | ||||
366 | set(${type}_at_${size}px) | ||||
367 | list(APPEND _${type}_known_sizes ${size}) | ||||
368 | endforeach() | ||||
369 | | ||||
370 | | ||||
371 | foreach(icon ${icons}) | ||||
372 | get_filename_component(icon_full ${icon} ABSOLUTE) | ||||
373 | if (NOT EXISTS "${icon_full}") | ||||
374 | message(AUTHOR_WARNING "${icon_full} does not exist, ignoring") | ||||
375 | else() | ||||
376 | get_filename_component(icon_name ${icon} NAME) | ||||
377 | string(REGEX MATCH "([0-9]+)\\-[^/]+\\.([a-z]+)$" | ||||
378 | _dummy "${icon_name}") | ||||
379 | set(size "${CMAKE_MATCH_1}") | ||||
380 | set(ext "${CMAKE_MATCH_2}") | ||||
381 | | ||||
382 | if (NOT (ext STREQUAL "svg" OR ext STREQUAL "svgz")) | ||||
383 | if (NOT size) | ||||
384 | message(AUTHOR_WARNING "${icon_full} is not named correctly for ecm_add_app_icon - ignoring") | ||||
385 | elseif (NOT ext STREQUAL "png") | ||||
386 | message(AUTHOR_WARNING "${icon_full} is not a png file - ignoring") | ||||
387 | else() | ||||
388 | list(FIND _${type}_known_sizes ${size} offset) | ||||
389 | | ||||
390 | if (offset GREATER -1) | ||||
391 | list(APPEND ${type}_at_${size}px "${icon_full}") | ||||
392 | elseif() | ||||
393 | message(STATUS "not found ${type}_at_${size}px ${icon_full}") | ||||
394 | endif() | ||||
395 | endif() | ||||
396 | endif() | ||||
397 | endif() | ||||
398 | endforeach() | ||||
399 | endmacro() |
5.48