Skip to content

Commit

Permalink
meson: various minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
concatime committed Dec 19, 2020
1 parent 2b8b1d2 commit f93e28d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 42 deletions.
2 changes: 1 addition & 1 deletion examples/meson.build
Original file line number Diff line number Diff line change
@@ -1 +1 @@
example_exe = executable('example', 'example.c', dependencies : spng_dep)
example_exe = executable('example', 'example.c', dependencies : spng_dep)
55 changes: 29 additions & 26 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if get_option('default_library') == 'static'
static_subproject = meson.is_subproject()
endif

if get_option('enable_opt') == false
if not get_option('enable_opt')
add_project_arguments('-DSPNG_DISABLE_OPT', language : 'c')
endif

Expand All @@ -30,64 +30,67 @@ if cc.compiles(files('tests/target_clones.c'), args : '-Werror', name : 'have ta
add_project_arguments('-DSPNG_ENABLE_TARGET_CLONES', language : 'c')
endif

if get_option('use_miniz') == true
spng_deps = [ cc.find_library('m', required : false) ]

if get_option('use_miniz')
add_project_arguments('-DSPNG_USE_MINIZ', language : 'c')
zlib_dep = dependency('miniz', fallback : [ 'miniz', 'miniz_dep'])
spng_deps += dependency('miniz',
default_options : [ 'default_library=static' ],
fallback : [ 'miniz', 'miniz_dep' ],
)
else
zlib_dep = dependency('zlib',
default_options : [ 'default_library=static' ],
fallback : [ 'zlib', 'zlib_dep' ],
required : false,
fallback : ['zlib', 'zlib_dep'],
static : get_option('static_zlib'))

if not zlib_dep.found()
zlib_dep = cc.find_library('z')
endif
static : get_option('static_zlib'),
)
spng_deps += zlib_dep.found() ? zlib_dep : cc.find_library('z')
endif

m_dep = cc.find_library('m', required : false)

spng_deps = [ zlib_dep, m_dep ]

spng_inc = include_directories('spng')

spng_src = files('spng/spng.c')

spng_lib = library('spng',
spng_src,
spng_lib = library('spng', spng_src,
c_args : spng_args,
dependencies : spng_deps,
install : not static_subproject,
version : meson.project_version()
)

spng_dep = declare_dependency(
link_with : spng_lib,
compile_args : spng_args,
include_directories : spng_inc,
version : meson.project_version()
link_with : spng_lib,
)

if meson.version().version_compare('>= 0.54.0')
meson.override_dependency('spng', spng_dep)
endif

if meson.is_subproject()
subdir_done()
endif

install_headers('spng/spng.h')

subdir('examples')
subdir('tests')

if get_option('benchmarks') == true
if get_option('dev_build')
subdir('tests')
endif

if get_option('benchmarks')
subproject('spngt')
endif

if static_subproject
subdir_done()
endif

install_headers('spng/spng.h')

pkg = import('pkgconfig')

pkg.generate(spng_lib,
pc= import('pkgconfig')
pc.generate(spng_lib,
description : 'PNG decoding and encoding library',
extra_cflags : spng_args,
libraries_private : [ '-lm', '-lz' ],
description : 'PNG decoding and encoding library'
)
3 changes: 1 addition & 2 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ option('use_miniz', type : 'boolean', value : false, description : 'Compile with
option('static_zlib', type : 'boolean', value : false, description : 'Link zlib statically')
option('benchmarks', type : 'boolean', value : false, description : 'Enable benchmarks, requires Git LFS')


# Not for end-users
option('multithreading', type : 'feature', value : 'disabled', description : 'Experimental multithreading features')
option('oss_fuzz', type : 'boolean', value : false, description : 'Enable regression tests with OSS-Fuzz corpora')
option('oss_fuzz', type : 'boolean', value : false, description : 'Enable regression tests with OSS-Fuzz corpora')
23 changes: 11 additions & 12 deletions tests/meson.build
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
if get_option('dev_build') == false
subdir_done()
endif

add_languages('cpp', native : false)
cpp = meson.get_compiler('cpp')

Expand All @@ -11,14 +7,17 @@ if cc.has_function('fmemopen', prefix : '#include <stdio.h>', args : '-D_GNU_SOU
fuzzer_args = [ '-D_GNU_SOURCE', '-DSPNGT_HAVE_FMEMOPEN' ]
endif

read_fuzzer = executable('fuzz_repro',
'fuzz_main.c',
'spng_read_fuzzer.c',
read_fuzzer = executable('fuzz_repro', 'fuzz_main.c', 'spng_read_fuzzer.c',
c_args : fuzzer_args,
link_with : spng_lib
include_directories : spng_inc,
link_with : spng_lib,
)

png_dep = dependency('libpng', version : '>=1.6.0', fallback : ['libpng', 'png_dep'])
png_dep = dependency('libpng',
version : '>=1.6.0',
fallback : [ 'libpng', 'png_dep' ],
default_options : [ 'default_library=static' ],
)

test_deps = [ spng_dep, png_dep ]

Expand All @@ -29,15 +28,15 @@ test('info', test_exe, args : 'info')
cpp_exe = executable('cpp_exe', 'test.cpp', dependencies : spng_dep)
test('cpp_test', cpp_exe)

subdir('images')
subdir('crashers')
subdir('images')

if get_option('oss_fuzz') == false
if not get_option('oss_fuzz')
subdir_done()
endif

corpora = subproject('fuzzing_corpora').get_variable('corpora')

foreach case : corpora
test('testcase', read_fuzzer, args : case)
endforeach
endforeach
2 changes: 1 addition & 1 deletion tests/spng_read_fuzzer.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#define SPNG_UNTESTED
#include "../spng/spng.h"
#include "spng.h"

#include <string.h>

Expand Down

0 comments on commit f93e28d

Please sign in to comment.