Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Meson build with configuration #140

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
66 changes: 38 additions & 28 deletions meson.build
Original file line number Diff line number Diff line change
@@ -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 = []
Expand All @@ -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

Expand All @@ -23,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')
6 changes: 3 additions & 3 deletions tests/framac_stubs.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef SPNG_FRAMAC_STUBS_H
#define SPNG_FRAMAC_STUBS_H
#ifndef FRAMAC_STUBS_H
#define FRAMAC_STUBS_H

#include <stddef.h>

Expand Down Expand Up @@ -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 */
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: 2 additions & 0 deletions tests/ossfuzz.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
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
14 changes: 10 additions & 4 deletions tests/target_clones.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
/* This will only be available for GCC with glibc for the foreseeable future */

#include <stdlib.h> /* 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;
}
const int y = f(39);
if (y != 42) {
exit(EXIT_FAILURE);
}

return EXIT_SUCCESS;
}