Skip to content
Permalink
Browse files

build: switch from cmake to meson

  • Loading branch information
Snaipe committed Nov 6, 2018
1 parent 2460fba commit e1eeb3fa4c15bf314286c8d164baf4ca8fd587ce
Showing with 448 additions and 31 deletions.
  1. +4 −0 ci/isdir.py
  2. +62 −0 include/meson.build
  3. +152 −0 meson.build
  4. +8 −0 meson_options.txt
  5. +11 −0 po/meson.build
  6. +53 −0 samples/meson.build
  7. +22 −22 src/config.h.in
  8. +3 −3 src/entry/params.c
  9. +1 −1 src/io/json.c
  10. +1 −1 src/io/tap.c
  11. +1 −1 src/io/xml.c
  12. +1 −1 src/log/normal.c
  13. +97 −0 src/meson.build
  14. +1 −1 src/string/i18n.c
  15. +1 −1 src/string/i18n.h
  16. +30 −0 test/meson.build
@@ -0,0 +1,4 @@
#!/usr/bin/env python3
import os, sys
os.chdir(os.environ['MESON_SOURCE_ROOT'])
sys.exit(0 if os.path.isdir(sys.argv[1]) else 1)
@@ -0,0 +1,62 @@
api = files(
'criterion/abort.h',
'criterion/alloc.h',
'criterion/assert.h',
'criterion/criterion.h',
'criterion/embedded.h',
'criterion/event.h',
'criterion/hooks.h',
'criterion/logging.h',
'criterion/options.h',
'criterion/output.h',
'criterion/parameterized.h',
'criterion/redirect.h',
'criterion/stats.h',
'criterion/theories.h',
'criterion/types.h',
)

api_new = files(
'criterion/new/assert.h',
'criterion/new/memory.h',
'criterion/new/stream.h',
)

api_internal = files(
'criterion/internal/asprintf-compat.h',
'criterion/internal/assert.h',
'criterion/internal/capabilities.h',
'criterion/internal/common.h',
'criterion/internal/deprecation.h',
'criterion/internal/designated-initializer-compat.h',
'criterion/internal/hooks.h',
'criterion/internal/new_asserts.h',
'criterion/internal/ordered-set.h',
'criterion/internal/parameterized.h',
'criterion/internal/preprocess.h',
'criterion/internal/redirect.h',
'criterion/internal/stdio_filebuf.hxx',
'criterion/internal/stream.hxx',
'criterion/internal/test.h',
'criterion/internal/theories.h',
)

api_internal_assert = files(
'criterion/internal/assert/complex.h',
'criterion/internal/assert/exceptions.h',
'criterion/internal/assert/ieee.h',
'criterion/internal/assert/memory.h',
'criterion/internal/assert/op.h',
'criterion/internal/assert/op.hxx',
'criterion/internal/assert/stream.h',
'criterion/internal/assert/tag.h',
'criterion/internal/assert/tostr.h',
'criterion/internal/assert/types.h',
)

criterion_api = include_directories('.')

install_headers(api, subdir: 'criterion')
install_headers(api_new, subdir: join_paths('criterion', 'new'))
install_headers(api_internal, subdir: join_paths('criterion', 'internal'))
install_headers(api_internal_assert, subdir: join_paths('criterion', 'internal', 'assert'))
@@ -0,0 +1,152 @@
project('criterion', 'c',
meson_version : '>= 0.48.0',
license : 'MIT',
version : '2.3.3',
default_options : ['c_std=c11', 'cpp_std=c++11', 'warning_level=2'])

# standard install directories
prefix = get_option('prefix')
localedir = get_option('localedir')

# Helper scripts
auxdir = join_paths(meson.source_root(), 'ci')
isdir = join_paths(auxdir, 'isdir.py')

python3 = find_program('python3')
git = find_program('git', required: false)

# Get the right version

is_git_repo = run_command([isdir, '.git']).returncode() == 0

version = 'v' + meson.project_version()
if git.found() and is_git_repo
version = run_command([git.path(), 'describe', '--dirty', '--tags']).stdout().strip()
branch = run_command([git.path(), 'rev-parse', '--abbrev-ref', 'HEAD']).stdout().strip()

if branch != 'master'
version = '@0@ (@1@)'.format(version, branch)
endif
endif

add_languages('cpp')

cc = meson.get_compiler('c')

add_project_arguments(
cc.get_supported_arguments([
'-Wno-unused-parameter',
'-Wno-unused-value',
'-fvisibility=hidden',

# MSVC-specific stuff
'/SAFESEH:NO',
'/source-charset:utf-8',
]),
'-DCRITERION_BUILDING_DLL=1',
'-DPB_ENABLE_MALLOC=1',
'-D_GNU_SOURCE',
language: ['c', 'cpp'])

