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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
# SPDX-FileCopyrightInfo: Copyright (C) DUNE Project contributors, see file LICENSE.md in module root
# SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
# Module that provides conversion routines using inkscape
#
# .. cmake_function:: inkscape_generate_png_from_svg
#
# .. cmake_param:: OUTPUT_DIR
# :single:
#
# The output directory for the generated png files.
# Defaults to the current build directory.
#
# .. cmake_param:: pngfiles
# :single:
# :positional:
# :required:
#
# The files that should be converted.
#
# .. cmake_param:: DPI
# :single:
#
# dpi value for the generated image (default: 90)
#
#
#
# .. cmake_function:: dune_create_inkscape_image_converter_target
#
# Creates a target that when built, converts svg images to png images using inkscape
#
# .. cmake_param:: TARGET
# :single:
#
# Name of the target to be created.
#
# .. cmake_param:: OUTPUT_DIR
# :single:
# :required:
#
# The output directory for the generated png files.
# Defaults to the current build directory.
#
# .. cmake_param:: IMAGES
# :multi:
# :required:
#
# The files that should be converted.
#
# .. cmake_param:: DPI
# :single:
#
# dpi value for the generated image (default: 90)
#
# .. cmake_param:: ALL
# :option:
#
# If given, will add the created target to the all target
#
include_guard(GLOBAL)
function(inkscape_generate_png_from_svg)
message(DEPRECATION "inkscape_generate_png_from_svg is deprecated (will be removed after release 2.9). "
"Use dune_create_inkscape_image_converter_target.")
if(NOT INKSCAPE)
return()
endif()
cmake_parse_arguments(INKSCAPE "" "OUTPUT_DIR;DPI" "" ${ARGN})
if(NOT INKSCAPE_OUTPUT_DIR)
set(INKSCAPE_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
endif()
if(NOT INKSCAPE_DPI)
set(INKSCAPE_DPI 90)
endif()
message(STATUS "Generate PNG from SVG in ${INKSCAPE_OUTPUT_DIR}")
set(_converted 0)
foreach(pic ${INKSCAPE_UNPARSED_ARGUMENTS})
string(REGEX REPLACE "\\.[a-zA-Z]+" ".svg" input ${pic})
if(NOT EXISTS ${INKSCAPE_OUTPUT_DIR}/${pic})
set(_converted 1)
if(INKSCAPE_NEW_VERSION)
execute_process(
COMMAND ${INKSCAPE} --export-dpi=${INKSCAPE_DPI} --export-type=png --export-filename=${pic} ${CMAKE_CURRENT_SOURCE_DIR}/${input}
WORKING_DIRECTORY ${INKSCAPE_OUTPUT_DIR}
OUTPUT_QUIET)
else()
execute_process(
COMMAND ${INKSCAPE} -z --export-dpi=${INKSCAPE_DPI} -e ${pic} ${CMAKE_CURRENT_SOURCE_DIR}/${input}
WORKING_DIRECTORY ${INKSCAPE_OUTPUT_DIR}
OUTPUT_QUIET)
endif()
endif()
endforeach()
if(_converted)
message(STATUS "Generate PNG from SVG in ${INKSCAPE_OUTPUT_DIR} - done")
else()
message(STATUS "Generate PNG from SVG in ${INKSCAPE_OUTPUT_DIR} - skipped")
endif()
endfunction()
function(dune_create_inkscape_image_converter_target)
set(OPTION ALL)
set(SINGLE TARGET OUTPUT_DIR DPI)
set(MULTI IMAGES)
cmake_parse_arguments(INKSCAPE_CONV "${OPTION}" "${SINGLE}" "${MULTI}" ${ARGN})
if(NOT INKSCAPE_CONV_TARGET)
message(FATAL_ERROR "Specifying a target name by setting TARGET is required.")
endif()
if(TARGET ${INKSCAPE_CONV_TARGET})
get_property(TARGET_SOURCE_DIR TARGET ${INKSCAPE_CONV_TARGET} PROPERTY SOURCE_DIR)
message(FATAL_ERROR "dune_create_inkscape_image_converter_target cannot create target "
"\"${INKSCAPE_CONV_TARGET}\" because another target with the same "
"name already exists. The existing target is a target created in "
"source directory \"${TARGET_SOURCE_DIR}\".")
endif()
# we always create the target even if it stays empty
# (might happen because inkscape is not found or the image list is empty)
if(INKSCAPE_CONV_ALL)
add_custom_target(${INKSCAPE_CONV_TARGET} ALL)
else()
add_custom_target(${INKSCAPE_CONV_TARGET})
endif()
if(NOT INKSCAPE)
message(STATUS "Inkscape not found so no images will be converted")
return()
endif()
if(NOT INKSCAPE_CONV_OUTPUT_DIR)
set(INKSCAPE_CONV_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
endif()
if(NOT INKSCAPE_CONV_DPI)
set(INKSCAPE_CONV_DPI 90)
endif()
foreach(_output_png ${INKSCAPE_CONV_IMAGES})
string(REGEX REPLACE "\\.[a-zA-Z]+" ".svg" _input_svg ${_output_png})
if(INKSCAPE_NEW_VERSION)
add_custom_command(TARGET ${INKSCAPE_CONV_TARGET} PRE_BUILD
COMMAND ${INKSCAPE} --export-dpi=${INKSCAPE_CONV_DPI} --export-type=png --export-filename=${_output_png} ${CMAKE_CURRENT_SOURCE_DIR}/${_input_svg}
WORKING_DIRECTORY ${INKSCAPE_CONV_OUTPUT_DIR}
COMMENT "Generating ${_output_png} from ${_input_svg} with inkscape"
)
else()
add_custom_command(TARGET ${INKSCAPE_CONV_TARGET} PRE_BUILD
COMMAND ${INKSCAPE} -z --export-dpi=${INKSCAPE_CONV_DPI} -e ${_output_png} ${CMAKE_CURRENT_SOURCE_DIR}/${_input_svg}
WORKING_DIRECTORY ${INKSCAPE_CONV_OUTPUT_DIR}
COMMENT "Generating ${_output_png} from ${_input_svg} with inkscape"
)
endif()
endforeach()
endfunction()
|