Skip to content

Commit

Permalink
[librsvg][gdk-pixbuf] Add librsvg support to gdk-pixbuf by adding lib…
Browse files Browse the repository at this point in the history
…rsvg as a dependency to gdk-pixbuf.

This changes the behavior of librsvg to be able to be built without gdk-pixbuf support (to avoid circular dependency) when built statically, and gdk-pixbuf to be built with librsvg support.
librsvg is optional when building gdk-pixbuf dynamically, and enabled by default when building statically.

This fixes #38012.

Signed-off-by: Vitalii Koshura <[email protected]>
  • Loading branch information
AenBleidd committed May 1, 2024
1 parent c561d1e commit 03e6723
Show file tree
Hide file tree
Showing 10 changed files with 355 additions and 35 deletions.
83 changes: 83 additions & 0 deletions ports/gdk-pixbuf/add_librsvg_dependency.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
diff --git a/gdk-pixbuf/gdk-pixbuf-io.c b/gdk-pixbuf/gdk-pixbuf-io.c
index e207d8143..4366ba191 100644
--- a/gdk-pixbuf/gdk-pixbuf-io.c
+++ b/gdk-pixbuf/gdk-pixbuf-io.c
@@ -659,6 +659,9 @@ gdk_pixbuf_io_init_builtin (void)
/* Except the gdip-png loader which normally isn't built at all even */
load_one_builtin_module (png);
#endif
+#ifdef INCLUDE_svg
+ load_one_builtin_module (svg);
+#endif

#undef load_one_builtin_module
}
@@ -695,6 +698,7 @@ module (xbm);
module (tga);
module (icns);
module (qtif);
+module (svg);
module (gdip_ico);
module (gdip_wmf);
module (gdip_emf);
@@ -777,6 +781,9 @@ gdk_pixbuf_load_module_unlocked (GdkPixbufModule *image_module,
#ifdef INCLUDE_qtif
try_module (qtif,qtif);
#endif
+#ifdef INCLUDE_svg
+ try_module (svg,svg);
+#endif

#undef try_module

diff --git a/gdk-pixbuf/gdk-pixbuf.c b/gdk-pixbuf/gdk-pixbuf.c
index 8bdd65035..241ddef5a 100644
--- a/gdk-pixbuf/gdk-pixbuf.c
+++ b/gdk-pixbuf/gdk-pixbuf.c
@@ -788,7 +788,6 @@ gboolean
gdk_pixbuf_get_has_alpha (const GdkPixbuf *pixbuf)
{
g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), FALSE);
-
return pixbuf->has_alpha ? TRUE : FALSE;
}

diff --git a/meson.build b/meson.build
index 8a16c8f97..e6734e41b 100644
--- a/meson.build
+++ b/meson.build
@@ -335,6 +335,19 @@ if not tiff_opt.disabled() and not native_windows_loaders
endif
endif

