Skip to content

Commit fcbc11b

Browse files
authored
feat: streamline cross-platform kata setup (#22)
Fetch and verify GoogleTest 1.17 when no installed package is available. Use Make locally and throughout CI while retaining direct CMake and CTest commands for environments without Make. Add three-platform CI, ownership, dependency updates, and zero-start documentation.
1 parent b00f995 commit fcbc11b

8 files changed

Lines changed: 145 additions & 38 deletions

File tree

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @Coding-Cuddles/kata-maintainers

.github/dependabot.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: github-actions
4+
directory: /
5+
schedule:
6+
interval: weekly

.github/workflows/main.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212

1313
steps:
14-
- uses: actions/checkout@v4
14+
- uses: actions/checkout@v7
1515

1616
- name: Check formatting
1717
run: make format-check
@@ -22,11 +22,11 @@ jobs:
2222
os: [ubuntu-latest, windows-latest, macos-latest]
2323
runs-on: ${{ matrix.os }}
2424

25-
steps:
26-
- uses: actions/checkout@v4
25+
env:
26+
GTEST_COLOR: "1"
2727

28-
- name: Build
29-
run: make build
28+
steps:
29+
- uses: actions/checkout@v7
3030

3131
- name: Test
3232
run: make test

.vscode/tasks.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
"group": {
1818
"kind": "test",
1919
"isDefault": true
20-
},
21-
"dependsOn": "Build"
20+
}
2221
},
2322
{
2423
"label": "Format",
@@ -30,4 +29,4 @@
3029
"problemMatcher": []
3130
}
3231
]
33-
}
32+
}

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
cmake_minimum_required(VERSION 3.19)
1+
cmake_minimum_required(VERSION 3.24)
22
project(bootstrap-cpp-kata CXX)
33

44
set(CMAKE_CXX_STANDARD 17)
55
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
set(CMAKE_CXX_EXTENSIONS OFF)
67
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
78
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
9+
set(CMAKE_COLOR_DIAGNOSTICS ON)
810

911
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
1012

@@ -32,5 +34,6 @@ if(UNIX)
3234
copy_if_different
3335
${CMAKE_BINARY_DIR}/compile_commands.json
3436
${CMAKE_CURRENT_LIST_DIR}
37+
COMMENT "Copying compile commands to the source directory"
3538
)
3639
endif()

