aboutsummaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2024-12-17 06:20:12 +0100
committerPřemysl Eric Janouch <p@janouch.name>2024-12-17 06:20:12 +0100
commit1930f138d4836f8ed9613a17bfe09dc53441618a (patch)
treee53551db91d0b876f0b5bc30cc66e03016501231 /cmake
parent32cbb152660566042ac25b00de4b19b1c90c0f5c (diff)
downloadliberty-master.tar.gz
liberty-master.tar.xz
liberty-master.zip
IconUtils: add Apple Icon Image format supportHEADorigin/mastermaster
Diffstat (limited to 'cmake')
-rw-r--r--cmake/IconUtils.cmake44
1 files changed, 44 insertions, 0 deletions
diff --git a/cmake/IconUtils.cmake b/cmake/IconUtils.cmake
index abd1f6a..c21cc4e 100644
--- a/cmake/IconUtils.cmake
+++ b/cmake/IconUtils.cmake
@@ -38,3 +38,47 @@ function (icon_for_win32 ico pngs pngs_raw)
DEPENDS ${pngs} ${pngs_raw}
COMMENT "Generating Windows program icon" VERBATIM)
endfunction ()
+
+function (icon_to_iconset_size name svg size iconset outputs)
+ math (EXPR _size2x "${size} * 2")
+ set (_dimensions "${size}x${size}")
+ set (_png1x "${iconset}/icon_${_dimensions}.png")
+ set (_png2x "${iconset}/icon_${_dimensions}@2x.png")
+ set (${outputs} "${_png1x};${_png2x}" PARENT_SCOPE)
+
+ set (_find_program_REQUIRE)
+ if (NOT ${CMAKE_VERSION} VERSION_LESS 3.18.0)
+ set (_find_program_REQUIRE REQUIRED)
+ endif ()
+
+ find_program (rsvg_convert_EXECUTABLE rsvg-convert ${_find_program_REQUIRE})
+ add_custom_command (OUTPUT "${_png1x}" "${_png2x}"
+ COMMAND ${CMAKE_COMMAND} -E make_directory "${iconset}"
+ COMMAND ${rsvg_convert_EXECUTABLE} "--output=${_png1x}"
+ "--width=${size}" "--height=${size}" -- "${svg}"
+ COMMAND ${rsvg_convert_EXECUTABLE} "--output=${_png2x}"
+ "--width=${_size2x}" "--height=${_size2x}" -- "${svg}"
+ DEPENDS "${svg}"
+ COMMENT "Generating ${name} ${_dimensions} icons" VERBATIM)
+endfunction ()
+function (icon_to_icns svg output_basename output)
+ get_filename_component (_name "${output_basename}" NAME_WE)
+ set (_iconset "${PROJECT_BINARY_DIR}/${_name}.iconset")
+ set (_icon "${PROJECT_BINARY_DIR}/${output_basename}")
+ set (${output} "${_icon}" PARENT_SCOPE)
+
+ set (_icon_png_list)
+ foreach (_icon_size 16 32 128 256 512)
+ icon_to_iconset_size ("${_name}" "${svg}"
+ "${_icon_size}" "${_iconset}" _icon_pngs)
+ list (APPEND _icon_png_list ${_icon_pngs})
+ endforeach ()
+
+ # XXX: This will not normally work from within Nix.
+ add_custom_command (OUTPUT "${_icon}"
+ COMMAND iconutil -c icns -o "${_icon}" "${_iconset}"
+ DEPENDS ${_icon_png_list}
+ COMMENT "Generating ${_name} icon" VERBATIM)
+ set_source_files_properties ("${_icon}" PROPERTIES
+ MACOSX_PACKAGE_LOCATION Resources)
+endfunction ()