Skip to main content

The missing CMake project initializer

Project description

cmake-init

๐Ÿš€ Generate modern CMake projects with best practices built-in

Powered by UV - the fast Python package manager.


Installation

For normal users, install directly from PyPI using uv:

# 1. Install UV (if you don't have it)
curl -LsSf https://astral.sh/uv/install.sh | sh

# 2. Install cmake-start from PyPI
uv tool install cmake-start

# 3. Create a project
cmake-init my-project

# 4. Build it
cd my-project
cmake --preset=dev
cmake --build --preset=dev

๐Ÿ“ฆ PyPI Package: https://pypi.org/project/cmake-start/


Quick Start (Development)

For contributors who want to develop cmake-start:

# 1. Install UV
curl -LsSf https://astral.sh/uv/install.sh | sh

# 2. Clone & Setup
git clone https://github.com/Guo-astro/cmake-start.git
cd cmake-start
./tasks.sh setup

# 3. Create a project
uv run cmake-init my-project

# 4. Build it
cd my-project
cmake --preset=dev
cmake --build --preset=dev

Usage

After installing from PyPI:

# C++ executable (default)
cmake-init my-app

# C++ library
cmake-init -s my-lib

# C++ header-only library
cmake-init -h my-headers

# C project
cmake-init --c my-c-app

# C++20 standard
cmake-init --std 20 my-modern-app

# With Conan/vcpkg
cmake-init -p conan my-app

For development (running from source): prefix commands with uv run, e.g., uv run cmake-init my-app

Important: Project names must be lowercase (e.g., my-project, not MyProject)


Code Quality Tools & OpenMP (Strongly Recommended)

clang-tidy, cppcheck, and OpenMP are enabled by default for better code quality and performance.

When you run cmake --preset=dev, the build system will:

  1. Check if clang-tidy, cppcheck, and OpenMP are installed
  2. Show detailed installation instructions if missing
  3. Continue building (tools disabled if not found)

Example Output (All Tools Found)

โœ… Found clang-tidy: /opt/homebrew/bin/clang-tidy
โœ… Found cppcheck: /opt/homebrew/bin/cppcheck
โณ OpenMP check deferred (waiting for project() command)
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
๐Ÿ“Š Code Quality & Performance Tools Status:
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
  โœ… clang-tidy: ENABLED
     /opt/homebrew/bin/clang-tidy
  โœ… cppcheck: ENABLED
     /opt/homebrew/bin/cppcheck
  โŒ OpenMP: ENABLED but NOT FOUND
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

โœ… Found OpenMP (post-project check):
     C++ version: 4.5

๐Ÿ“ To use OpenMP in your code:
   1. Add to CMakeLists.txt:
      target_link_libraries(your_target PRIVATE OpenMP::OpenMP_CXX)
   2. In your C/C++ code:
      #include <omp.h>
      #pragma omp parallel for

๐ŸŽ‰ All code quality and performance tools are active!

Example Output (Tools Missing)

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
โš ๏ธ  clang-tidy not found - installation instructions:
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

๐Ÿ“ฆ macOS (Homebrew):
   brew install llvm

โ„๏ธ  Nix (declarative - recommended):
   Add to your configuration.nix or home.nix:
   home.packages = [ pkgs.clang-tools ];

โ„๏ธ  Nix (imperative - quick test):
   nix-env -iA nixpkgs.clang-tools
   # OR with nix profile:
   nix profile install nixpkgs#clang-tools

๐Ÿ’ก To disable this check:
   cmake --preset=dev -DENABLE_clang-tidy=OFF
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

Installation Guide

๐Ÿ“ฆ macOS (Homebrew)
# Code quality tools
brew install llvm cppcheck

# OpenMP for parallel programming
brew install libomp

# Add to PATH if needed:
export PATH="/opt/homebrew/opt/llvm/bin:$PATH"
โ„๏ธ Nix (Declarative - Recommended)

Add to your configuration.nix, home.nix, or flake.nix:

# For system-wide (configuration.nix)
environment.systemPackages = with pkgs; [
  clang-tools       # clang-tidy
  cppcheck
  llvmPackages.openmp  # OpenMP
  # OR use gcc which includes OpenMP
  gcc
];

# For home-manager (home.nix)
home.packages = with pkgs; [
  clang-tools
  cppcheck
  llvmPackages.openmp
];

# For flake.nix devShell (recommended for project isolation)
devShells.default = pkgs.mkShell {
  buildInputs = with pkgs; [
    cmake
    clang-tools
    cppcheck
    llvmPackages.openmp
  ];
};

Then rebuild:

# NixOS
sudo nixos-rebuild switch

# home-manager
home-manager switch

# flake devShell
nix develop
โ„๏ธ Nix (Imperative - Quick Test)
# Traditional nix-env
nix-env -iA nixpkgs.clang-tools nixpkgs.cppcheck nixpkgs.llvmPackages.openmp

# Modern nix profile
nix profile install nixpkgs#clang-tools nixpkgs#cppcheck nixpkgs#llvmPackages.openmp

# Temporary shell (doesn't persist - great for testing)
nix-shell -p clang-tools cppcheck llvmPackages.openmp
๐Ÿ“ฆ Ubuntu/Debian
sudo apt update
sudo apt install clang-tidy cppcheck libomp-dev

# OpenMP is also included with GCC:
sudo apt install build-essential
๐Ÿ“ฆ Fedora
sudo dnf install clang-tools-extra cppcheck libomp-devel

# OpenMP is also included with GCC:
sudo dnf groupinstall 'Development Tools'
๐Ÿ“ฆ Arch Linux
sudo pacman -S clang cppcheck openmp

# Note: OpenMP is included with GCC on Arch
๐Ÿ“ฆ Windows
choco install llvm cppcheck

Using OpenMP in Your Code

Once OpenMP is detected, you can use it in your project:

# In your CMakeLists.txt
target_link_libraries(your_target PRIVATE OpenMP::OpenMP_CXX)
// In your C++ code
#include <omp.h>

int main() {
    #pragma omp parallel for
    for (int i = 0; i < 1000; i++) {
        // This loop runs in parallel!
        process(i);
    }
}

Disabling (Not Recommended)

If you want to disable these features:

cmake --preset=dev -DENABLE_CLANG_TIDY=OFF -DENABLE_CPPCHECK=OFF -DENABLE_OPENMP=OFF

Development

Project Structure

cmake-start/
โ”œโ”€โ”€ cmake-init/              โ† EDIT THESE (source of truth)
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ __main__.py
โ”‚   โ”œโ”€โ”€ cmake_init.py
โ”‚   โ”œโ”€โ”€ template.py
โ”‚   โ””โ”€โ”€ templates/          โ† All CMake templates
โ”‚
โ”œโ”€โ”€ src/cmake_init_lib/     โ† Generated by build.py (tracked in git)
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ __main__.py
โ”‚   โ”œโ”€โ”€ cmake_init.py
โ”‚   โ”œโ”€โ”€ template.py
โ”‚   โ””โ”€โ”€ templates/          โ† Copied from cmake-init/templates/
โ”‚
โ””โ”€โ”€ build.py                โ† Copies cmake-init/ โ†’ src/

Making Changes

# 1. Edit source files in cmake-init/
vim cmake-init/cmake_init.py
vim cmake-init/templates/common/cmake/code-quality.cmake

# 2. Rebuild (copies files to src/)
python build.py

# 3. Test your changes
uv run cmake-init test-project

# 4. Commit both cmake-init/ and src/ changes
git add cmake-init/ src/
git commit -m "Your changes"

Single source of truth: cmake-init/ directory Distribution package: src/cmake_init_lib/ (generated by build.py)


Common Issues

"Changes not working"

python build.py  # Run after editing cmake-init/

"Invalid project name"

# Bad:  uv run cmake-init MyProject
# Good: uv run cmake-init my-project

NixOS build errors

export CXX=clang++
cmake --preset=dev

Commands Reference

For Normal Users (PyPI Installation)

Command Description
uv tool install cmake-start Install from PyPI
cmake-init my-app Create C++ executable
cmake-init -s my-lib Create C++ library
cmake-init -h my-headers Create header-only library
cmake-init --c my-c-app Create C project
cmake-init --std 20 my-app Use C++20
cmake-init -p conan my-app Use Conan package manager
cmake-init --version Show version

For Contributors (Development)

Command Description
./tasks.sh setup Initial setup
uv run cmake-init my-app Create project (from source)
python build.py Build after editing templates
python release.py patch Release new version to PyPI

Releasing to PyPI

One command release:

# Option 1: Automatic (commits everything first)
./quick-release.sh patch  # 1.0.1 โ†’ 1.0.2

# Option 2: Manual (requires clean git)
python release.py patch   # 1.0.1 โ†’ 1.0.2

The script automates:

  • โœ… Version bump in pyproject.toml
  • โœ… Template sync (build.py)
  • โœ… Wheel + source distribution build
  • โœ… Git commit & tag
  • โœ… PyPI upload
  • โœ… GitHub push

First time setup:

# Get PyPI token: https://pypi.org/manage/account/token/
export PYPI_TOKEN='pypi-...'
# OR configure ~/.pypirc (see .pypirc.example)

See RELEASE.md for detailed documentation.


What Makes This Different?

โœ… Smart code quality - detects clang-tidy/cppcheck, shows clear install instructions โœ… Nix-friendly - proper support for declarative and imperative workflows โœ… Latest vcpkg - automatically fetches current baseline hash โœ… Fast - powered by UV (10-100x faster than pip) โœ… Modern - CMake presets, FetchContent-ready โœ… Developer-friendly - helpful error messages, not forced requirements โœ… Cross-platform - macOS, Linux, Windows, NixOS, Nix โœ… Single source - edit cmake-init/, run build.py


Links


Made with โค๏ธ for developers who hate boilerplate

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cmake_start-1.0.13.tar.gz (96.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cmake_start-1.0.13-py3-none-any.whl (86.4 kB view details)

Uploaded Python 3

File details

Details for the file cmake_start-1.0.13.tar.gz.

File metadata

  • Download URL: cmake_start-1.0.13.tar.gz
  • Upload date:
  • Size: 96.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.14

File hashes

Hashes for cmake_start-1.0.13.tar.gz
Algorithm Hash digest
SHA256 a6c82c827d2047efd3cc416bbf2bd127ade37c8767c22f0c3da26f2396c8bd3a
MD5 06c64b98e54430475bdb6493435c159c
BLAKE2b-256 1d8b0f0e73dfc4e46ab8731559e35cc6388b2675ff2eb6761d9b3a8cbd363d90

See more details on using hashes here.

File details

Details for the file cmake_start-1.0.13-py3-none-any.whl.

File metadata

File hashes

Hashes for cmake_start-1.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 e0558d35ee92ffb904313c59f5957377f3a7cd67dbe51a0b05b6bd9e4fca91dc
MD5 a01a0632cd52d966ec2b87a885454fce
BLAKE2b-256 a0a7c9342686517d9a5abbc8b7514c06f29ce49d9a057017090406f078a869a0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page