Makefile

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,47 @@
1-
all: build test
1+
COLOR_CYAN := \033[36m
2+
COLOR_RESET := \033[0m
3+
4+
CLICOLOR ?= 1
5+
GTEST_COLOR ?= 1
6+
export CLICOLOR GTEST_COLOR
27

38
BUILDDIR ?= build
4-
SRCS := $(shell git ls-files *.cpp *.h)
9+
BUILDCONFIG ?= Debug
10+
SRCS := $(shell git ls-files '*.cpp' '*.h' '*.hpp')
11+
12+
.DEFAULT_GOAL := help
13+
14+
.PHONY: all
15+
all: test ## Build and run tests
16+
17+
.PHONY: help
18+
help: ## Show this help message
19+
@awk 'BEGIN {FS = ":.*##"; printf "Usage: make [options] $(COLOR_CYAN)[target] ...$(COLOR_RESET)\n\n"} \
20+
/^[a-zA-Z_-]+:.*##/ {printf " $(COLOR_CYAN)%-20s$(COLOR_RESET) %s\n", $$1, $$2}' \
21+
$(MAKEFILE_LIST)
522

623
.PHONY: build
7-
build:
8-
cmake -B ${BUILDDIR} .
9-
cmake --build ${BUILDDIR}
24+
build: ## Configure and build
25+
cmake -S . -B ${BUILDDIR} -DCMAKE_BUILD_TYPE=${BUILDCONFIG}
26+
cmake --build ${BUILDDIR} --config ${BUILDCONFIG}
1027

1128
.PHONY: test
12-
test:
13-
ctest --output-on-failure --test-dir ${BUILDDIR}
29+
test: build ## Build and run tests
30+
ctest --test-dir ${BUILDDIR} --build-config ${BUILDCONFIG} --output-on-failure
1431

1532
.PHONY: format
16-
format:
33+
format: ## Format C++ sources in place
1734
clang-format -i -style=file $(SRCS)
1835

1936
.PHONY: format-check
20-
format-check:
37+
format-check: ## Fail if C++ sources require formatting
2138
clang-format -style=file --dry-run -Werror $(SRCS) \
2239
|| (echo "Some files require formatting. Run 'make format' to fix." && exit 1)
2340

2441
.PHONY: clean
25-
clean:
26-
rm -rf ${BUILDDIR}
42+
clean: ## Remove generated build artifacts
43+
rm -rf ${BUILDDIR} compile_commands.json
2744

28-
ifndef VERBOSE
45+
ifneq ($(VERBOSE),1)
2946
.SILENT:
3047
endif

README.md

Lines changed: 83 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,95 @@
11
# Bootstrap for C++ coding kata
22

33
[![CI](https://github.com/Coding-Cuddles/bootstrap-cpp-kata/actions/workflows/main.yml/badge.svg)](https://github.com/Coding-Cuddles/bootstrap-cpp-kata/actions/workflows/main.yml)
4+
[![C++17](https://img.shields.io/badge/C%2B%2B-17-blue.svg)](https://en.cppreference.com/w/cpp/17)
5+
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
46

5-
## Overview
6-
7-
This is a bootstrap repository for clean code katas in C++17 using GoogleTest.
7+
Start a C++17 coding kata with GoogleTest. Setup is complete when the starter
8+
test passes.
89

910
## Prerequisites
1011

11-
- A compatible C++ compiler that supports at least C++17
12-
- [CMake](https://cmake.org)
13-
- [GoogleTest](https://github.com/google/googletest)
12+
Required:
13+
14+
- [Git](https://git-scm.com/downloads)
15+
- A compiler with C++17 support. Choose one:
16+
- [GCC](https://gcc.gnu.org/) 10+ on Linux
17+
- [LLVM Clang](https://llvm.org/) 14+ on Linux
18+
- [Apple Clang](https://developer.apple.com/xcode/) 17+ on macOS
19+
- [MSVC](https://visualstudio.microsoft.com/) 2022 on Windows
20+
- [CMake 3.24 or later](https://cmake.org)
21+
22+
Optional:
23+
24+
- [GNU Make](https://www.gnu.org/software/make/), for shorter commands. Every
25+
required task also has direct CMake and CTest commands.
26+
27+
You do not need to install GoogleTest separately. CMake finds an installed
28+
copy or downloads the pinned release when needed.
29+
30+
## Set up the kata
31+
32+
1. Clone the repository:
33+
34+
```console
35+
git clone https://github.com/Coding-Cuddles/bootstrap-cpp-kata.git
36+
```
37+
38+
2. Enter the repository directory:
39+
40+
```console
41+
cd bootstrap-cpp-kata
42+
```
43+
44+
3. Run the starter test. Use Make when it is installed:
45+
46+
```console
47+
make test
48+
```
49+
50+
Otherwise, use CMake and CTest directly:
51+
52+
```console
53+
cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug
54+
cmake --build build --config Debug
55+
ctest --test-dir build --build-config Debug --output-on-failure
56+
```
57+
58+
The first run may download and build GoogleTest. Setup is complete when CTest reports
59+
`100% tests passed`.
60+
61+
If a command reports a missing compiler or CMake, install that prerequisite
62+
and run the setup commands again.
63+
64+
## Work on the kata
65+
66+
1. Replace the starter assertions in `test_something.cpp` with the first kata test.
67+
68+
2. Run the tests after each change. Use Make when it is installed:
69+
70+
```console
71+
make test
72+
```
73+
74+
Otherwise, use CMake and CTest directly:
1475

15-
## Usage
76+
```console
77+
cmake --build build --config Debug
78+
ctest --test-dir build --build-config Debug --output-on-failure
79+
```
1680

17-
### Build
81+
Continue when CTest reports `100% tests passed`.
1882

19-
```console
20-
make build
21-
```
83+
## Make command reference
2284

23-
### Run tests
85+
Make is optional. Run `make` or `make help` to list these commands in the
86+
terminal.
2487

25-
```console
26-
make test
27-
```
88+
| Command | Result |
89+
| ------------------- | ----------------------------------------- |
90+
| `make all` | Build and run the test suite |
91+
| `make build` | Configure and build without running tests |
92+
| `make test` | Build and run the test suite |
93+
| `make format` | Format tracked C++ and header files |
94+
| `make format-check` | Check formatting without changing files |
95+
| `make clean` | Remove generated build artifacts |

cmake/FetchGTest.cmake

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
include(FetchContent)
22

3+
# Find an installed GoogleTest package or fetch and verify the pinned release
34
function(fetch_gtest)
5+
string(
6+
CONCAT
7+
gtest_url
8+
"https://github.com/google/googletest/releases/download/"
9+
"v1.17.0/googletest-1.17.0.tar.gz"
10+
)
11+
set(
12+
gtest_sha256
13+
65fab701d9829d38cb77c14acdc431d2108bfdbf8979e40eb8ae567edf10b27c
14+
)
15+
416
FetchContent_Declare(
517
googletest
6-
URL https://github.com/google/googletest/releases/download/v1.16.0/googletest-1.16.0.tar.gz
7-
URL_HASH MD5=9a75eb2ac97300cdb8b65b1a5833f411
18+
URL ${gtest_url}
19+
URL_HASH SHA256=${gtest_sha256}
820
DOWNLOAD_EXTRACT_TIMESTAMP
921
FALSE
1022
FIND_PACKAGE_ARGS
@@ -13,6 +25,7 @@ function(fetch_gtest)
1325
)
1426

1527
# Prevent overriding parent project's compiler/linker settings on Windows
28+
# cmake-lint: disable=C0103
1629
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
1730
FetchContent_MakeAvailable(googletest)
1831
endfunction()

0 commit comments

Comments
 (0)