2014-11-19 14:46:19 +03:00
SET ( WINDRES_EXECUTABLE_BASE ${ CMAKE_RC_COMPILER } )
2012-04-02 15:44:24 +04:00
# This macro is taken from kdelibs/cmake/modules/KDE4Macros.cmake.
#
# Copyright (c) 2006-2009 Alexander Neundorf, <neundorf@kde.org>
# Copyright (c) 2006, 2007, Laurent Montel, <montel@kde.org>
# Copyright (c) 2007 Matthias Kretz <kretz@kde.org>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file [in KDE repositories].
# adds application icon to target source list
# for detailed documentation see the top of FindKDE4Internal.cmake
macro ( KDE4_ADD_APP_ICON appsources pattern )
set ( _outfilename ${ CMAKE_CURRENT_BINARY_DIR } / ${ appsources } )
if ( WIN32 )
if ( NOT WINCE )
find_program ( PNG2ICO_EXECUTABLE NAMES png2ico )
else ( NOT WINCE )
find_program ( PNG2ICO_EXECUTABLE NAMES png2ico PATHS ${ HOST_BINDIR } NO_DEFAULT_PATH )
endif ( NOT WINCE )
2014-11-19 14:46:19 +03:00
find_program ( WINDRES_EXECUTABLE NAMES ${ WINDRES_EXECUTABLE_BASE } )
2012-04-02 15:44:24 +04:00
if ( MSVC )
set ( WINDRES_EXECUTABLE TRUE )
endif ( MSVC )
if ( PNG2ICO_EXECUTABLE AND WINDRES_EXECUTABLE )
2012-05-02 18:33:07 +04:00
string ( REPLACE "*" "([0123456789]*)" pattern_rx "${pattern}" )
2012-04-02 15:44:24 +04:00
file ( GLOB files "${pattern}" )
foreach ( it ${ files } )
string ( REGEX REPLACE "${pattern_rx}" "\\1" fn "${it}" )
if ( fn MATCHES ".*16.*" )
list ( APPEND _icons ${ it } )
endif ( fn MATCHES ".*16.*" )
if ( fn MATCHES ".*32.*" )
list ( APPEND _icons ${ it } )
endif ( fn MATCHES ".*32.*" )
if ( fn MATCHES ".*48.*" )
list ( APPEND _icons ${ it } )
endif ( fn MATCHES ".*48.*" )
if ( fn MATCHES ".*64.*" )
list ( APPEND _icons ${ it } )
endif ( fn MATCHES ".*64.*" )
if ( fn MATCHES ".*128.*" )
list ( APPEND _icons ${ it } )
endif ( fn MATCHES ".*128.*" )
2018-08-28 11:06:28 +03:00
if ( fn MATCHES ".*256.*" )
list ( APPEND _icons ${ it } )
2019-09-03 18:54:22 +03:00
endif ( fn MATCHES ".*256.*" )
if ( fn MATCHES ".*512.*" )
list ( APPEND _icons ${ it } )
endif ( fn MATCHES ".*512.*" )
if ( fn MATCHES ".*1024.*" )
list ( APPEND _icons ${ it } )
endif ( fn MATCHES ".*1024.*" )
2012-04-02 15:44:24 +04:00
endforeach ( it )
if ( _icons )
add_custom_command ( OUTPUT ${ _outfilename } .ico ${ _outfilename } .rc
C O M M A N D $ { P N G 2 I C O _ E X E C U T A B L E } A R G S - - r c f i l e $ { _ o u t f i l e n a m e } . r c $ { _ o u t f i l e n a m e } . i c o $ { _ i c o n s }
D E P E N D S $ { P N G 2 I C O _ E X E C U T A B L E } $ { _ i c o n s }
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R }
)
if ( MINGW )
add_custom_command ( OUTPUT ${ _outfilename } _res.o
C O M M A N D $ { W I N D R E S _ E X E C U T A B L E } A R G S - i $ { _ o u t f i l e n a m e } . r c - o $ { _ o u t f i l e n a m e } _ r e s . o - - i n c l u d e - d i r = $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R }
D E P E N D S $ { W I N D R E S _ E X E C U T A B L E } $ { _ o u t f i l e n a m e } . r c
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R }
)
list ( APPEND ${ appsources } ${ _outfilename } _res.o )
else ( MINGW )
list ( APPEND ${ appsources } ${ _outfilename } .rc )
endif ( MINGW )
else ( _icons )
message ( STATUS "Unable to find a related icon that matches pattern ${pattern} for variable ${appsources} - application will not have an application icon!" )
endif ( _icons )
else ( PNG2ICO_EXECUTABLE AND WINDRES_EXECUTABLE )
2014-02-10 17:36:32 +04:00
message ( WARNING "Unable to find the png2ico or windres utilities - application will not have an application icon!" )
2012-04-02 15:44:24 +04:00
endif ( PNG2ICO_EXECUTABLE AND WINDRES_EXECUTABLE )
endif ( WIN32 )
2014-02-04 11:36:59 +04:00
if ( APPLE )
2017-07-28 18:51:52 +03:00
file ( GLOB_RECURSE files "${pattern}" )
file ( MAKE_DIRECTORY ${ appsources } .iconset )
2012-04-02 15:44:24 +04:00
2017-07-28 18:51:52 +03:00
# List from:
# https://developer.apple.com/library/content/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Optimizing/Optimizing.html#//apple_ref/doc/uid/TP40012302-CH7-SW4
foreach ( it ${ files } )
if ( it MATCHES ".*icon-16.*" )
configure_file ( ${ it } ${ appsources } .iconset/icon_16x16.png COPYONLY )
elseif ( it MATCHES ".*icon-32.*" )
configure_file ( ${ it } ${ appsources } .iconset/icon_16x16@2x.png COPYONLY )
configure_file ( ${ it } ${ appsources } .iconset/icon_32x32.png COPYONLY )
elseif ( it MATCHES ".*icon-64.*" )
configure_file ( ${ it } ${ appsources } .iconset/icon_32x32@2x.png COPYONLY )
elseif ( it MATCHES ".*icon-128.*" )
configure_file ( ${ it } ${ appsources } .iconset/icon_128x128.png COPYONLY )
elseif ( it MATCHES ".*icon-256.*" )
configure_file ( ${ it } ${ appsources } .iconset/icon_128x128@2x.png COPYONLY )
configure_file ( ${ it } ${ appsources } .iconset/icon_256x256.png COPYONLY )
elseif ( it MATCHES ".*icon-512.*" )
configure_file ( ${ it } ${ appsources } .iconset/icon_256x256@2x.png COPYONLY )
configure_file ( ${ it } ${ appsources } .iconset/icon_512x512.png COPYONLY )
elseif ( it MATCHES ".*icon-1024.*" )
configure_file ( ${ it } ${ appsources } .iconset/icon_512x512@2x.png COPYONLY )
endif ( )
endforeach ( it )
2012-04-02 15:44:24 +04:00
2017-07-28 18:51:52 +03:00
# Copy the sidebar icons in the main app bundle for the FinderSync extension to pick.
# https://developer.apple.com/library/content/documentation/General/Conceptual/ExtensibilityPG/Finder.html#//apple_ref/doc/uid/TP40014214-CH15-SW15
foreach ( it ${ files } )
if ( it MATCHES ".*sidebar-16.*" )
configure_file ( ${ it } ${ appsources } .iconset/sidebar_16x16.png COPYONLY )
elseif ( it MATCHES ".*sidebar-32.*" )
2019-09-03 18:54:22 +03:00
configure_file ( ${ it } ${ appsources } .iconset/sidebar_18x18.png COPYONLY )
2017-07-28 18:51:52 +03:00
configure_file ( ${ it } ${ appsources } .iconset/sidebar_16x16@2x.png COPYONLY )
elseif ( it MATCHES ".*sidebar-64.*" )
2019-09-03 18:54:22 +03:00
configure_file ( ${ it } ${ appsources } .iconset/sidebar_18x18@2x.png COPYONLY )
elseif ( it MATCHES ".*sidebar-128.*" )
configure_file ( ${ it } ${ appsources } .iconset/sidebar_32x32.png COPYONLY )
elseif ( it MATCHES ".*sidebar-256.*" )
2017-07-28 18:51:52 +03:00
configure_file ( ${ it } ${ appsources } .iconset/sidebar_32x32@2x.png COPYONLY )
endif ( )
endforeach ( it )
2012-04-02 15:44:24 +04:00
2017-07-28 18:51:52 +03:00
add_custom_command ( OUTPUT ${ _outfilename } .icns
C O M M A N D e c h o = = = B u i l d i n g b u n d l e i c n s w i t h i c o n s e t :
C O M M A N D l s - 1 $ { a p p s o u r c e s } . i c o n s e t
C O M M A N D i c o n u t i l - c i c n s - o $ { _ o u t f i l e n a m e } . i c n s $ { a p p s o u r c e s } . i c o n s e t
D E P E N D S $ { f i l e s }
)
2012-04-02 15:44:24 +04:00
2017-07-28 18:51:52 +03:00
# This will register the icon into the bundle
set ( MACOSX_BUNDLE_ICON_FILE ${ appsources } .icns )
2012-04-02 15:44:24 +04:00
2017-07-28 18:51:52 +03:00
# Append the icns file to the sources list so it will be a dependency to the
# main target
list ( APPEND ${ appsources } ${ _outfilename } .icns )
2012-04-02 15:44:24 +04:00
2017-07-28 18:51:52 +03:00
# Install the icon into the Resources dir in the bundle
set_source_files_properties ( ${ _outfilename } .icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources )
2014-02-04 11:36:59 +04:00
endif ( APPLE )
2012-04-02 15:44:24 +04:00
endmacro ( KDE4_ADD_APP_ICON )