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

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

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 (194 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.1.tar.gz (30.0 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.1-py3-none-any.whl (38.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: buildgen-0.1.1.tar.gz
  • Upload date:
  • Size: 30.0 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.1.tar.gz
Algorithm Hash digest
SHA256 1f53e21d9b036d2af5db610a323535f00281986685b7a5e930290120a2872c49
MD5 e10ef30afb351295d481ca61878c1694
BLAKE2b-256 98953724f60a21976c7f50082ed7a725bc524556780e3b1c3db936e0bedbfd6d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: buildgen-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 38.0 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1257d2c5c1c8e307a14920a410fbb05fa31577ea8044bc2fcf39bb2c09fe87e0
MD5 8778555451d7fb11260c595dff72cf7c
BLAKE2b-256 c47cbf14c96a9e35f153411118daaa7af0a19e9532a740112a5a5a75745d2bb9

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