diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/KDE4Macros.cmake | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/modules/KDE4Macros.cmake b/modules/KDE4Macros.cmake index e0e72318..3188a856 100644 --- a/modules/KDE4Macros.cmake +++ b/modules/KDE4Macros.cmake @@ -952,6 +952,7 @@ endmacro (KDE4_CREATE_HTML_HANDBOOK) # example: KDE4_ADD_WIN32_APP_ICON(myapp_SRCS "pics/cr16-myapp.png;pics/cr32-myapp.png") macro (KDE4_ADD_WIN32_APP_ICON appsources) + message(STATUS "KDE4_ADD_WIN32_APP_ICON() is deprecated, use KDE4_ADD_APP_ICON() instead") if (WIN32) find_program(PNG2ICO_EXECUTABLE NAMES png2ico) find_program(WINDRES_EXECUTABLE NAMES windres) @@ -979,3 +980,109 @@ macro (KDE4_ADD_WIN32_APP_ICON appsources) endif(WIN32) endmacro (KDE4_ADD_WIN32_APP_ICON) +# adds application icon to target source list + +# this macro adds an application icon to the specified target +# mac osx notes : the application icon is added to a Mac OS X bundle so that Finder and friends show the right thing. +# win32 notes: the application icon(s) are compiled into the application +# parameters: +# 'target' - cmake target to generate +# 'appsources' - specifies the list of source files +# 'pattern' - regular expression for searching application icons +# example: KDE4_ADD_APP_ICON(myapp myapp_sources "pics/cr*-myapp.png") + +macro (KDE4_ADD_APP_ICON target appsources pattern ) + if (WIN32) + find_program(PNG2ICO_EXECUTABLE NAMES png2ico) + find_program(WINDRES_EXECUTABLE NAMES windres) + if(MSVC) + set(WINDRES_EXECUTABLE TRUE) + endif(MSVC) + if (PNG2ICO_EXECUTABLE AND WINDRES_EXECUTABLE) + file(GLOB files "${pattern}") + FOREACH (it ${files}) + GET_FILENAME_COMPONENT(_name ${it} NAME_WE) + if (it MATCHES ".*16-.*" ) + list (APPEND _icons ${it}) + endif (it MATCHES ".*16-.*") + if (it MATCHES ".*32-.*" ) + list (APPEND _icons ${it}) + endif (it MATCHES ".*32-.*") + if (it MATCHES ".*64-.*" ) + list (APPEND _icons ${it}) + endif (it MATCHES ".*64-.*") + ENDFOREACH (it) + if (_icons) + set (_outfilename ${CMAKE_CURRENT_BINARY_DIR}/${target}) + # requires kdewin32 >= 0.3.4 + ADD_CUSTOM_COMMAND(OUTPUT ${_outfilename}.ico ${_outfilename}.rc + COMMAND ${PNG2ICO_EXECUTABLE} ARGS --rcfile ${_outfilename}.rc ${_outfilename}.ico ${_icons} + DEPENDS ${PNG2ICO_EXECUTABLE} ${ARGN} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) + if (MINGW) + ADD_CUSTOM_COMMAND(OUTPUT ${_outfilename}_res.o + COMMAND ${WINDRES_EXECUTABLE} ARGS -i ${_outfilename}.rc -o ${_outfilename}_res.o --include-dir=${CMAKE_CURRENT_SOURCE_DIR} + DEPENDS ${WINDRES_EXECUTABLE} ${_outfilename}.rc + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) + 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 for target ${target} - application will not have an application icon!") + endif(_icons) + else(PNG2ICO_EXECUTABLE AND WINDRES_EXECUTABLE) + message(STATUS "Unable to find the png2ico or windres utilities - application will not have an application icon!") + endif(PNG2ICO_EXECUTABLE AND WINDRES_EXECUTABLE) + endif(WIN32) + if (Q_WS_MAC) + # first convert image to a tiff using the Mac OS X "sips" utility, + # then use tiff2icns to convert to an icon + find_program(SIPS_EXECUTABLE NAMES sips) + find_program(TIFF2ICNS_EXECUTABLE NAMES tiff2icns) + if (SIPS_EXECUTABLE AND TIFF2ICNS_EXECUTABLE) + file(GLOB files "${pattern}") + FOREACH (it ${files}) + if (it MATCHES ".*128-.*" ) + set (_icon ${it}) + endif (it MATCHES ".*128-.*") + ENDFOREACH (it) + set (_outfilename ${CMAKE_CURRENT_BINARY_DIR}/${target}) + + if (_icon) + + # first, get the basename of our app icon + add_custom_command(OUTPUT ${_outfilename}.icns + COMMAND sips -s format tiff ${_icon} --out _tmp_appicon.tiff + COMMAND tiff2icns _tmp_appicon.tiff ${_outfilename}.icns + DEPENDS ${_icon} + ) + + macro_additional_clean_files(_tmp_appicon.tiff ${_outfilename}.icns) + + # This will register the icon into the bundle + set(MACOSX_BUNDLE_ICON_FILE ${target}.icns) + + # Append the icns file to the sources list so it will be a dependency to the + # main target + list(APPEND ${appsources} ${_outfilename}.icns) + + # this doesn't seem to work for me - Use manual "install" instead + # SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/${target}.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources) + + install(FILES ${_outfilename}.icns DESTINATION ${BIN_INSTALL_DIR}/${target}.app/Contents/Resources/) + + else(_icon) + # TODO - try to scale a non-128 icon...? Try to convert an SVG on the fly? + message(STATUS "Unable to find an 128x128 icon for target ${target} - application will not have an application icon!") + endif(_icon) + + else(SIPS_EXECUTABLE AND TIFF2ICNS_EXECUTABLE) + message(STATUS "Unable to find the sips and tiff2icns utilities - application will not have an application icon!") + endif(SIPS_EXECUTABLE AND TIFF2ICNS_EXECUTABLE) + endif(Q_WS_MAC) +endmacro (KDE4_ADD_APP_ICON) + + |