From f93e28d9bcf595574b23256658c2c7a68048f1c5 Mon Sep 17 00:00:00 2001 From: "Issam E. Maghni" Date: Sat, 19 Dec 2020 14:11:57 -0500 Subject: [PATCH] meson: various minor improvements --- examples/meson.build | 2 +- meson.build | 55 +++++++++++++++++++++------------------- meson_options.txt | 3 +-- tests/meson.build | 23 ++++++++--------- tests/spng_read_fuzzer.c | 2 +- 5 files changed, 43 insertions(+), 42 deletions(-) diff --git a/examples/meson.build b/examples/meson.build index 3317fe97..678f9974 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -1 +1 @@ -example_exe = executable('example', 'example.c', dependencies : spng_dep) \ No newline at end of file +example_exe = executable('example', 'example.c', dependencies : spng_dep) diff --git a/meson.build b/meson.build index 3539e94b..7ccf290a 100644 --- a/meson.build +++ b/meson.build @@ -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 @@ -30,30 +30,29 @@ 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, @@ -61,20 +60,28 @@ spng_lib = library('spng', ) 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 @@ -82,12 +89,8 @@ 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' ) diff --git a/meson_options.txt b/meson_options.txt index c2489bbc..c5d8b43c 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -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') \ No newline at end of file +option('oss_fuzz', type : 'boolean', value : false, description : 'Enable regression tests with OSS-Fuzz corpora') diff --git a/tests/meson.build b/tests/meson.build index db792d29..3e1d66bf 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -1,7 +1,3 @@ -if get_option('dev_build') == false - subdir_done() -endif - add_languages('cpp', native : false) cpp = meson.get_compiler('cpp') @@ -11,14 +7,17 @@ if cc.has_function('fmemopen', prefix : '#include ', 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 ] @@ -29,10 +28,10 @@ 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 @@ -40,4 +39,4 @@ corpora = subproject('fuzzing_corpora').get_variable('corpora') foreach case : corpora test('testcase', read_fuzzer, args : case) -endforeach \ No newline at end of file +endforeach diff --git a/tests/spng_read_fuzzer.c b/tests/spng_read_fuzzer.c index ed0f2124..0c6e07da 100644 --- a/tests/spng_read_fuzzer.c +++ b/tests/spng_read_fuzzer.c @@ -1,5 +1,5 @@ #define SPNG_UNTESTED -#include "../spng/spng.h" +#include "spng.h" #include