+svg_opt = get_option('svg')
+if not svg_opt.disabled()
+ # We currently don't have a fallback subproject, but this handles error
+ # reporting if svg_opt is enabled.
+ svg_dep = dependency('librsvg-2.0', required: svg_opt)
+
+ if svg_dep.found()
+ enabled_loaders += 'svg'
+ gdk_pixbuf_deps += svg_dep
+ add_project_arguments([ '-DINCLUDE_svg' ], language: 'c')
+ endif
+endif
+
# Determine whether we enable application bundle relocation support, and we use
# this always on Windows
if host_system == 'windows'
diff --git a/meson_options.txt b/meson_options.txt
index d198d99d5..00ee61af8 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -10,6 +10,10 @@ option('jpeg',
description: 'Enable JPEG loader (requires libjpeg), disabled on Windows if "native_windows_loaders" is used',
type: 'feature',
value: 'enabled')
+option('svg',
+ description: 'Enable SVG loader (requires librsvg)',
+ type: 'feature',
+ value: 'auto')
option('builtin_loaders',
description: 'Comma-separated list of loaders to build into gdk-pixbuf',
type: 'array',
7 changes: 7 additions & 0 deletions ports/gdk-pixbuf/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ vcpkg_from_gitlab(
loaders-cache.patch
use-libtiff-4-pkgconfig.patch
fix-static-deps.patch
add_librsvg_dependency.patch
)

if("introspection" IN_LIST FEATURES)
Expand Down Expand Up @@ -37,6 +38,12 @@ else()
list(APPEND OPTIONS -Djpeg=disabled)
endif()

if("svg" IN_LIST FEATURES)
list(APPEND OPTIONS -Dsvg=enabled)
else()
list(APPEND OPTIONS -Dsvg=disabled)
endif()

if(CMAKE_HOST_WIN32 AND VCPKG_TARGET_ARCHITECTURE STREQUAL "x86")
set(GIR_TOOL_DIR ${CURRENT_INSTALLED_DIR})
else()
Expand Down
17 changes: 16 additions & 1 deletion ports/gdk-pixbuf/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gdk-pixbuf",
"version": "2.42.10",
"port-version": 5,
"port-version": 6,
"description": "Image loading library.",
"homepage": "https://gitlab.gnome.org/GNOME/gdk-pixbuf",
"license": "LGPL-2.1-or-later",
Expand All @@ -28,6 +28,10 @@
"default-features": [
"jpeg",
"png",
{
"name": "svg",
"platform": "static"
},
"tiff"
],
"features": {
Expand All @@ -50,6 +54,17 @@
"libpng"
]
},
"svg": {
"description": "Enable SVG loader (requires librsvg)",
"dependencies": [
{
"name": "librsvg",
"features": [
"pixbufloader"
]
}
]
},
"tiff": {
"description": "Enable TIFF loader (requires libtiff)",
"supports": "!windows",
Expand Down
90 changes: 61 additions & 29 deletions ports/librsvg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ Set(libdir "\${prefix}/lib")
Set(includedir "\${prefix}/include")

# Public required modules (cf. headers and librsvg.pc)
set(librsvg_pc_requires glib-2.0 gio-2.0 gdk-pixbuf-2.0 cairo)
set(librsvg_pc_requires glib-2.0 gio-2.0 cairo)
if (BUILD_SHARED_LIBS)
list(APPEND librsvg_pc_requires gdk-pixbuf-2.0)
endif()
# Other required modules from configure.ac
set(librsvg_pc_requires_private
libxml-2.0
Expand Down Expand Up @@ -132,42 +135,71 @@ install(
DESTINATION include/librsvg-${RSVG_API_VERSION}/librsvg
)

if (BUILD_SHARED_LIBS)
set(gdk_pixbuf_pc_requires_private gdk-pixbuf-2.0)
pkg_check_modules(GDK_PIXBUF ${gdk_pixbuf_pc_requires_private} IMPORTED_TARGET REQUIRED)
pkg_get_variable(GDK_PIXBUF_MODULEDIR ${gdk_pixbuf_pc_requires_private} gdk_pixbuf_moduledir)
endif()

set(gdk_pixbuf_pc_requires_private gdk-pixbuf-2.0)
pkg_check_modules(GDK_PIXBUF ${gdk_pixbuf_pc_requires_private} IMPORTED_TARGET REQUIRED)
pkg_get_variable(GDK_PIXBUF_MODULEDIR ${gdk_pixbuf_pc_requires_private} gdk_pixbuf_moduledir)
if (ENABLE_GDK_PIXBUF_LOADER)
set(PIXBUFLOADERSVG_SOURCES
gdk-pixbuf-loader/io-svg.c
)

set(PIXBUFLOADERSVG_SOURCES
gdk-pixbuf-loader/io-svg.c
)
if (BUILD_SHARED_LIBS)
add_library(pixbufloader-svg MODULE ${PIXBUFLOADERSVG_SOURCES})
else()
add_library(pixbufloader-svg ${PIXBUFLOADERSVG_SOURCES})
endif()

add_library(pixbufloader-svg MODULE ${PIXBUFLOADERSVG_SOURCES})
target_include_directories(pixbufloader-svg
PRIVATE
"${CMAKE_CURRENT_BINARY_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}"
)
target_compile_definitions(pixbufloader-svg PRIVATE
-DRSVG_COMPILATION
-D_CRT_SECURE_NO_WARNINGS
-DSRCDIR=""
-DGDK_PIXBUF_ENABLE_BACKEND
-DG_LOG_DOMAIN="libpixbufloader-svg"
)
target_link_libraries(pixbufloader-svg
PRIVATE
${LIBRSVG_TARGET}
PkgConfig::GDK_PIXBUF
)
install(TARGETS pixbufloader-svg
RUNTIME DESTINATION "${GDK_PIXBUF_MODULEDIR}"
LIBRARY DESTINATION "${GDK_PIXBUF_MODULEDIR}"
)
target_include_directories(pixbufloader-svg
PRIVATE
"${CMAKE_CURRENT_BINARY_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}"
)
target_compile_definitions(pixbufloader-svg PRIVATE
-DRSVG_COMPILATION
-D_CRT_SECURE_NO_WARNINGS
-DSRCDIR=""
-DGDK_PIXBUF_ENABLE_BACKEND
-DG_LOG_DOMAIN="libpixbufloader-svg"
)
if (BUILD_SHARED_LIBS)
target_link_libraries(pixbufloader-svg
PRIVATE
${LIBRSVG_TARGET}
PkgConfig::GDK_PIXBUF
)
else()
target_link_libraries(pixbufloader-svg
PRIVATE
${LIBRSVG_TARGET}
)
endif()

if (BUILD_SHARED_LIBS)
install(TARGETS pixbufloader-svg
RUNTIME DESTINATION "${GDK_PIXBUF_MODULEDIR}"
LIBRARY DESTINATION "${GDK_PIXBUF_MODULEDIR}"
)
else()
install(TARGETS pixbufloader-svg
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
endif()
endif()

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/librsvg.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/librsvg.pc" @ONLY)
file(READ "${CMAKE_CURRENT_BINARY_DIR}/librsvg.pc" librsvg_pc)
list(JOIN librsvg_pc_requires_private " " requires_private)
string(REPLACE "Requires.private:" "Requires.private: ${requires_private}" librsvg_pc "${librsvg_pc}")
if (ENABLE_GDK_PIXBUF_LOADER AND NOT BUILD_SHARED_LIBS)
string(REPLACE "-lm" "-lpixbufloader-svg -lm" librsvg_pc "${librsvg_pc}")
endif()
if (NOT BUILD_SHARED_LIBS)
string(REPLACE "gdk-pixbuf-2.0" "" librsvg_pc "${librsvg_pc}")
endif()
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/librsvg.pc" "${librsvg_pc}")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/librsvg.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" RENAME "librsvg-${RSVG_API_VERSION}.pc")

0 comments on commit 03e6723

Please sign in to comment.