Skip to content

Commit 7991bda

Browse files
committed
meson: various minor improvements
1 parent c63937c commit 7991bda

File tree

5 files changed

+44
-42
lines changed

5 files changed

+44
-42
lines changed

examples/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
example_exe = executable('example', 'example.c', dependencies : spng_dep)
1+
example_exe = executable('example', 'example.c', dependencies : spng_dep)

meson.build

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if get_option('default_library') == 'static'
1919
static_subproject = meson.is_subproject()
2020
endif
2121

22-
if get_option('enable_opt') == false
22+
if not get_option('enable_opt')
2323
add_project_arguments('-DSPNG_DISABLE_OPT', language : 'c')
2424
endif
2525

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

33-
if get_option('use_miniz') == true
33+
spng_deps = [ cc.find_library('m', required : false) ]
34+
35+
if get_option('use_miniz')
3436
add_project_arguments('-DSPNG_USE_MINIZ', language : 'c')
35-
zlib_dep = dependency('miniz', fallback : [ 'miniz', 'miniz_dep'])
37+
spng_deps += dependency('miniz',
38+
default_options : [ 'default_library=static' ],
39+
fallback : [ 'miniz', 'miniz_dep' ],
40+
)
3641
else
3742
zlib_dep = dependency('zlib',
43+
default_options : [ 'default_library=static' ],
44+
fallback : [ 'zlib', 'zlib_dep' ],
3845
required : false,
39-
fallback : ['zlib', 'zlib_dep'],
40-
static : get_option('static_zlib'))
41-
42-
if not zlib_dep.found()
43-
zlib_dep = cc.find_library('z')
44-
endif
46+
static : get_option('static_zlib'),
47+
)
48+
spng_deps += zlib_dep.found() ? zlib_dep : cc.find_library('z')
4549
endif
4650

47-
m_dep = cc.find_library('m', required : false)
48-
49-
spng_deps = [ zlib_dep, m_dep ]
50-
5151
spng_inc = include_directories('spng')
5252

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

55-
spng_lib = library('spng',
56-
spng_src,
55+
spng_lib = library('spng', spng_src,
5756
c_args : spng_args,
5857
dependencies : spng_deps,
5958
install : not static_subproject,
6059
version : meson.project_version()
6160
)
6261

6362
spng_dep = declare_dependency(
64-
link_with : spng_lib,
6563
compile_args : spng_args,
6664
include_directories : spng_inc,
67-
version : meson.project_version()
65+
link_with : spng_lib,
66+
version : meson.project_version(),
6867
)
6968

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

73+
if meson.is_subproject()
74+
subdir_done()
75+
endif
76+
77+
install_headers('spng/spng.h')
78+
7479
subdir('examples')
75-
subdir('tests')
7680

77-
if get_option('benchmarks') == true
81+
if get_option('dev_build')
82+
subdir('tests')
83+
endif
84+
85+
if get_option('benchmarks')
7886
subproject('spngt')
7987
endif
8088

8189
if static_subproject
8290
subdir_done()
8391
endif
8492

85-
install_headers('spng/spng.h')
86-
87-
pkg = import('pkgconfig')
88-
89-
pkg.generate(spng_lib,
93+
pc= import('pkgconfig')
94+
pc.generate(spng_lib,
95+
description : 'PNG decoding and encoding library',
9096
extra_cflags : spng_args,
91-
libraries_private : [ '-lm', '-lz' ],
92-
description : 'PNG decoding and encoding library'
9397
)

meson_options.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ option('use_miniz', type : 'boolean', value : false, description : 'Compile with
44
option('static_zlib', type : 'boolean', value : false, description : 'Link zlib statically')
55
option('benchmarks', type : 'boolean', value : false, description : 'Enable benchmarks, requires Git LFS')
66

7-
87
# Not for end-users
98
option('multithreading', type : 'feature', value : 'disabled', description : 'Experimental multithreading features')
10-
option('oss_fuzz', type : 'boolean', value : false, description : 'Enable regression tests with OSS-Fuzz corpora')
9+
option('oss_fuzz', type : 'boolean', value : false, description : 'Enable regression tests with OSS-Fuzz corpora')

tests/meson.build

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
if get_option('dev_build') == false
2-
subdir_done()
3-
endif
4-
51
add_languages('cpp', native : false)
62
cpp = meson.get_compiler('cpp')
73

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

14-
read_fuzzer = executable('fuzz_repro',
15-
'fuzz_main.c',
16-
'spng_read_fuzzer.c',
10+
read_fuzzer = executable('fuzz_repro', 'fuzz_main.c', 'spng_read_fuzzer.c',
1711
c_args : fuzzer_args,
18-
link_with : spng_lib
12+
include_directories : spng_inc,
13+
link_with : spng_lib,
1914
)
2015

21-
png_dep = dependency('libpng', version : '>=1.6.0', fallback : ['libpng', 'png_dep'])
16+
png_dep = dependency('libpng',
17+
version : '>=1.6.0',
18+
fallback : [ 'libpng', 'png_dep' ],
19+
default_options : [ 'default_library=static' ],
20+
)
2221

2322
test_deps = [ spng_dep, png_dep ]
2423

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

32-
subdir('images')
3331
subdir('crashers')
32+
subdir('images')
3433

35-
if get_option('oss_fuzz') == false
34+
if not get_option('oss_fuzz')
3635
subdir_done()
3736
endif
3837

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

4140
foreach case : corpora
4241
test('testcase', read_fuzzer, args : case)
43-
endforeach
42+
endforeach

tests/spng_read_fuzzer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#define SPNG_UNTESTED
2-
#include "../spng/spng.h"
2+
#include "spng.h"
33

44
#include <string.h>
55

0 commit comments

Comments
 (0)