diff --git a/cmake/modules/ImageHelper.cmake b/cmake/modules/ImageHelper.cmake new file mode 100644 --- /dev/null +++ b/cmake/modules/ImageHelper.cmake @@ -0,0 +1,74 @@ +# Facilities for image transformations +include(DoOrFail) + +macro(convert_svg_to_png SVG PNG DPI) + find_program_or_fail(RSVG_CONVERT_EXECUTABLE rsvg-convert) + + add_custom_command( + OUTPUT + "${PNG}" + COMMAND + "${RSVG_CONVERT_EXECUTABLE}" + -f png + -d "${DPI}" + -p "${DPI}" + "${SVG}" + -o "${PNG}" + MAIN_DEPENDENCY + "${SVG}" + ) +endmacro() + +macro(_convert_png_to_tiff_linux PNG TIFF) + # find_package(ImageMagick) does not search in the default bin + # directories and fails. This is a known bug from FindImageMagick: + # https://gitlab.kitware.com/cmake/cmake/issues/16179 + # When the issue is solved the following can be uncommented: + # find_package(ImageMagick COMPONENTS convert REQUIRED CMAKE_FIND_ROOT_PATH_BOTH) + # + # For now, use find_program as a workaround. + find_program_or_fail(ImageMagick_convert_EXECUTABLE convert) + + add_custom_command( + OUTPUT + "${TIFF}" + COMMAND + "${ImageMagick_convert_EXECUTABLE}" + "${PNG}" + "${TIFF}" + MAIN_DEPENDENCY + "${PNG}" + ) +endmacro() + +macro(convert_png_to_tiff PNG TIFF) + if(NOT CMAKE_CROSSCOMPILING AND ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + message(FATAL_ERROR "The PNG to TIFF conversion is only supported on Linux.") + else() + _convert_png_to_tiff_linux("${PNG}" "${TIFF}") + endif() +endmacro() + +macro(_cat_multi_resolution_tiff_linux OUTPUT) + find_program_or_fail(TIFFCP_EXECUTABLE tiffcp) + + add_custom_command( + OUTPUT + "${OUTPUT}" + COMMAND + "${TIFFCP_EXECUTABLE}" + -c none + ${ARGN} + "${OUTPUT}" + DEPENDS + ${ARGN} + ) +endmacro() + +macro(cat_multi_resolution_tiff OUTPUT) + if(NOT CMAKE_CROSSCOMPILING AND ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + message(FATAL_ERROR "The PNG to TIFF concatenation is only supported on Linux.") + else() + _cat_multi_resolution_tiff_linux("${OUTPUT}" ${ARGN}) + endif() +endmacro() diff --git a/contrib/macdeploy/background.svg.cmake.in b/contrib/macdeploy/background.svg.cmake.in new file mode 100644 --- /dev/null +++ b/contrib/macdeploy/background.svg.cmake.in @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + ${PACKAGE_NAME} + + + + + diff --git a/src/qt/CMakeLists.txt b/src/qt/CMakeLists.txt --- a/src/qt/CMakeLists.txt +++ b/src/qt/CMakeLists.txt @@ -415,10 +415,50 @@ BitcoinABC-Qt ) - add_custom_target(osx-deploydir + # Building the DMG background image requires several steps: + # 1/ The SVG file must be edited to display the package name + # 2/ The SVG file should be transformed into a couple PNG files, on for + # low resolution screens and one for high resolution screens. + # 3/ The PNG files must be transformed into a multi-resolution TIFF file. + # The names are not set arbitrarily, they follow Apple's guidelines for + # resolution independent bitmap images (see `man tiffutil`). + set(BACKGROUND_SVG "background.svg") + configure_file( + "${CMAKE_SOURCE_DIR}/contrib/macdeploy/background.svg.cmake.in" + "${BACKGROUND_SVG}" + ) + + include(ImageHelper) + set(BACKGROUND_PNG_LOWRES "${CMAKE_CURRENT_BINARY_DIR}/background_temp.png") + set(BACKGROUND_PNG_HIRES "${CMAKE_CURRENT_BINARY_DIR}/background_temp@2x.png") + set(BACKGROUND_TIFF_LOWRES "${CMAKE_CURRENT_BINARY_DIR}/background_temp.tiff") + set(BACKGROUND_TIFF_HIRES "${CMAKE_CURRENT_BINARY_DIR}/background_temp@2x.tiff") + set(BACKGROUND_TIFF_NAME "background.tiff") + set(BACKGROUND_TIFF_MULTIRES "${CMAKE_BINARY_DIR}/${BACKGROUND_TIFF_NAME}") + convert_svg_to_png("${BACKGROUND_SVG}" "${BACKGROUND_PNG_LOWRES}" 36) + convert_svg_to_png("${BACKGROUND_SVG}" "${BACKGROUND_PNG_HIRES}" 72) + convert_png_to_tiff("${BACKGROUND_PNG_LOWRES}" "${BACKGROUND_TIFF_LOWRES}") + convert_png_to_tiff("${BACKGROUND_PNG_HIRES}" "${BACKGROUND_TIFF_HIRES}") + cat_multi_resolution_tiff("${BACKGROUND_TIFF_MULTIRES}" "${BACKGROUND_TIFF_LOWRES}" "${BACKGROUND_TIFF_HIRES}") + + set(BACKGROUND_DIST_DIR "${DMG_DIST}/.background") + set(BACKGROUND_DIST_TIFF "${BACKGROUND_DIST_DIR}/${BACKGROUND_TIFF_NAME}") + add_custom_command( + OUTPUT + "${BACKGROUND_DIST_TIFF}" + COMMAND + ${CMAKE_COMMAND} -E make_directory "${BACKGROUND_DIST_DIR}" + COMMAND + ${CMAKE_COMMAND} -E copy "${BACKGROUND_TIFF_MULTIRES}" "${BACKGROUND_DIST_TIFF}" DEPENDS + "${BACKGROUND_TIFF_MULTIRES}" "${DMG_DIST}" ) + + add_custom_target(osx-deploydir + DEPENDS + "${BACKGROUND_DIST_TIFF}" + ) endif() # Test tests