Skip to content

Commit dbd4933

Browse files
mensindahenryiii
authored andcommitted
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
1 parent f583e5b commit dbd4933

File tree

8 files changed

+73
-0
lines changed

8 files changed

+73
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ a.out*
55
/Makefile
66
/CMakeFiles/*
77
/cmake_install.cmake
8+
/*.kdev4
9+
!/meson.build

azure-pipelines.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,22 @@ jobs:
4848
- template: .ci/azure-build.yml
4949
- template: .ci/azure-test.yml
5050

51+
- job: Meson
52+
pool:
53+
vmImage: 'ubuntu-latest'
54+
steps:
55+
- task: UsePythonVersion@0
56+
inputs:
57+
versionSpec: '3.6'
58+
- script: python3 -m pip install meson ninja
59+
- script: meson build
60+
displayName: Run meson to generate build
61+
workingDirectory: tests/mesonTest
62+
- script: ninja -C tests/mesonTest/build
63+
displayName: Build with Ninja
64+
- script: ./tests/mesonTest/build/main --help
65+
displayName: Run help
66+
5167
- job: Docker
5268
variables:
5369
cli11.single: OFF

meson.build

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
project('CLI11', ['cpp'],
2+
version : run_command(find_program('scripts/ExtractVersion.py')).stdout().strip(),
3+
default_options : ['cpp_std=c++11']
4+
)
5+
6+
CLI11_inc = include_directories(['include'])
7+
8+
CLI11_dep = declare_dependency(
9+
include_directories : CLI11_inc,
10+
version : meson.project_version(),
11+
)

scripts/ExtractVersion.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import re
5+
6+
base_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
7+
config_h = os.path.join(base_path, 'include', 'CLI', 'Version.hpp')
8+
data = {'MAJOR': 0, 'MINOR': 0, 'PATCH': 0}
9+
reg = re.compile(r'^\s*#define\s+CLI11_VERSION_([A-Z]+)\s+([0-9]+).*$')
10+
11+
with open(config_h, 'r') as fp:
12+
for l in fp:
13+
m = reg.match(l)
14+
if m:
15+
data[m.group(1)] = int(m.group(2))
16+
17+
print('{}.{}.{}'.format(data['MAJOR'], data['MINOR'], data['PATCH']))

tests/mesonTest/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# CLI11 Meson test / example
2+
3+
Requirements: meson, ninja
4+
5+
## Build
6+
7+
```bash
8+
meson build
9+
ninja -C build
10+
```

tests/mesonTest/main.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <CLI/CLI.hpp>
2+
3+
int main(int argc, char **argv) {
4+
CLI::App app{"App description"};
5+
6+
std::string filename = "default";
7+
app.add_option("-f,--file", filename, "A help string");
8+
9+
CLI11_PARSE(app, argc, argv);
10+
return 0;
11+
}

tests/mesonTest/meson.build

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
project('mesonTest', ['c', 'cpp'], default_options: ['cpp_std=c++11'])
2+
3+
cli11_dep = subproject('CLI11').get_variable('CLI11_dep')
4+
5+
mainExe = executable('main', ['main.cpp'], dependencies: [cli11_dep])

tests/mesonTest/subprojects/CLI11

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../..

0 commit comments

Comments
 (0)