if target_machine.system() == 'windows'
add_project_arguments(
'-DVC_EXTRALEAN',
'-DWIN32_LEAN_AND_MEAN',
'-D_CRT_RAND_S',
'-D_CRT_SECURE_NO_WARNINGS=1',
'-D_WIN32_WINNT=0x600',
language: ['c', 'cpp'])
endif

checks = [
{'fn': 'clock_gettime'},
{'fn': 'fopencookie'},
{'fn': 'funopen'},
{'fn': 'getcwd'},
{'fn': 'isatty'},
{'fn': 'nl_langinfo'},
{'fn': 'open_memstream'},
{'fn': 'strtok_r'},
{'fn': 'strtok_s'},

{'sym': 'CLOCK_MONOTONIC_RAW', 'header': 'time.h'},

{'prefix': 'Win32', 'fn': 'GetCurrentDirectory'},
{'prefix': 'Win32', 'fn': 'PathIsRelative'},
{'prefix': 'Win32', 'hdr': 'synchapi.h'}
]

config = configuration_data()
config.set('package', meson.project_name())
config.set('version', version)
config.set('localedir', '@0@/@1@'.format(prefix, localedir))

config.set('MINGW_DEFINE_OFF_T', get_option('mingw-define-off_t'))

check_prelude = '''
#define _GNU_SOURCE
'''

foreach check : checks
chk_prefix = check.get('prefix', '')
if chk_prefix != ''
chk_prefix = chk_prefix + '_'
endif

result = false
if check.has_key('fn')
name = check.get('fn')
result = cc.has_function(name, prefix: check_prelude)
elif check.has_key('sym')
name = check.get('sym')
result = cc.has_header_symbol(check.get('header'), name, prefix: check_prelude)
elif check.has_key('hdr')
name = check.get('hdr')
result = cc.has_header(name)
endif

name = 'HAVE_@1@@0@'.format(name.to_upper(), chk_prefix.to_upper())
config.set(name, result)
endforeach

subdir('po')

if get_option('dev')
config.set('ENABLE_VALGRIND_ERRORS', true)
endif

criterion_includedir = include_directories(
'dependencies/debugbreak',
'dependencies/klib',
'dependencies/nanopb',
'dependencies/valgrind/include',

'include',
'src',
)

threads = dependency('threads')
nanomsg = dependency('nanomsg')
libgit2 = dependency('libgit2')

# These libraries are currently broken for not providing a pkg-config file
boxfort = cc.find_library('boxfort')
csptr = cc.find_library('csptr')
dyncall = cc.find_library('dyncall_s', required: get_option('theories'))

config.set('ENABLE_THEORIES', dyncall.found())

# optional platform-dependent standard libs
librt = cc.find_library('rt', required: false)
libm = cc.find_library('m', required: false)

if target_machine.system() == 'windows'
config.set10('HAVE_WIN32_THREADS', true)
else
config.set10('HAVE_PTHREADS', true)
endif

subdir('include')
subdir('src')
subdir('samples')
subdir('test')
@@ -0,0 +1,8 @@
option('tests', type: 'boolean', value: true)
option('dev', type: 'boolean', value: false)

option('i18n', type: 'feature', value: 'auto')
option('theories', type: 'feature', value: 'enabled')

# Platform-specific workarounds
option('mingw-define-off_t', type: 'boolean', value: false)
@@ -0,0 +1,11 @@
gettext = find_program('gettext', required: get_option('i18n'))

if gettext.found()
i18n = import('i18n')
config.set('ENABLE_NLS', true)

add_project_arguments('-DGETTEXT_PACKAGE="criterion"', language: 'c')
i18n.gettext(meson.project_name(),
args: '--directory=' + meson.source_root()
)
endif
@@ -0,0 +1,53 @@
samples = [
'asserts.c',
'description.c',
'fixtures.c',
'log.c',
'more-suites.c',
'parameterized.c',
'redirect.c',
'report.c',
'signal.c',
'simple.c',
'skip.c',
'suites.c',
'theories.c',
'timeout.c',

'tests/exit.c',
'tests/failmessages.c',
'tests/flood.c',
'tests/long-messages.c',
'tests/other-crashes.c',
'tests/theories_regression.c',
'tests/with-time.c',

'asserts.cc',
'description.cc',
'fixtures.cc',
'log.cc',
'more-suites.cc',
'parameterized.cc',
'redirect.cc',
'report.cc',
'signal.cc',
'simple.cc',
'skip.cc',
'suites.cc',
'theories.cc',

'tests/exception.cc',
'tests/exit.cc',
'tests/failmessages.cc',
'tests/long-messages.cc',
'tests/other-crashes.cc',
'tests/theories_regression.cc',
]

foreach sample : samples
e = executable(sample + '.bin', sample,
include_directories: [criterion_api],
dependencies: [libm],
link_with: criterion)
test(sample, e, args: '--always-succeed')
endforeach
@@ -1,29 +1,29 @@
#ifndef CONFIG_H_IN_
# define CONFIG_H_IN_
#define CONFIG_H_IN_

