File: IconCache.cmake

package info (click to toggle)
evolution 3.56.2-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 135,044 kB
  • sloc: ansic: 519,950; javascript: 8,494; xml: 5,207; python: 702; makefile: 563; sh: 294; perl: 169
file content (76 lines) | stat: -rw-r--r-- 2,795 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# IconCache.cmake
#
# This is required here only to have defined target 'uninstall'
# in the same directory.
#
# Macros:
# add_icon_cache_files(_destdir _fileslistvar ...)
#    adds rules to install icons to icon cache directory with prefix _destdir;
#    the other arguments are one or more list variables with file names.

include(UninstallTarget)

macro(get_one_icon_component _instring _outvalue _outrest)
	string(FIND "${_instring}" "_" _pos)
	if(_pos EQUAL -1)
		message(FATAL_ERROR "get_one_icon_component() failed to get one component from '${_instring}'")
	endif(_pos EQUAL -1)

	math(EXPR _posinc "${_pos}+1")

	string(SUBSTRING "${_instring}" 0 ${_pos} ${_outvalue})
	string(SUBSTRING "${_instring}" ${_posinc} -1 ${_outrest})
endmacro(get_one_icon_component)

macro(split_icon_components _infilename _outtheme _outcontext _outsize _outiconfile)
	set(_rest "${_infilename}")

	get_one_icon_component("${_rest}" ${_outtheme} _rest)
	get_one_icon_component("${_rest}" ${_outcontext} _rest)
	get_one_icon_component("${_rest}" ${_outsize} _rest)
	set(${_outiconfile} "${_rest}")
endmacro(split_icon_components)

find_program(GTK_UPDATE_ICON_CACHE gtk-update-icon-cache)
if(NOT GTK_UPDATE_ICON_CACHE)
	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")
endif(NOT GTK_UPDATE_ICON_CACHE)

set(_update_icon_cache_cmd ${GTK_UPDATE_ICON_CACHE} -f -t "${SHARE_INSTALL_PREFIX}/icons/hicolor")

macro(process_icons _destdir _fileslistvar _install_codevar)
	foreach(srcfile IN LISTS ${_fileslistvar})
		split_icon_components(${srcfile} theme context size iconfile)
		install(FILES ${srcfile}
			DESTINATION ${_destdir}/icons/${theme}/${size}/${context}
			RENAME ${iconfile}
		)
		set(${_install_codevar} "${${_install_codevar}}
			COMMAND ${CMAKE_COMMAND} -E copy_if_different \"${CMAKE_CURRENT_SOURCE_DIR}/${srcfile}\" \"${_destdir}/icons/${theme}/${size}/${context}/${iconfile}\""
		)
	endforeach(srcfile)
endmacro(process_icons)

macro(add_icon_cache_files _destdir _fileslistvar)
	set(_install_code)

	foreach(_filesvar ${_fileslistvar} ${ARGN})
		process_icons("${_destdir}" ${_filesvar} _install_code)
	endforeach(_filesvar)

	if(GTK_UPDATE_ICON_CACHE)
		install(CODE
			"if(\"\$ENV{DESTDIR}\" STREQUAL \"\")
				execute_process(${_install_code}
					COMMAND ${CMAKE_COMMAND} -E chdir . ${_update_icon_cache_cmd}
				)
			endif(\"\$ENV{DESTDIR}\" STREQUAL \"\")")
	endif(GTK_UPDATE_ICON_CACHE)
endmacro(add_icon_cache_files)

if(GTK_UPDATE_ICON_CACHE)
	add_custom_command(TARGET uninstall POST_BUILD
		COMMAND ${CMAKE_COMMAND} -E chdir . ${_update_icon_cache_cmd}
		COMMENT "Updating icon cache in '${SHARE_INSTALL_PREFIX}/icons/hicolor'"
	)
endif(GTK_UPDATE_ICON_CACHE)