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
This commit is contained in:
Daniel Mensinger 2019-07-25 23:26:13 +02:00 committed by Henry Schreiner
parent f583e5baf6
commit dbd4933506
8 changed files with 73 additions and 0 deletions

2
.gitignore vendored
View File

@ -5,3 +5,5 @@ a.out*
/Makefile
/CMakeFiles/*
/cmake_install.cmake
/*.kdev4
!/meson.build

View File

@ -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

11
meson.build Normal file
View File

@ -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(),
)

17
scripts/ExtractVersion.py Executable file
View File

@ -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']))

10
tests/mesonTest/README.md Normal file
View File

@ -0,0 +1,10 @@
# CLI11 Meson test / example
Requirements: meson, ninja
## Build
```bash
meson build
ninja -C build
```

11
tests/mesonTest/main.cpp Normal file
View File

@ -0,0 +1,11 @@
#include <CLI/CLI.hpp>
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;
}

View File

@ -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])

View File

@ -0,0 +1 @@
../../..