Skip to main content

Build system generator - Makefile, CMake, and more.

Project description

buildgen

A build system generator package supporting Makefile, CMake, and cross-generator project definitions.

Originally inspired by prior work on shedskin.makefile in the shedskin project.

Installation

pip install buildgen

Quick Start

# Create a project config
buildgen project init -t full -n myproject -o project.json

# Generate both Makefile and CMakeLists.txt
buildgen project generate -c project.json --all

# Or generate CMake with Makefile frontend
buildgen project generate -c project.json --cmake

Features

  • Makefile Generation: Programmatic Makefile creation with variables, pattern rules, conditionals
  • CMake Generation: Full CMakeLists.txt generation with find_package, FetchContent, install rules
  • Cross-Generator: Define project once in JSON/YAML, generate both build systems
  • CMake Frontend: Use CMake as build system with convenient Makefile wrapper
  • Project Templates: Quick-start templates for common project types
  • scikit-build-core Templates: Python extension project scaffolding (pybind11, cython, nanobind, C)

Usage

CLI

# Project configuration workflow (recommended)
buildgen project init -t full -n myproject -o project.json
buildgen project generate -c project.json --all
buildgen project types  # List available templates

# Direct Makefile generation
buildgen makefile generate -o Makefile --targets "all:main.o:"
buildgen makefile build myprogram --cppfiles main.cpp

# Direct CMake generation
buildgen cmake generate -o CMakeLists.txt --project myapp --cxx-standard 17
buildgen cmake build -S . -B build --build-type Release

Python API

from buildgen import ProjectConfig, TargetConfig, DependencyConfig

# Load from config file
config = ProjectConfig.load("project.json")
config.generate_all()  # Creates Makefile and CMakeLists.txt

# Or build programmatically
config = ProjectConfig(
    name="myproject",
    version="1.0.0",
    cxx_standard=17,
    compile_options=["-Wall", "-Wextra"],
    dependencies=[
        DependencyConfig(name="Threads"),
        DependencyConfig(
            name="fmt",
            git_repository="https://github.com/fmtlib/fmt.git",
            git_tag="10.1.1",
        ),
    ],
    targets=[
        TargetConfig(
            name="mylib",
            target_type="static",
            sources=["src/lib.cpp"],
            include_dirs=["include"],
        ),
        TargetConfig(
            name="myapp",
            target_type="executable",
            sources=["src/main.cpp"],
            link_libraries=["mylib", "fmt::fmt"],
            install=True,
        ),
    ],
)
config.generate_all()

CMake with Makefile Frontend

Generate CMake as the build system with a Makefile that wraps cmake commands:

config.generate_cmake_with_frontend(
    build_dir="build",
    build_type="Release",
)

This creates:

  • CMakeLists.txt - The actual build logic
  • Makefile - Convenience wrapper with targets:
make              # Configure and build
make build        # Same as above
make configure    # Run cmake configure only
make clean        # Remove build directory
make rebuild      # Clean and rebuild
make install      # Install the project
make test         # Run tests with ctest
make myapp        # Build specific target
make help         # Show available targets

# Override defaults
make BUILD_TYPE=Debug
make BUILD_DIR=cmake-build
make CMAKE_FLAGS="-DFOO=bar"

Project Configuration

JSON Format

{
    "name": "myproject",
    "version": "1.0.0",
    "cxx_standard": 17,
    "compile_options": ["-Wall", "-Wextra"],
    "dependencies": [
        "Threads",
        {"name": "OpenSSL", "required": true},
        {
            "name": "fmt",
            "git_repository": "https://github.com/fmtlib/fmt.git",
            "git_tag": "10.1.1"
        }
    ],
    "targets": [
        {
            "name": "mylib",
            "type": "static",
            "sources": ["src/lib.cpp"],
            "include_dirs": ["include"],
            "install": true
        },
        {
            "name": "myapp",
            "type": "executable",
            "sources": ["src/main.cpp"],
            "link_libraries": ["mylib", "Threads::Threads"],
            "install": true
        }
    ]
}

Project Templates

buildgen project types
Template Description
executable Single executable (src/main.cpp)
static Static library with include/
shared Shared library with -fPIC
header-only Header-only/interface library
library-with-tests Library + test executable
app-with-lib Executable with internal library
full Library + app + tests + Threads
skbuild-pybind11 Python extension using pybind11
skbuild-cython Python extension using Cython
skbuild-c Python C extension (Python.h)
skbuild-nanobind Python extension using nanobind

scikit-build-core Projects

Generate complete Python extension projects with scikit-build-core:

# Create a pybind11 extension project
buildgen project init -t skbuild-pybind11 -n myext

# Use traditional virtualenv instead of uv
buildgen project init -t skbuild-pybind11 -n myext --env venv

This creates a complete project structure:

myext/
  pyproject.toml      # scikit-build-core configuration
  CMakeLists.txt      # CMake build instructions
  Makefile            # Convenience wrapper
  src/myext/
    __init__.py       # Python package
    _core.cpp         # C++ extension source
  tests/
    test_myext.py     # pytest tests

The generated Makefile provides convenient commands (using uv by default):

make sync     # Initial setup (uv sync)
make build    # Rebuild extension after code changes
make test     # Run tests (uv run pytest)
make wheel    # Build wheel distribution
make clean    # Remove build artifacts

For traditional virtualenv workflows, use --env venv to generate pip/python commands instead.

Low-Level API

For fine-grained control, use the generators directly:

from buildgen import MakefileGenerator, CMakeListsGenerator

# Makefile
gen = MakefileGenerator("Makefile")
gen.add_cxxflags("-Wall", "-std=c++17")
gen.add_target("myapp", "$(CXX) $(CXXFLAGS) -o $@ $^", deps=["main.o"])
gen.add_pattern_rule("%.o", "%.cpp", "$(CXX) $(CXXFLAGS) -c $< -o $@")
gen.add_phony("all", "clean")
gen.generate()

# CMake
gen = CMakeListsGenerator("CMakeLists.txt")
gen.set_project("myapp", version="1.0.0")
gen.set_cxx_standard(17)
gen.add_find_package("Threads", required=True)
gen.add_executable("myapp", ["src/main.cpp"], link_libraries=["Threads::Threads"])
gen.generate()

Development

make test        # Run tests (224 tests)
make coverage    # Coverage report

License

GPL-3.0-or-later

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

buildgen-0.1.2.tar.gz (34.8 kB view details)

Uploaded Source

Built Distribution

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

buildgen-0.1.2-py3-none-any.whl (43.9 kB view details)

Uploaded Python 3

File details

Details for the file buildgen-0.1.2.tar.gz.

File metadata

  • Download URL: buildgen-0.1.2.tar.gz
  • Upload date:
  • Size: 34.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for buildgen-0.1.2.tar.gz
Algorithm Hash digest
SHA256 22168f9b85ad9250117e27b328a07e7d5636c4c561fedca0b466fffeb5d7ae39
MD5 28ece9672838fc36bc7c6dc7ac7de236
BLAKE2b-256 85b012e62c494b89c678c3cebad694687027fd3abdd9dafbe24e9b79e03c95c8

See more details on using hashes here.

File details

Details for the file buildgen-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: buildgen-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 43.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for buildgen-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 54b2ba8c2b95f69c11c27f2b13d93c1eac3e0be638d97cb1166784a7d8f2b19f
MD5 d1e0eb07b5ec6ef6cd51712aca891486
BLAKE2b-256 e7d74ffddcbe25a7647aff9a9d2810d0e134d39794df55db27e33f91f7ae1c1a

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