TsukiNi22/ai-utils / skills/cpp/cpp-project
cpp-project
UnverifiedSet up a new C++20 project in Tsukini's way with the setup.sh of the cpp_project_template repository (TsukiNi22/cpp_project_template) - name / core class renaming, kind of project (binary, static .a or shared .so library, header-only; RPM/DEB/Arch packages of every variant, Windows MinGW-w64 build and packages), libutils v4 or not, exception codes, GTest tests, the CI/CD workflows of the template (dispatch, unit tests, build, packages, GitHub release from the CHANGELOG, docs) and the optional gh-pages branch (signed packages repository + docs), install script, README/CHANGELOG/docs written by the template, xstyle pre-commit hook - using the other skills (cmake-style, cpp-class, libutils-exception, readme-style, git-conventions, ci-cd, html-doc). Use whenever the user wants to create, bootstrap, initialize or scaffold a new C++ project or repository.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 14.5 KB |
| requires.txt | markdown | 85 B |
| scripts/new_project.shexecutable | script | 4.7 KB |
| scripts/update_gitignore.pyexecutable | script | 6.4 KB |
scripts/update_gitignore.py
View on GitHub#!/usr/bin/env python3
"""
Keep the .gitignore of a C++ project in line with what its CMake produces.
Usage:
update_gitignore.py [<project root>] [--dry-run]
Reads the root CMakeLists.txt and the sub-directories it adds (tests/...), then writes a managed block in
.gitignore with:
- the executables written in the sources (CMAKE_RUNTIME_OUTPUT_DIRECTORY = ${CMAKE_SOURCE_DIR}): /<name>
- the libraries/plugins written in the sources (LIBRARY/ARCHIVE_OUTPUT_DIRECTORY): /<dir>/*.so, *.a
- the generated files (GENERATED_EXCEPTION_HEADER, configure_file outputs in the sources)
- the packages when CPack is used (*.rpm, *.deb) and the build directory
The block is replaced at each run (idempotent); lines already present elsewhere in the file are not repeated.
"""
import argparse
import os
import re
import sys
BEGIN = "## Project outputs (generated by cpp-project/scripts/update_gitignore.py, rerun it after a CMake change)"
END = "## End of project outputs"
def commands(text: str) -> list[tuple[str, list[str]]]:
text = re.sub(r"#[^\n]*", "", text)
out = []
for m in re.finditer(r"([A-Za-z_]\w*)\s*\(", text):
depth, i = 1, m.end()
while i < len(text) and depth:
depth += {"(": 1, ")": -1}.get(text[i], 0)
i += 1
args = re.findall(r'"[^"]*"|[^\s"]+', text[m.end():i - 1])
out.append((m.group(1).lower(), [a.strip('"') for a in args]))
return out
def scan(root: str, rel: str, variables: dict, found: dict, depth: int = 0) -> None:
path = os.path.join(root, rel, "CMakeLists.txt")
if depth > 4 or not os.path.isfile(path):
return
v = dict(variables)
v["CMAKE_CURRENT_SOURCE_DIR"] = os.path.join(root, rel).rstrip("/")
def expand(s: str) -> str:
for _ in range(8):
s = re.sub(r"\$\{(\w+)\}", lambda m: v.get(m.group(1), ""), s)
return s
def inside(p: str) -> str | None:
p = os.path.normpath(expand(p))
if not os.path.isabs(p):
p = os.path.normpath(os.path.join(root, rel, p))
r = os.path.relpath(p, root)
return None if r.startswith("..") else r
runtime_here = None
executables = []
for name, args in commands(open(path, encoding="utf-8").read()):
if name == "set" and args:
v[args[0]] = expand(" ".join(args[1:]))
if args[0] == "CMAKE_RUNTIME_OUTPUT_DIRECTORY" and len(args) > 1:
runtime_here = inside(args[1])
if args[0] == "GENERATED_EXCEPTION_HEADER" and len(args) > 1:
r = inside(args[1])
if r: found["generated"].add("/" + r)
elif name == "add_executable" and args:
executables.append(expand(args[0]))
elif name == "add_library" and args:
found["libraries"].add(expand(args[0]))
elif name == "set_target_properties":
for i, a in enumerate(args):
if a in ("LIBRARY_OUTPUT_DIRECTORY", "ARCHIVE_OUTPUT_DIRECTORY", "RUNTIME_OUTPUT_DIRECTORY") and i + 1 < len(args):
r = inside(args[i + 1])
if r and r != ".": found["dirs"].add((r, a.split("_")[0]))
elif name == "configure_file" and len(args) > 1:
r = inside(args[1])
if r and not r.startswith(("build/", "build")) and "CMAKE_BINARY_DIR" not in args[1]:
found["generated"].add("/" + r)
elif name == "include" and args and args[0] == "CPack":
found["cpack"] = True
elif name == "add_subdirectory" and args:
scan(root, os.path.join(rel, expand(args[0])), v, found, depth + 1)
if runtime_here is not None:
for e in executables:
found["executables"].add("/" + (e if runtime_here == "." else os.path.join(runtime_here, e)))
def main() -> int:
ap = argparse.ArgumentParser()
ap.add_argument("root", nargs="?", default=".")
ap.add_argument("--dry-run", action="store_true")
a = ap.parse_args()
root = os.path.abspath(a.root)
if not os.path.isfile(os.path.join(root, "CMakeLists.txt")):
sys.stderr.write(f"Error: no CMakeLists.txt in {root}\n")
return 1
found = {"executables": set(), "libraries": set(), "dirs": set(), "generated": set(), "cpack": False}
scan(root, "", {"CMAKE_SOURCE_DIR": root, "PROJECT_SOURCE_DIR": root}, found)
# a MinGW toolchain (the Windows build of the template): the .exe at the same place, its build directory
toolchains = os.path.join(root, "cmake", "toolchain")
windows = os.path.isdir(toolchains) and any("mingw" in f.lower() for f in os.listdir(toolchains))
if windows:
found["executables"] |= {e + ".exe" for e in found["executables"]}
block = []
if found["executables"]:
block += ["# Executables"] + sorted(found["executables"])
if found["dirs"]:
block += ["# Libraries / plugins written in the sources"]
for d, kind in sorted(found["dirs"]):
block.append(f"/{d}/*.so" if kind == "LIBRARY" else f"/{d}/*.a" if kind == "ARCHIVE" else f"/{d}/*")
if found["generated"]:
block += ["# Generated files"] + sorted(found["generated"])
if found["cpack"]:
block += ["# Packages (CPack)", "*.rpm", "*.deb", "_CPack_Packages/"]
block += ["# Build", "/build"] + (["/build-windows"] if windows else [])
gi = os.path.join(root, ".gitignore")
content = open(gi, encoding="utf-8").read() if os.path.exists(gi) else ""
content = re.sub(rf"\n?{re.escape(BEGIN)}\n.*?{re.escape(END)}\n?", "\n", content, flags=re.S).rstrip("\n")
existing = {l.strip() for l in content.split("\n")}
def covered(l: str) -> bool:
if l in existing or l.lstrip("/") in existing: return True
glob = l.rsplit("/", 1)[-1]
return glob.startswith("*.") and glob in existing # '/plugins/*.so' covered by a global '*.so'
lines = [l for l in block if l.startswith("#") or not covered(l)]
# Drop the comment of an empty group
cleaned = []
for i, l in enumerate(lines):
if l.startswith("#") and (i + 1 == len(lines) or lines[i + 1].startswith("#")):
continue
cleaned.append(l)
new = (content + "\n\n" if content else "") + "\n".join([BEGIN] + cleaned + [END]) + "\n"
if a.dry_run:
print("\n".join([BEGIN] + cleaned + [END]))
return 0
with open(gi, "w", encoding="utf-8") as f:
f.write(new)
print(f".gitignore: {len([l for l in cleaned if not l.startswith('#')])} project output(s) -> {gi}")
return 0
if __name__ == "__main__":
sys.exit(main())
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 318k | Updated | Claude CodeCodex | Unverified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 318k | Updated | Claude CodeCodex | Unverified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 318k | Updated | Claude CodeCodex | Unverified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |