~ubuntu-branches/ubuntu/trusty/tomahawk/trusty-proposed

« back to all changes in this revision

Viewing changes to CMakeModules/AddAppIconMacro.cmake

  • Committer: Package Import Robot
  • Author(s): Harald Sitter
  • Date: 2013-03-07 21:50:13 UTC
  • Revision ID: package-import@ubuntu.com-20130307215013-6gdjkdds7i9uenvs
Tags: upstream-0.6.0+dfsg
ImportĀ upstreamĀ versionĀ 0.6.0+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
SET(WINDRES_EXECUTABLE  ${CMAKE_RC_COMPILER})
 
2
 
 
3
# This macro is taken from kdelibs/cmake/modules/KDE4Macros.cmake.
 
4
#
 
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>
 
8
#
 
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].
 
11
 
 
12
 
 
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})
 
17
 
 
18
    if (WIN32)
 
19
        if(NOT WINCE)
 
20
        find_program(PNG2ICO_EXECUTABLE NAMES png2ico)
 
21
        else(NOT WINCE)
 
22
        find_program(PNG2ICO_EXECUTABLE NAMES png2ico PATHS ${HOST_BINDIR} NO_DEFAULT_PATH )
 
23
        endif(NOT WINCE)
 
24
        find_program(WINDRES_EXECUTABLE NAMES windres)
 
25
        if(MSVC)
 
26
            set(WINDRES_EXECUTABLE TRUE)
 
27
        endif(MSVC)
 
28
        if (PNG2ICO_EXECUTABLE AND WINDRES_EXECUTABLE)
 
29
            string(REPLACE "*" "(.*)" pattern_rx "${pattern}")
 
30
            file(GLOB files  "${pattern}")
 
31
            foreach (it ${files})
 
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.*")
 
48
            endforeach (it)
 
49
            if (_icons)
 
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}
 
54
                                  )
 
55
                if (MINGW)
 
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}
 
60
                                      )
 
61
                    list(APPEND ${appsources} ${_outfilename}_res.o)
 
62
                else(MINGW)
 
63
                    list(APPEND ${appsources} ${_outfilename}.rc)
 
64
                endif(MINGW)
 
65
            else(_icons)
 
66
                message(STATUS "Unable to find a related icon that matches pattern ${pattern} for variable ${appsources} - application will not have an application icon!")
 
67
            endif(_icons)
 
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)
 
71
    endif(WIN32)
 
72
    if (Q_WS_MAC)
 
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
 
80
            foreach (it ${files})
 
81
                if (it MATCHES ".*128.*" )
 
82
                    set (_icon ${it})
 
83
                endif (it MATCHES ".*128.*")
 
84
            endforeach (it)
 
85
 
 
86
            if (_icon)
 
87
                
 
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
 
92
                                   DEPENDS ${_icon}
 
93
                                   )
 
94
 
 
95
                # This will register the icon into the bundle
 
96
                set(MACOSX_BUNDLE_ICON_FILE ${appsources}.icns)
 
97
 
 
98
                # Append the icns file to the sources list so it will be a dependency to the
 
99
                # main target
 
100
                list(APPEND ${appsources} ${_outfilename}.icns)
 
101
 
 
102
                # Install the icon into the Resources dir in the bundle
 
103
                set_source_files_properties(${_outfilename}.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
 
104
 
 
105
            else(_icon)
 
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!")
 
108
            endif(_icon)
 
109
 
 
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)
 
113
    endif(Q_WS_MAC)
 
114
endmacro (KDE4_ADD_APP_ICON)