1# IconCache.cmake 2# 3# This is required here only to have defined target 'uninstall' 4# in the same directory. 5# 6# Macros: 7# add_icon_cache_files(_destdir _fileslistvar ...) 8# adds rules to install icons to icon cache directory with prefix _destdir; 9# the other arguments are one or more list variables with file names. 10 11include(UninstallTarget) 12 13macro(get_one_icon_component _instring _outvalue _outrest) 14 string(FIND "${_instring}" "_" _pos) 15 if(_pos EQUAL -1) 16 message(FATAL_ERROR "get_one_icon_component() failed to get one component from '${_instring}'") 17 endif(_pos EQUAL -1) 18 19 math(EXPR _posinc "${_pos}+1") 20 21 string(SUBSTRING "${_instring}" 0 ${_pos} ${_outvalue}) 22 string(SUBSTRING "${_instring}" ${_posinc} -1 ${_outrest}) 23endmacro(get_one_icon_component) 24 25macro(split_icon_components _infilename _outtheme _outcontext _outsize _outiconfile) 26 set(_rest "${_infilename}") 27 28 get_one_icon_component("${_rest}" ${_outtheme} _rest) 29 get_one_icon_component("${_rest}" ${_outcontext} _rest) 30 get_one_icon_component("${_rest}" ${_outsize} _rest) 31 set(${_outiconfile} "${_rest}") 32endmacro(split_icon_components) 33 34find_program(GTK_UPDATE_ICON_CACHE gtk-update-icon-cache) 35if(NOT GTK_UPDATE_ICON_CACHE) 36 message(WARNING "gtk-update-icon-cache not found. Make sure to call ${GTK_UPDATE_ICON_CACHE} -f -t \"${SHARE_INSTALL_PREFIX}/icons/hicolor\" after install and uninstall") 37endif(NOT GTK_UPDATE_ICON_CACHE) 38 39set(_update_icon_cache_cmd ${GTK_UPDATE_ICON_CACHE} -f -t "${SHARE_INSTALL_PREFIX}/icons/hicolor") 40 41macro(process_icons _destdir _fileslistvar _install_codevar) 42 foreach(srcfile IN LISTS ${_fileslistvar}) 43 split_icon_components(${srcfile} theme context size iconfile) 44 install(FILES ${srcfile} 45 DESTINATION ${_destdir}/icons/${theme}/${size}/${context} 46 RENAME ${iconfile} 47 ) 48 set(${_install_codevar} "${${_install_codevar}} 49 COMMAND ${CMAKE_COMMAND} -E copy_if_different \"${CMAKE_CURRENT_SOURCE_DIR}/${srcfile}\" \"${_destdir}/icons/${theme}/${size}/${context}/${iconfile}\"" 50 ) 51 endforeach(srcfile) 52endmacro(process_icons) 53 54macro(add_icon_cache_files _destdir _fileslistvar) 55 set(_install_code) 56 57 foreach(_filesvar ${_fileslistvar} ${ARGN}) 58 process_icons("${_destdir}" ${_filesvar} _install_code) 59 endforeach(_filesvar) 60 61 if(GTK_UPDATE_ICON_CACHE) 62 install(CODE 63 "if(\"\$ENV{DESTDIR}\" STREQUAL \"\") 64 execute_process(${_install_code} 65 COMMAND ${CMAKE_COMMAND} -E chdir . ${_update_icon_cache_cmd} 66 ) 67 endif(\"\$ENV{DESTDIR}\" STREQUAL \"\")") 68 endif(GTK_UPDATE_ICON_CACHE) 69endmacro(add_icon_cache_files) 70 71if(GTK_UPDATE_ICON_CACHE) 72 add_custom_command(TARGET uninstall POST_BUILD 73 COMMAND ${CMAKE_COMMAND} -E chdir . ${_update_icon_cache_cmd} 74 COMMENT "Updating icon cache in '${SHARE_INSTALL_PREFIX}/icons/hicolor'" 75 ) 76endif(GTK_UPDATE_ICON_CACHE) 77