diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 673a7abc..e06777b2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -45,6 +45,24 @@ jobs: run: ctest --output-on-failure working-directory: build + meson-build: + name: Meson build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Prepare commands + run: | + pipx install meson + pipx install ninja + + - name: Configure + run: meson setup build-meson . -Dtests=true + + - name: Build + run: meson compile -C build-meson + + cmake-config: name: CMake config check runs-on: ubuntu-latest diff --git a/meson.build b/meson.build index 8b36c2a7..c0de945e 100644 --- a/meson.build +++ b/meson.build @@ -1,11 +1,23 @@ project('CLI11', ['cpp'], - version : run_command(find_program('scripts/ExtractVersion.py')).stdout().strip(), - default_options : ['cpp_std=c++11'] + version : run_command(find_program('scripts/ExtractVersion.py'), check: true).stdout().strip(), + default_options : ['cpp_std=c++11', 'warning_level=3'] ) +cxx = meson.get_compiler('cpp') + CLI11_inc = include_directories(['include']) CLI11_dep = declare_dependency( include_directories : CLI11_inc, version : meson.project_version(), ) + +if get_option('tests') + warnings = ['-Wshadow', '-Wsign-conversion', '-Wswitch-enum'] + if cxx.get_id() == 'gcc' and cxx.version().version_compare('>=4.9') + warnings += '-Weffc++' + endif + add_project_arguments(cxx.get_supported_arguments(warnings), language: 'cpp') + + subdir('tests') +endif diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 00000000..dd4654d4 --- /dev/null +++ b/meson_options.txt @@ -0,0 +1 @@ +option('tests', type: 'boolean', value: false, description: 'Build CLI11 tests') diff --git a/subprojects/catch2.wrap b/subprojects/catch2.wrap new file mode 100644 index 00000000..ce0b2a99 --- /dev/null +++ b/subprojects/catch2.wrap @@ -0,0 +1,11 @@ +[wrap-file] +directory = Catch2-2.13.7 +source_url = https://github.com/catchorg/Catch2/archive/v2.13.7.zip +source_filename = Catch2-2.13.7.zip +source_hash = 3f3ccd90ad3a8fbb1beeb15e6db440ccdcbebe378dfd125d07a1f9a587a927e9 +patch_filename = catch2_2.13.7-1_patch.zip +patch_url = https://wrapdb.mesonbuild.com/v2/catch2_2.13.7-1/get_patch +patch_hash = 2f7369645d747e5bd866317ac1dd4c3d04dc97d3aad4fc6b864bdf75d3b57158 + +[provide] +catch2 = catch2_dep diff --git a/tests/meson.build b/tests/meson.build new file mode 100644 index 00000000..27e22161 --- /dev/null +++ b/tests/meson.build @@ -0,0 +1,78 @@ +catch2 = dependency('catch2') + +testmain = static_library( + 'catch_main', + 'main.cpp', 'catch.hpp', + dependencies: catch2, +) +testdep = declare_dependency( + link_with: testmain, + dependencies: [catch2, CLI11_dep] +) + +link_test_lib = library( + 'link_test_1', + 'link_test_1.cpp', + dependencies: CLI11_dep, +) + +if cxx.get_id() == 'msvc' + nodeprecated = ['/wd4996'] +else + nodeprecated = ['-Wno-deprecated-declarations'] +endif + +boost = dependency('boost', required: false) +if boost.found() + boost_dep = declare_dependency( + dependencies: boost, + compile_args: '-DCLI11_BOOST_OPTIONAL', + ) +else + boost_dep = declare_dependency() +endif + +testnames = [ + ['HelpersTest', {}], + ['ConfigFileTest', {}], + ['OptionTypeTest', {}], + ['SimpleTest', {}], + ['AppTest', {}], + ['SetTest', {}], + ['TransformTest', {}], + ['CreationTest', {}], + ['SubcommandTest', {}], + ['HelpTest', {}], + ['FormatterTest', {}], + ['NewParseTest', {}], + ['OptionalTest', {'dependencies': boost_dep}], + ['DeprecatedTest', {'cpp_args': nodeprecated}], + ['StringParseTest', {}], + ['ComplexTypeTest', {}], + ['TrueFalseTest', {}], + ['OptionGroupTest', {}], + # multi-only + ['TimerTest', {}], + # link_test + ['link_test_2', {'link_with': link_test_lib}], +] + +if host_machine.system() == 'windows' + testnames += [['WindowsTest', {}]] +endif + +if boost.found() + testnames += [['BoostOptionTypeTest', {'dependencies': boost_dep}]] +endif + +foreach n: testnames + name = n[0] + kwargs = n[1] + t = executable(name, name + '.cpp', + cpp_args: kwargs.get('cpp_args', []), + build_by_default: false, + dependencies: [testdep] + kwargs.get('dependencies', []), + link_with: kwargs.get('link_with', []) + ) + test(name, t) +endforeach