GenerateIconsUtils.cmake 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # UPSTREAM our ECMAddAppIcon.cmake then require that version here
  2. # find_package(ECM 1.7.0 REQUIRED NO_MODULE)
  3. # list(APPEND CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
  4. include(ECMAddAppIcon)
  5. find_program(SVG_CONVERTER
  6. NAMES inkscape inkscape.exe rsvg-convert
  7. REQUIRED
  8. HINTS "C:\\Program Files\\Inkscape\\bin" "/usr/bin" ENV SVG_CONVERTER_DIR)
  9. # REQUIRED keyword is only supported on CMake 3.18 and above
  10. if (NOT SVG_CONVERTER)
  11. message(FATAL_ERROR "Could not find a suitable svg converter. Set SVG_CONVERTER_DIR to the path of either the inkscape or rsvg-convert executable.")
  12. endif()
  13. function(generate_sized_png_from_svg icon_path size)
  14. set(options)
  15. set(oneValueArgs OUTPUT_ICON_NAME OUTPUT_ICON_FULL_NAME_WLE OUTPUT_ICON_PATH)
  16. set(multiValueArgs)
  17. cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
  18. get_filename_component(icon_name_dir ${icon_path} DIRECTORY)
  19. get_filename_component(icon_name_wle ${icon_path} NAME_WLE)
  20. if (ARG_OUTPUT_ICON_NAME)
  21. set(icon_name_wle ${ARG_OUTPUT_ICON_NAME})
  22. endif ()
  23. if (ARG_OUTPUT_ICON_PATH)
  24. set(icon_name_dir ${ARG_OUTPUT_ICON_PATH})
  25. endif ()
  26. set(output_icon_full_name_wle "${size}-${icon_name_wle}")
  27. if (ARG_OUTPUT_ICON_FULL_NAME_WLE)
  28. set(output_icon_full_name_wle ${ARG_OUTPUT_ICON_FULL_NAME_WLE})
  29. endif ()
  30. if (EXISTS "${icon_name_dir}/${output_icon_full_name_wle}.png")
  31. return()
  32. endif()
  33. set(icon_output_name "${output_icon_full_name_wle}.png")
  34. message(STATUS "Generate ${icon_output_name}")
  35. execute_process(COMMAND
  36. "${SVG_CONVERTER}" -w ${size} -h ${size} "${icon_path}" -o "${icon_output_name}"
  37. WORKING_DIRECTORY "${icon_name_dir}"
  38. RESULT_VARIABLE
  39. SVG_CONVERTER_SIDEBAR_ERROR
  40. OUTPUT_QUIET
  41. ERROR_QUIET)
  42. if (SVG_CONVERTER_SIDEBAR_ERROR)
  43. message(FATAL_ERROR
  44. "${SVG_CONVERTER} could not generate icon: ${SVG_CONVERTER_SIDEBAR_ERROR}")
  45. else()
  46. endif()
  47. endfunction()