meson: Build C++ tests for the currently supported C++ standard versions

We've various macros definitions that are depending using C++ features
that may not work in all the standard versions, so recompile the cxx
tests that we have in all the ones we want to support.
This commit is contained in:
Marco Trevisan (Treviño) 2022-09-13 18:26:40 +02:00
parent a20a36b26f
commit 1cbe7a6734
5 changed files with 61 additions and 0 deletions

View File

@ -27,6 +27,8 @@ if cc.has_header('pty.h')
endif endif
endif endif
test_cpp_args = test_c_args
if host_machine.system() == 'windows' if host_machine.system() == 'windows'
common_gio_tests_deps += [iphlpapi_dep, winsock2, cc.find_library ('secur32')] common_gio_tests_deps += [iphlpapi_dep, winsock2, cc.find_library ('secur32')]
endif endif
@ -130,8 +132,19 @@ if have_cxx
gio_tests += { gio_tests += {
'cxx' : { 'cxx' : {
'source' : ['cxx.cpp'], 'source' : ['cxx.cpp'],
'suite': ['C++'],
}, },
} }
foreach std, arg: cxx_standards
gio_tests += {
'cxx-@0@'.format(std) : {
'source' : ['cxx.cpp'],
'suite' : ['cpp'],
'cpp_args' : [arg],
},
}
endforeach
endif endif
test_extra_programs = { test_extra_programs = {
@ -853,6 +866,7 @@ foreach test_name, extra_args : gio_tests
exe = executable(test_name, [source, extra_sources], exe = executable(test_name, [source, extra_sources],
c_args : test_c_args + extra_args.get('c_args', []), c_args : test_c_args + extra_args.get('c_args', []),
cpp_args : test_cpp_args + extra_args.get('cpp_args', []),
dependencies : common_gio_tests_deps + extra_args.get('dependencies', []), dependencies : common_gio_tests_deps + extra_args.get('dependencies', []),
install_rpath : extra_args.get('install_rpath', ''), install_rpath : extra_args.get('install_rpath', ''),
install_dir: installed_tests_execdir, install_dir: installed_tests_execdir,

View File

@ -159,8 +159,19 @@ if have_cxx
glib_tests += { glib_tests += {
'cxx' : { 'cxx' : {
'source' : ['cxx.cpp'], 'source' : ['cxx.cpp'],
'suite': ['cpp'],
} }
} }
foreach std, arg: cxx_standards
glib_tests += {
'cxx-@0@'.format(std) : {
'source' : ['cxx.cpp'],
'suite' : ['cpp'],
'cpp_args' : [arg],
},
}
endforeach
endif endif
if cc.get_id() != 'msvc' if cc.get_id() != 'msvc'
@ -244,6 +255,7 @@ test_env.set('MALLOC_CHECK_', '2')
test_deps = [libm, thread_dep, libglib_dep] test_deps = [libm, thread_dep, libglib_dep]
test_cargs = ['-DG_LOG_DOMAIN="GLib"', '-UG_DISABLE_ASSERT'] test_cargs = ['-DG_LOG_DOMAIN="GLib"', '-UG_DISABLE_ASSERT']
test_cpp_args = test_cargs
foreach test_name, extra_args : glib_tests foreach test_name, extra_args : glib_tests
source = extra_args.get('source', test_name + '.c') source = extra_args.get('source', test_name + '.c')
@ -264,6 +276,7 @@ foreach test_name, extra_args : glib_tests
exe = executable(test_name, source, exe = executable(test_name, source,
c_args : test_cargs + extra_args.get('c_args', []), c_args : test_cargs + extra_args.get('c_args', []),
cpp_args : test_cpp_args + extra_args.get('cpp_args', []),
link_args : extra_args.get('link_args', []), link_args : extra_args.get('link_args', []),
dependencies : test_deps + extra_args.get('dependencies', []), dependencies : test_deps + extra_args.get('dependencies', []),
install_dir: installed_tests_execdir, install_dir: installed_tests_execdir,

View File

@ -15,8 +15,19 @@ if have_cxx
gmodule_tests += { gmodule_tests += {
'cxx' : { 'cxx' : {
'source' : ['cxx.cpp'], 'source' : ['cxx.cpp'],
'suite' : ['cpp'],
} }
} }
foreach std, arg: cxx_standards
gmodule_tests += {
'cxx-@0@'.format(std) : {
'source' : ['cxx.cpp'],
'suite' : ['cpp'],
'cpp_args' : [arg],
},
}
endforeach
endif endif
module_suffix = [] module_suffix = []
@ -49,6 +60,7 @@ test_env.set('MALLOC_CHECK_', '2')
test_deps = [libm, thread_dep, libglib_dep, libgmodule_dep] test_deps = [libm, thread_dep, libglib_dep, libgmodule_dep]
test_cargs = ['-DG_LOG_DOMAIN="GModule"', '-UG_DISABLE_ASSERT'] test_cargs = ['-DG_LOG_DOMAIN="GModule"', '-UG_DISABLE_ASSERT']
test_cpp_args = test_cargs
foreach test_name, extra_args : gmodule_tests foreach test_name, extra_args : gmodule_tests
source = extra_args.get('source', test_name + '.c') source = extra_args.get('source', test_name + '.c')
@ -69,6 +81,7 @@ foreach test_name, extra_args : gmodule_tests
exe = executable(test_name, source, exe = executable(test_name, source,
c_args : test_cargs + extra_args.get('c_args', []), c_args : test_cargs + extra_args.get('c_args', []),
cpp_args : test_cpp_args + extra_args.get('cpp_args', []),
link_args : extra_args.get('link_args', []), link_args : extra_args.get('link_args', []),
dependencies : test_deps + extra_args.get('dependencies', []), dependencies : test_deps + extra_args.get('dependencies', []),
export_dynamic : extra_args.get('export_dynamic', false), export_dynamic : extra_args.get('export_dynamic', false),

View File

@ -102,8 +102,19 @@ if have_cxx
gobject_tests += { gobject_tests += {
'cxx' : { 'cxx' : {
'source' : ['cxx.cpp'], 'source' : ['cxx.cpp'],
'suite' : ['cpp'],
}, },
} }
foreach std, arg: cxx_standards
gobject_tests += {
'cxx-@0@'.format(std) : {
'source' : ['cxx.cpp'],
'suite' : ['cpp'],
'cpp_args' : [arg],
},
}
endforeach
endif endif
if cc.get_id() != 'msvc' if cc.get_id() != 'msvc'
@ -125,6 +136,7 @@ test_env.set('MALLOC_CHECK_', '2')
test_deps = [libm, thread_dep, libglib_dep, libgobject_dep] test_deps = [libm, thread_dep, libglib_dep, libgobject_dep]
test_cargs = ['-DG_LOG_DOMAIN="GLib-GObject"', '-UG_DISABLE_ASSERT'] test_cargs = ['-DG_LOG_DOMAIN="GLib-GObject"', '-UG_DISABLE_ASSERT']
test_cpp_args = test_cargs
foreach test_name, extra_args : gobject_tests foreach test_name, extra_args : gobject_tests
source = extra_args.get('source', test_name + '.c') source = extra_args.get('source', test_name + '.c')
@ -145,6 +157,7 @@ foreach test_name, extra_args : gobject_tests
exe = executable(test_name, source, exe = executable(test_name, source,
c_args : test_cargs + extra_args.get('c_args', []), c_args : test_cargs + extra_args.get('c_args', []),
cpp_args : test_cpp_args + extra_args.get('cpp_args', []),
dependencies : test_deps + extra_args.get('dependencies', []), dependencies : test_deps + extra_args.get('dependencies', []),
install_dir: installed_tests_execdir, install_dir: installed_tests_execdir,
install: install, install: install,

View File

@ -13,6 +13,14 @@ cc = meson.get_compiler('c')
have_cxx = add_languages('cpp', native: false, required: get_option('oss_fuzz').enabled()) have_cxx = add_languages('cpp', native: false, required: get_option('oss_fuzz').enabled())
if have_cxx if have_cxx
cxx = meson.get_compiler('cpp') cxx = meson.get_compiler('cpp')
cxx_standards = {}
foreach std : ['98', '03', '11', '14', '17', '20', '2b', 'latest']
arg = (cxx.get_id() == 'msvc' ? '/std:' : '-std=') + 'c++' + std
if cxx.has_argument(arg)
cxx_standards += { std: arg }
endif
endforeach
endif endif
cc_can_run = meson.can_run_host_binaries() cc_can_run = meson.can_run_host_binaries()