Skip to content

Commit 24ddfb9

Browse files
committed
fix: use CMake and set version
1 parent e299cbf commit 24ddfb9

File tree

6 files changed

+34
-18
lines changed

6 files changed

+34
-18
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@ jobs:
2222

2323
- uses: actions/setup-python@v2
2424

25-
- name: Make header
26-
run: python ./scripts/MakeSingleHeader.py include/CLI/* --output CLI11.hpp
27-
2825
- name: Prepare CMake config
29-
run: cmake -S . -B build
26+
run: cmake -S . -B build -DCLI11_SINGLE_FILE=ON
3027

3128
- name: Make package
3229
run: cmake --build build --target package_source
@@ -37,10 +34,13 @@ jobs:
3734
cp build/CLI11-*-Source.* CLI11-Source
3835
cp build/CLI11-*-Source.* .
3936
37+
- name: Make header
38+
run: cmake --build build --target CLI11-generate-single-file
39+
4040
- uses: actions/upload-artifact@v2
4141
with:
4242
name: CLI11.hpp
43-
path: CLI11.hpp
43+
path: build/include/CLI11.hpp
4444

4545
- uses: actions/upload-artifact@v2
4646
with:

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,10 @@ if(CLI11_SINGLE_FILE)
247247
add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp"
248248
COMMAND Python::Interpreter
249249
"${CMAKE_CURRENT_SOURCE_DIR}/scripts/MakeSingleHeader.py"
250-
"${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp"
250+
${CLI11_headers}
251+
--main "${CMAKE_CURRENT_SOURCE_DIR}/CLI11.hpp.in"
252+
--output "${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp"
253+
--version "${CLI11_VERSION}"
251254
DEPENDS
252255
"${CMAKE_CURRENT_SOURCE_DIR}/include/CLI/CLI.hpp"
253256
${CLI11_headers})

include/CLI/App.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#pragma once
88

9-
// #[CLI11:public_includes:set]
9+
// [CLI11:public_includes:set]
1010
#include <algorithm>
1111
#include <cstdint>
1212
#include <functional>
@@ -19,7 +19,7 @@
1919
#include <string>
2020
#include <utility>
2121
#include <vector>
22-
// #[CLI11:public_includes:end]
22+
// [CLI11:public_includes:end]
2323

2424
// CLI Library includes
2525
#include "ConfigFwd.hpp"

include/CLI/Option.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#pragma once
88

9-
// #[CLI11:public_includes:set]
9+
// [CLI11:public_includes:set]
1010
#include <algorithm>
1111
#include <functional>
1212
#include <memory>
@@ -15,7 +15,7 @@
1515
#include <tuple>
1616
#include <utility>
1717
#include <vector>
18-
// #[CLI11:public_includes:end]
18+
// [CLI11:public_includes:end]
1919

2020
#include "Error.hpp"
2121
#include "Macros.hpp"

include/CLI/StringTools.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include <string>
1616
#include <type_traits>
1717
#include <vector>
18-
// [CLI11:public_includes:set]
18+
// [CLI11:public_includes:end]
1919

2020
namespace CLI {
2121

scripts/MakeSingleHeader.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,17 @@ def read_header(self, filename):
6262
), "{name} read in more than once! Quitting.".format(name=name)
6363
self[name] = content
6464
elif action == "set":
65-
self[name] = self.get("name", set()) | set(content.strip().splitlines())
65+
self[name] = self.get(name, set()) | set(content.strip().splitlines())
6666
else:
6767
raise RuntimeError("Action not understood, must be verbatim or set")
6868

69+
def post_process(self):
70+
for key in self:
71+
if isinstance(self[key], set):
72+
self[key] = "\n".join(self[key])
6973

70-
def MakeHeader(output, main_header, files, tag, namespace, macro=None):
74+
75+
def MakeHeader(output, main_header, files, tag, namespace, macro=None, version=None):
7176
groups = HeaderGroups(tag)
7277

7378
# Set tag if possible to class variable
@@ -80,14 +85,13 @@ def MakeHeader(output, main_header, files, tag, namespace, macro=None):
8085
except OSError:
8186
groups["git"] = ""
8287

83-
with open(main_header) as f:
84-
header = f.read()
85-
8688
for f in files:
8789
groups.read_header(f)
8890

8991
groups["namespace"] = namespace
90-
groups["version"] = "HACK"
92+
groups["version"] = version or groups["git"]
93+
94+
groups.post_process()
9195

9296
with open(main_header) as f:
9397
single_header = f.read().format(**groups)
@@ -122,6 +126,15 @@ def MakeHeader(output, main_header, files, tag, namespace, macro=None):
122126
parser.add_argument(
123127
"--macro", nargs=2, help="Replaces OLD_PREFIX_ with NEW_PREFIX_"
124128
)
129+
parser.add_argument("--version", help="Include this version in the generated file")
125130
args = parser.parse_args()
126131

127-
MakeHeader(args.output, args.main, args.files, args.tag, args.namespace, args.macro)
132+
MakeHeader(
133+
args.output,
134+
args.main,
135+
args.files,
136+
args.tag,
137+
args.namespace,
138+
args.macro,
139+
args.version,
140+
)

0 commit comments

Comments
 (0)