1
0
mirror of https://github.com/benhoyt/inih.git synced 2025-01-17 22:22:53 +08:00
inih/meson.build
matoro ed4525140d
Add meson support for tests (#170)
Allows tests to use "meson test" instead of a shell script.  This also
means that they now fully respect user-specified toolchain (e.g. clang
compiler, custom CFLAGS, etc).  Running C++ test is conditional on
enabling INIReader support in the build.

```
 1/16 test_multi                               OK              0.05s
 2/16 test_multi_max_line                      OK              0.04s
 3/16 test_single                              OK              0.04s
 4/16 test_disallow_inline_comments            OK              0.03s
 5/16 test_stop_on_first_error                 OK              0.03s
 6/16 test_handler_lineno                      OK              0.02s
 7/16 test_heap                                OK              0.06s
 8/16 test_string                              OK              0.06s
 9/16 test_heap_max_line                       OK              0.05s
10/16 test_heap_realloc                        OK              0.05s
11/16 test_heap_realloc_max_line               OK              0.05s
12/16 test_heap_string                         OK              0.04s
13/16 test_call_handler_on_new_section         OK              0.04s
14/16 test_allow_no_value                      OK              0.03s
15/16 test_alloc                               OK              0.02s
16/16 test_INIReaderExample                    OK              0.02s

Ok:                 16
Expected Fail:      0
Fail:               0
Unexpected Pass:    0
Skipped:            0
Timeout:            0
```

Co-authored-by: matoro <matoro@users.noreply.github.com>
2024-06-12 09:47:53 +12:00

139 lines
3.7 KiB
Meson

project('inih',
['c'],
license : 'BSD-3-Clause',
version : '58',
default_options : ['cpp_std=c++11'],
meson_version: '>=0.56.0'
)
#### options ####
arg_static = []
distro_install = get_option('distro_install')
extra_args = []
if distro_install
pkg = import('pkgconfig')
else
if not get_option('multi-line_entries')
arg_static += ['-DINI_ALLOW_MULTILINE=0']
endif
if not get_option('utf-8_bom')
arg_static += ['-DINI_ALLOW_BOM=0']
endif
if not get_option('inline_comments')
arg_static += ['-DINI_ALLOW_INLINE_COMMENTS=0']
endif
inline_comment_prefix = get_option('inline_comment_prefix')
if inline_comment_prefix != ';'
arg_static += ['-DINI_INLINE_COMMENT_PREFIXES="' + inline_comment_prefix + '"']
endif
sol_comment_prefix = get_option('start-of-line_comment_prefix')
if sol_comment_prefix != ';#'
arg_static += ['-DINI_START_COMMENT_PREFIXES="' + sol_comment_prefix + '"']
endif
if get_option('allow_no_value')
arg_static += ['-DINI_ALLOW_NO_VALUE=1']
endif
if get_option('stop_on_first_error')
arg_static += ['-DINI_STOP_ON_FIRST_ERROR=1']
endif
if get_option('report_line_numbers')
arg_static += ['-DINI_HANDLER_LINENO=1']
endif
if get_option('call_handler_on_new_section')
arg_static += ['-DINI_CALL_HANDLER_ON_NEW_SECTION=1']
endif
if get_option('use_heap')
arg_static += ['-DINI_USE_STACK=0']
endif
max_line_length = get_option('max_line_length')
if max_line_length != 200
arg_static += ['-DINI_MAX_LINE=' + max_line_length.to_string()]
endif
initial_malloc_size = get_option('initial_malloc_size')
if initial_malloc_size != 200
arg_static += ['-DINI_INITIAL_ALLOC=' + initial_malloc_size.to_string()]
endif
if get_option('allow_realloc')
arg_static += ['-DINI_ALLOW_REALLOC=1']
endif
endif
if host_machine.system() == 'windows'
lib = get_option('default_library')
if lib == 'both'
error('default_library=both is not supported on Windows')
elif lib == 'shared'
extra_args += '-DINI_SHARED_LIB'
add_project_arguments('-DINI_SHARED_LIB_BUILDING', language: ['c', 'cpp'])
endif
endif
#### inih ####
inc_inih = include_directories('.')
src_inih = files('ini.c')
lib_inih = library('inih',
[src_inih],
include_directories : inc_inih,
c_args : [arg_static, extra_args],
install : distro_install,
soversion : '0',
gnu_symbol_visibility: 'hidden'
)
if distro_install
install_headers('ini.h')
pkg.generate(lib_inih,
name : 'inih',
description : 'simple .INI file parser',
extra_cflags : extra_args,
)
endif
inih_dep = declare_dependency(
link_with : lib_inih,
compile_args : arg_static + extra_args,
include_directories : inc_inih
)
subdir('tests')
#### INIReader ####
if get_option('with_INIReader')
add_languages('cpp')
inc_INIReader = include_directories('cpp')
src_INIReader = files(join_paths('cpp', 'INIReader.cpp'))
lib_INIReader = library('INIReader',
src_INIReader,
cpp_args : extra_args,
include_directories : inc_INIReader,
dependencies : inih_dep,
install : distro_install,
soversion : '0',
gnu_symbol_visibility: 'hidden'
)
if distro_install
install_headers('cpp/INIReader.h')
pkg.generate(lib_INIReader,
name : 'INIReader',
description : 'simple .INI file parser for C++',
extra_cflags : extra_args,
)
endif
INIReader_dep = declare_dependency(
link_with : lib_INIReader,
include_directories : inc_INIReader,
compile_args : extra_args
)
subdir('examples')
endif