#cmakedefine ENABLE_NLS @ENABLE_NLS@
#cmakedefine ENABLE_VALGRIND_ERRORS @ENABLE_VALGRIND_ERRORS@
#cmakedefine MINGW_DEFINE_OFF_T @MINGW_DEFINE_OFF_T@
#cmakedefine HAVE_STRTOK_S
#cmakedefine HAVE_STRTOK_R
#mesondefine ENABLE_NLS
#mesondefine ENABLE_VALGRIND_ERRORS
#mesondefine MINGW_DEFINE_OFF_T

#cmakedefine HAVE_FUNOPEN @HAVE_FUNOPEN@
#cmakedefine HAVE_FOPENCOOKIE @HAVE_FOPENCOOKIE@
#cmakedefine HAVE_OPEN_MEMSTREAM @HAVE_OPEN_MEMSTREAM@
#cmakedefine HAVE_CLOCK_GETTIME @HAVE_CLOCK_GETTIME@
#cmakedefine HAVE_CLOCK_MONOTONIC_RAW @HAVE_CLOCK_MONOTONIC_RAW@
#cmakedefine HAVE_WIN32_THREADS @HAVE_WIN32_THREADS@
#cmakedefine HAVE_WIN32_SYNCHAPI @HAVE_WIN32_SYNCHAPI@
#cmakedefine HAVE_PTHREADS @HAVE_PTHREADS@
#cmakedefine HAVE_GETCWD @HAVE_GETCWD@
#cmakedefine HAVE_GETCURRENTDIRECTORY @HAVE_GETCURRENTDIRECTORY@
#cmakedefine HAVE_PATHISRELATIVE @HAVE_PATHISRELATIVE@
#cmakedefine HAVE_ISATTY @HAVE_ISATTY@
#cmakedefine HAVE_NL_LANGINFO @HAVE_NL_LANGINFO@
#mesondefine HAVE_CLOCK_GETTIME
#mesondefine HAVE_CLOCK_MONOTONIC_RAW
#mesondefine HAVE_FOPENCOOKIE
#mesondefine HAVE_FUNOPEN
#mesondefine HAVE_GETCWD
#mesondefine HAVE_ISATTY
#mesondefine HAVE_NL_LANGINFO
#mesondefine HAVE_OPEN_MEMSTREAM
#mesondefine HAVE_PTHREADS
#mesondefine HAVE_STRTOK_R
#mesondefine HAVE_STRTOK_S
#mesondefine HAVE_WIN32_GETCURRENTDIRECTORY
#mesondefine HAVE_WIN32_PATHISRELATIVE
#mesondefine HAVE_WIN32_SYNCHAPI
#mesondefine HAVE_WIN32_THREADS

# define LOCALEDIR "${LOCALEDIR}"
# define PACKAGE "${PROJECT_NAME}"
# define VERSION "${PROJECT_VERSION}"
#define LOCALEDIR "@localedir@"
#define PACKAGE "@package@"
#define VERSION "@version@"

#ifdef _WIN32
# define NN_SOCKET_PATH ""
@@ -37,7 +37,7 @@
#include "common.h"
#include "err.h"

#if ENABLE_NLS
#ifdef ENABLE_NLS
# include <libintl.h>
#endif

@@ -49,7 +49,7 @@
# include <langinfo.h>
#endif

#define VERSION_MSG "Tests compiled with Criterion v" VERSION "\n"
#define VERSION_MSG "Tests compiled with Criterion " VERSION "\n"

#define USAGE \
VERSION_MSG "\n" \
@@ -282,7 +282,7 @@ CR_API int criterion_handle_args(int argc, char *argv[],
};

setlocale(LC_ALL, "");
#if ENABLE_NLS
#ifdef ENABLE_NLS
textdomain(PACKAGE "-test");
#endif

@@ -99,7 +99,7 @@

#define JSON_BASE_TEMPLATE_BEGIN \
"{\n" \
" \"id\": \"Criterion v" VERSION "\",\n" \
" \"id\": \"Criterion " VERSION "\",\n" \
" \"passed\": " CR_SIZE_T_FORMAT ",\n" \
" \"failed\": " CR_SIZE_T_FORMAT ",\n" \
" \"errored\": " CR_SIZE_T_FORMAT ",\n" \
@@ -38,7 +38,7 @@ static void print_prelude(FILE *f, struct criterion_global_stats *stats)
fprintf(f, "TAP version 13\n1.."
CR_SIZE_T_FORMAT
"\n", stats->nb_tests);
fprintf(f, "# Criterion v%s\n", VERSION);
fprintf(f, "# Criterion %s\n", VERSION);
}

static void print_pre_suite(FILE *f, struct criterion_suite_stats *stats)

0 comments on commit e1eeb3f

Please sign in to comment.
You can’t perform that action at this time.