From dbd49335066bae6984df76fd0b31302fe5cb8239 Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Thu, 25 Jul 2019 23:26:13 +0200 Subject: [PATCH] meson: Basic meson support (#299) * meson: Basic meson support With this patch, CLI11 can be used as a meson subproject: http://mesonbuild.com/Subprojects.html However, CMake is still required for testing and installation. The current meson.build is not a complete replacement. * meson: Added meson test * Adding Azure test --- .gitignore | 2 ++ azure-pipelines.yml | 16 ++++++++++++++++ meson.build | 11 +++++++++++ scripts/ExtractVersion.py | 17 +++++++++++++++++ tests/mesonTest/README.md | 10 ++++++++++ tests/mesonTest/main.cpp | 11 +++++++++++ tests/mesonTest/meson.build | 5 +++++ tests/mesonTest/subprojects/CLI11 | 1 + 8 files changed, 73 insertions(+) create mode 100644 meson.build create mode 100755 scripts/ExtractVersion.py create mode 100644 tests/mesonTest/README.md create mode 100644 tests/mesonTest/main.cpp create mode 100644 tests/mesonTest/meson.build create mode 120000 tests/mesonTest/subprojects/CLI11 diff --git a/.gitignore b/.gitignore index 66ead1a5..168acd7c 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ a.out* /Makefile /CMakeFiles/* /cmake_install.cmake +/*.kdev4 +!/meson.build diff --git a/azure-pipelines.yml b/azure-pipelines.yml index f70ee777..d5ac217b 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -48,6 +48,22 @@ jobs: - template: .ci/azure-build.yml - template: .ci/azure-test.yml +- job: Meson + pool: + vmImage: 'ubuntu-latest' + steps: + - task: UsePythonVersion@0 + inputs: + versionSpec: '3.6' + - script: python3 -m pip install meson ninja + - script: meson build + displayName: Run meson to generate build + workingDirectory: tests/mesonTest + - script: ninja -C tests/mesonTest/build + displayName: Build with Ninja + - script: ./tests/mesonTest/build/main --help + displayName: Run help + - job: Docker variables: cli11.single: OFF diff --git a/meson.build b/meson.build new file mode 100644 index 00000000..8b36c2a7 --- /dev/null +++ b/meson.build @@ -0,0 +1,11 @@ +project('CLI11', ['cpp'], + version : run_command(find_program('scripts/ExtractVersion.py')).stdout().strip(), + default_options : ['cpp_std=c++11'] +) + +CLI11_inc = include_directories(['include']) + +CLI11_dep = declare_dependency( + include_directories : CLI11_inc, + version : meson.project_version(), +) diff --git a/scripts/ExtractVersion.py b/scripts/ExtractVersion.py new file mode 100755 index 00000000..42d82cd2 --- /dev/null +++ b/scripts/ExtractVersion.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 + +import os +import re + +base_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) +config_h = os.path.join(base_path, 'include', 'CLI', 'Version.hpp') +data = {'MAJOR': 0, 'MINOR': 0, 'PATCH': 0} +reg = re.compile(r'^\s*#define\s+CLI11_VERSION_([A-Z]+)\s+([0-9]+).*$') + +with open(config_h, 'r') as fp: + for l in fp: + m = reg.match(l) + if m: + data[m.group(1)] = int(m.group(2)) + +print('{}.{}.{}'.format(data['MAJOR'], data['MINOR'], data['PATCH'])) diff --git a/tests/mesonTest/README.md b/tests/mesonTest/README.md new file mode 100644 index 00000000..ec08dc5b --- /dev/null +++ b/tests/mesonTest/README.md @@ -0,0 +1,10 @@ +# CLI11 Meson test / example + +Requirements: meson, ninja + +## Build + +```bash +meson build +ninja -C build +``` diff --git a/tests/mesonTest/main.cpp b/tests/mesonTest/main.cpp new file mode 100644 index 00000000..24647ba1 --- /dev/null +++ b/tests/mesonTest/main.cpp @@ -0,0 +1,11 @@ +#include + +int main(int argc, char **argv) { + CLI::App app{"App description"}; + + std::string filename = "default"; + app.add_option("-f,--file", filename, "A help string"); + + CLI11_PARSE(app, argc, argv); + return 0; +} diff --git a/tests/mesonTest/meson.build b/tests/mesonTest/meson.build new file mode 100644 index 00000000..56ebadb6 --- /dev/null +++ b/tests/mesonTest/meson.build @@ -0,0 +1,5 @@ +project('mesonTest', ['c', 'cpp'], default_options: ['cpp_std=c++11']) + +cli11_dep = subproject('CLI11').get_variable('CLI11_dep') + +mainExe = executable('main', ['main.cpp'], dependencies: [cli11_dep]) diff --git a/tests/mesonTest/subprojects/CLI11 b/tests/mesonTest/subprojects/CLI11 new file mode 120000 index 00000000..a8a4f8c2 --- /dev/null +++ b/tests/mesonTest/subprojects/CLI11 @@ -0,0 +1 @@ +../../.. \ No newline at end of file