generated from cpp-best-practices/cmake_conan_boilerplate_template
-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Taskfile.yml
149 lines (127 loc) · 5.67 KB
/
Taskfile.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# Notes
# - install task from: https://taskfile.dev/#/installation or use `setup-cpp --task true`
# - If using Visual Studio, either run the following commands inside the Visual Studio command prompt (vcvarsall) or set CMAKE_GENERATOR to "Visual Studio 17 2022"
version: 3
tasks:
# The templates called in the other tasks. The variables can be set using the `vars` parameter or by environment variables. To create global variables that are passed to the internally called templates, use `env`
# This template accepts the generator, build type and feature flags defined by the vars. Other flags can be passed by `CONFIGURE_FLAGS` and `BUILD_FLAGS`. For example, a specific target can be built by setting BUILD_FLAGS to "--target <NAME>"
build_template:
- cmake -S ./ -B ./build -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' -DCMAKE_BUILD_TYPE:STRING={{.CMAKE_BUILD_TYPE}} -DFEATURE_TESTS:BOOL={{.FEATURE_TESTS}} -DFEATURE_DOCS:BOOL='{{.FEATURE_DOCS | default "OFF"}}' {{.CONFIGURE_FLAGS}}
- cmake --build ./build --config {{.CMAKE_BUILD_TYPE}} {{.BUILD_FLAGS}}
# Execute the app or the tests
run_template:
- cd build/my_exe/test && ctest -C {{.CMAKE_BUILD_TYPE}} --output-on-failure
- cd build/my_header_lib/test && ctest -C {{.CMAKE_BUILD_TYPE}} --output-on-failure
- cd build/my_lib/test && ctest -C {{.CMAKE_BUILD_TYPE}} --output-on-failure
# Run with coverage analysis
coverage_template:
cmds:
# Set --sources "your_source_folder\*" and --filter "your_source_folder/" to have a clean coverage report
- |
{{if eq OS "windows"}}
OpenCppCoverage.exe --export_type html:./build/coverage --export_type cobertura:./build/coverage.xml --cover_children --sources "my_exe\*" --sources "my_lib\*" --sources "my_header_lib\*" --modules "build\*" -- task run_template
powershell -c "if (!\$env:CI) { echo '[info] Opening ./build/coverage/index.html...'; start ./build/coverage/index.html }"
{{else}}
task run_template
mkdir -p ./build/coverage/
gcovr -j {{.nproc | default 1}} --delete --filter "my_exe/" --filter "my_lib/" --filter "my_header_lib/" --root ./ --print-summary --html-details ./build/coverage/index.html --xml-pretty --xml ./build/coverage.xml --gcov-ignore-errors=no_working_dir_found ./build
echo "Open ./build/coverage/index.html in a browser for a visual coverage report"
{{end}}
env:
CMAKE_BUILD_TYPE: "{{.CMAKE_BUILD_TYPE}}"
build:
- task: build_template
vars:
FEATURE_TESTS: OFF
CMAKE_BUILD_TYPE: Release
build_debug:
- task: build_template
vars:
FEATURE_TESTS: OFF
CMAKE_BUILD_TYPE: Debug
build_cross_mingw:
- task: build_template
vars:
FEATURE_TESTS: OFF
CMAKE_BUILD_TYPE: Release
CONFIGURE_FLAGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DDEFAULT_TRIPLET=x64-mingw-dynamic
install:
- task: build
- cmake --install ./build --prefix {{.INSTALL_PREFIX | default "./install"}}
- cd build && cpack -C Release -G {{.CPACK_GENERATOR | default "ZIP"}}
test:
- task: build_template
vars:
FEATURE_TESTS: ON
CMAKE_BUILD_TYPE: Debug
- task: run_template
vars:
CMAKE_BUILD_TYPE: Debug
test_release_debug:
- task: build_template
vars:
FEATURE_TESTS: ON
CMAKE_BUILD_TYPE: RelWithDebInfo
- task: run_template
vars:
CMAKE_BUILD_TYPE: RelWithDebInfo
test_release:
- task: build_template
vars:
FEATURE_TESTS: ON
CMAKE_BUILD_TYPE: Release
- task: run_template
vars:
CMAKE_BUILD_TYPE: Release
coverage:
- task: build_template
vars:
FEATURE_TESTS: ON
CMAKE_BUILD_TYPE: Debug
- task: coverage_template
vars:
CMAKE_BUILD_TYPE: Debug
coverage_release_debug:
- task: build_template
vars:
FEATURE_TESTS: ON
CMAKE_BUILD_TYPE: RelWithDebInfo
- task: coverage_template
vars:
CMAKE_BUILD_TYPE: RelWithDebInfo
coverage_release:
- task: build_template
vars:
FEATURE_TESTS: ON
CMAKE_BUILD_TYPE: Release
- task: coverage_template
vars:
TEST_COMMAND: task run_template
CMAKE_BUILD_TYPE: Release
docs:
- task: build_template
vars:
CMAKE_BUILD_TYPE: Debug
FEATURE_DOCS: ON
BUILD_FLAGS: --target doxygen-docs
lint:
- |
{{if eq OS "windows"}}
powershell -c '$files=(git ls-files --exclude-standard); foreach ($file in $files) { if ((get-item $file).Extension -in ".cpp", ".hpp", ".c", ".cc", ".cxx", ".hxx", ".ixx") { clang-format -i -style=file $file } }'
{{else}}
git ls-files --exclude-standard | grep -E '\.(cpp|hpp|c|cc|cxx|hxx|ixx)$' | xargs clang-format -i -style=file
{{end}}
- |
{{if eq OS "windows"}}
powershell -c '$files=(git ls-files --exclude-standard); foreach ($file in $files) { $item=(get-item $file); if (($item.Name -eq "CMakeLists.txt") -or ($item.Extension -in ".cmake")) { cmake-format --in-place $file; cmake-lint $file --disabled-codes C0103 C0301 R0912 R0915 R0913 --suppress-decorations } }'
{{else}}
git ls-files --exclude-standard | grep -E '(CMakeLists\.txt)|(\.(cmake))$' | xargs cmake-format --in-place | xargs cmake-lint --disabled-codes C0103 C0301 R0912 R0915 R0913 --suppress-decorations
{{end}}
- ~/vcpkg/vcpkg format-manifest ./vcpkg.json
- npx -y cspell lint --no-progress --show-suggestions
clean: |
{{if eq OS "windows"}}
powershell -c 'function rmrf($file) { if (test-path $file) { rm -r -force $file }}; rmrf ./build; rmrf ./install'
{{else}}
rm -rf ./build ./install
{{end}}