Skip to content

Commit

Permalink
Build a dynamically loadable module for resvg
Browse files Browse the repository at this point in the history
  • Loading branch information
kleisauke committed Jan 17, 2023
1 parent bc9dd66 commit 349a7b7
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 10 deletions.
2 changes: 1 addition & 1 deletion libvips/foreign/foreign.c
Original file line number Diff line number Diff line change
Expand Up @@ -3006,7 +3006,7 @@ vips_foreign_operation_init( void )
vips_foreign_load_pdf_source_get_type();
#endif /*HAVE_PDFIUM*/

#if defined(HAVE_RSVG) || defined(HAVE_RESVG)
#if (defined(HAVE_RSVG) || defined(HAVE_RESVG)) && !defined(RESVG_MODULE)
vips_foreign_load_svg_file_get_type();
vips_foreign_load_svg_buffer_get_type();
#ifdef HAVE_RSVG
Expand Down
9 changes: 8 additions & 1 deletion libvips/foreign/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ foreign_sources = files(
'rawsave.c',
'spngload.c',
'spngsave.c',
'svgload.c',
'tiff2vips.c',
'tiff.c',
'tiffload.c',
Expand Down Expand Up @@ -123,6 +122,14 @@ endif

libvips_sources += foreign_sources

resvg_module_sources = files(
'svgload.c',
)

if not resvg_module
foreign_sources += resvg_module_sources
endif

foreign_lib = static_library('foreign',
foreign_sources,
foreign_headers,
Expand Down
15 changes: 15 additions & 0 deletions libvips/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,18 @@ if openslide_module
install_dir: module_dir
)
endif

if resvg_module
shared_module('vips-resvg',
'module/resvg.c',
resvg_module_sources,
c_args: module_c_args,
link_args: module_link_args,
name_prefix: '',
name_suffix: module_suffix,
dependencies: [gmodule_dep, libvips_dep, resvg_dep],
gnu_symbol_visibility: 'hidden',
install: true,
install_dir: module_dir
)
endif
70 changes: 70 additions & 0 deletions libvips/module/resvg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/* resvg as a dynamically loadable module
*
* 17/1/23 kleisauke
* - initial
*/

/*
This file is part of VIPS.
VIPS is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/

/*
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
*/

/*
#define DEBUG
*/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /*HAVE_CONFIG_H*/
#include <glib/gi18n-lib.h>

#include <stdio.h>
#include <stdlib.h>

#include <vips/vips.h>
#include <vips/debug.h>
#include <vips/internal.h>

#if defined(HAVE_RESVG) && defined(RESVG_MODULE)

/* This is called on module load.
*/
G_MODULE_EXPORT const gchar *
g_module_check_init( GModule *module )
{
#ifdef DEBUG
printf( "vips_resvg: module init\n" );
#endif /*DEBUG*/

extern GType vips_foreign_load_svg_file_get_type( void );
extern GType vips_foreign_load_svg_buffer_get_type( void );

vips_foreign_load_svg_file_get_type();
vips_foreign_load_svg_buffer_get_type();

return( NULL );
}

#endif /*defined(HAVE_RESVG) && defined(RESVG_MODULE)*/
21 changes: 13 additions & 8 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -371,13 +371,18 @@ if librsvg_found
cfg_var.set('HAVE_RSVG', '1')
endif

# libresvg doesn't ship pkg-config files, so we can't use dependency().
libresvg_dep = cc.find_library('resvg', has_headers: ['resvg.h'], required: get_option('resvg'))
libresvg_found = libresvg_dep.found()
if libresvg_found
# It's annoying that I have to spell out the `include_directories` here, but without it Meson can build
# but `compile_commands.json` doesn't have the -I$PREFIX/include, making code analysis tools & VSCode fail.
libvips_deps += declare_dependency(dependencies: [libresvg_dep], include_directories: [include_directories(get_option('prefix') / get_option('includedir'))], link_args: ['-ldl'])
# only if librsvg not found
resvg_dep = disabler()
resvg_module = false
if not librsvg_found
# resvg doesn't ship pkg-config files, so we can't use dependency()
resvg_dep = cc.find_library('resvg', has_headers: ['resvg.h'], required: get_option('resvg'))
resvg_module = modules_enabled and not get_option('resvg-module').disabled()
if resvg_module
cfg_var.set('RESVG_MODULE', '1')
else
libvips_deps += resvg_dep
endif
cfg_var.set('HAVE_RESVG', '1')
endif

Expand Down Expand Up @@ -644,7 +649,7 @@ build_summary = {
'PDF load with PDFium': [pdfium_dep.found()],
'PDF load with poppler-glib': [libpoppler_found, ' (dynamic module: ', libpoppler_module, ')'],
'SVG load with librsvg': [librsvg_found],
'SVG load with libresvg': [libresvg_found],
'SVG load with libresvg': [resvg_dep.found(), ' (dynamic module: ', resvg_module, ')'],
'EXR load with OpenEXR': [openexr_dep.found()],
'OpenSlide load': [openslide_dep.found(), ' (dynamic module: ', openslide_module, ')'],
'Matlab load with libmatio': [matio_dep.found()],
Expand Down
5 changes: 5 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ option('resvg',
value: 'auto',
description: 'Build with resvg')

option('resvg-module',
type: 'feature',
value: 'auto',
description: 'Build resvg as module')

option('spng',
type: 'feature',
value: 'auto',
Expand Down

0 comments on commit 349a7b7

Please sign in to comment.