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 92877c9e..7ccf290a 100644 --- a/meson.build +++ b/meson.build @@ -1,7 +1,14 @@ project('libspng', 'c', version : '0.6.2', - license : [ 'bsd', 'libpng2' ], - default_options : 'c_std=c99' + license : [ 'BSD-2-Clause', 'libpng-2.0' ], + default_options : [ + 'b_lto=true', + 'b_ndebug=if-release', + 'buildtype=debugoptimized', + 'c_std=c99', + 'warning_level=3', + # 'werror=true', + ], ) spng_args = [] @@ -12,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 @@ -23,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, @@ -54,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 @@ -75,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/framac_stubs.h b/tests/framac_stubs.h index 7a33a224..4b03f9d2 100644 --- a/tests/framac_stubs.h +++ b/tests/framac_stubs.h @@ -1,5 +1,5 @@ -#ifndef SPNG_FRAMAC_STUBS_H -#define SPNG_FRAMAC_STUBS_H +#ifndef FRAMAC_STUBS_H +#define FRAMAC_STUBS_H #include @@ -86,4 +86,4 @@ unsigned long crc32(unsigned long crc, const unsigned char *buf, unsigned int le return crc+len; } -#endif /* SPNG_FRAMAC_STUBS_H */ +#endif /* FRAMAC_STUBS_H */ 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/ossfuzz.sh b/tests/ossfuzz.sh index ce8eaf36..e3c5ce7d 100755 --- a/tests/ossfuzz.sh +++ b/tests/ossfuzz.sh @@ -18,12 +18,14 @@ ar x libz.a ar rcs libspng_static.a *.o $CXX $CXXFLAGS -std=c++11 \ + -I$SRC/libspng/spng \ $SRC/libspng/tests/spng_read_fuzzer.c \ -DSPNGT_HAVE_FMEMOPEN=1 \ -o $OUT/spng_read_fuzzer \ $LIB_FUZZING_ENGINE $SRC/libspng/build/libspng_static.a $SRC/zlib/build/libz.a $CXX $CXXFLAGS -std=c++11 -I$SRC/zlib/build -I$SRC/zlib \ + -I$SRC/libspng/spng \ $SRC/libspng/tests/spng_read_fuzzer.c \ -DSPNGT_HAVE_FMEMOPEN=1 \ -o $OUT/spng_read_fuzzer_structure_aware \ 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 diff --git a/tests/target_clones.c b/tests/target_clones.c index 6bdd5d9a..0eecf0af 100644 --- a/tests/target_clones.c +++ b/tests/target_clones.c @@ -1,12 +1,18 @@ /* This will only be available for GCC with glibc for the foreseeable future */ +#include /* EXIT_*, exit */ + __attribute__((target_clones("default,avx2"))) int f(int x) { return x + 3; } -int main(int argc, char **argv) +int main(void) { - int y = f(39); - return 0; -} \ No newline at end of file + const int y = f(39); + if (y != 42) { + exit(EXIT_FAILURE); + } + + return EXIT_SUCCESS; +}