Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ jobs:
with:
name: ctprintf-packages
path: |
ctprintf/build/release/*.tar.zst
ctprintf/build/release/*.tar.gz
build/debian/
if-no-files-found: error
55 changes: 55 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Release

on:
workflow_dispatch:

jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v7

- name: Install build dependencies
run: ./scripts/build-dependencies.sh

- name: Verify release version
id: version
run: |
if [[ "$GITHUB_REF" != "refs/heads/main" ]]; then
echo "Releases must be run from the main branch."
exit 1
fi

debian_version="$(dpkg-parsechangelog --show-field Version)"
upstream_version="${debian_version%-*}"
tag="v${upstream_version}"

if git ls-remote --exit-code --tags origin "refs/tags/${tag}" >/dev/null; then
echo "Tag ${tag} already exists."
exit 1
fi

echo "upstream_version=${upstream_version}" >>"$GITHUB_OUTPUT"
echo "tag=${tag}" >>"$GITHUB_OUTPUT"

- name: Configure, build, test, and package
working-directory: ctprintf
run: cmake --workflow --fresh --preset release-workflow

- name: Build Debian package
run: ./scripts/build-package.sh

- name: Create GitHub release
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ steps.version.outputs.tag }}
target_commitish: ${{ github.sha }}
name: Release ${{ steps.version.outputs.tag }}
generate_release_notes: true
files: |
ctprintf/build/release/*.tar.gz
build/debian/*.deb
build/debian/*.buildinfo
build/debian/*.changes
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ The library is intended for diagnostic output such as UART, ITM/SWO, log
buffers, or host-side test buffers. It does not use `printf`, iostreams,
`std::string`, or dynamic allocation itself.


[![CI](https://github.com/embtom/ctprintf/actions/workflows/ci-build.yml/badge.svg)](https://github.com/embtom/ctprintf/actions/workflows/ci-build.yml)
[![Latest release](https://img.shields.io/github/v/release/embtom/ctprintf)](https://github.com/embtom/ctprintf/releases)

## Features

- C++20 header-only library
Expand Down Expand Up @@ -143,16 +147,16 @@ ctest --test-dir build --output-on-failure

## Creating a package

CPack creates a Zstandard-compressed tarball containing the installable headers,
CPack creates a gzip-compressed tarball containing the installable headers,
CMake package files, README, and license:

```bash
cpack --config build/CPackConfig.cmake
```

The archive is written to the build directory and is named
`ctprintf-<version>-<system>.tar.zst`, for example
`ctprintf-0.1.0-Linux.tar.zst`.
`ctprintf-<version>-<system>.tar.gz`, for example
`ctprintf-0.1.0-Linux.tar.gz`.

## Installation and CMake integration

Expand Down
25 changes: 20 additions & 5 deletions ctprintf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
cmake_minimum_required(VERSION 3.25)
project(ctprintf VERSION 0.1.0 LANGUAGES CXX)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

include(DebianChangelog)
parse_debian_changelog("${CMAKE_SOURCE_DIR}/../debian/changelog")

project(
ctprintf
VERSION ${DEBIAN_PROJECT_VERSION}
LANGUAGES CXX)

include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

option(ENABLE_TESTING "Build and enable tests" OFF)

Expand Down Expand Up @@ -35,19 +44,25 @@ install(
NAMESPACE ctprintf::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ctprintf)

install(FILES cmake/ctprintf-config.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ctprintf)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/ctprintf-config-version.cmake"
VERSION "${PROJECT_VERSION}"
COMPATIBILITY SameMinorVersion)

install(
FILES ${CMAKE_CURRENT_SOURCE_DIR}/../README.md ${CMAKE_CURRENT_SOURCE_DIR}/../LICENSE
DESTINATION ${CMAKE_INSTALL_DOCDIR})
FILES cmake/ctprintf-config.cmake "${CMAKE_CURRENT_BINARY_DIR}/ctprintf-config-version.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ctprintf)

install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/../README.md ${CMAKE_CURRENT_SOURCE_DIR}/../LICENSE
DESTINATION ${CMAKE_INSTALL_DOCDIR})

if(ENABLE_TESTING)
include(CTest)
enable_testing()
add_subdirectory(tests)
endif() # ENABLE_TESTING

set(CPACK_GENERATOR "TZST")
set(CPACK_GENERATOR "TGZ")
set(CPACK_PACKAGE_CONTACT "Thomas Willetal <t.willetal@googlemail.com>")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Compile-time checked printf-style formatting library")
set(CPACK_PACKAGE_DIRECTORY "${CMAKE_BINARY_DIR}")
Expand Down
66 changes: 66 additions & 0 deletions ctprintf/cmake/DebianChangelog.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# cmake-format: off
# Function: parse_debian_changelog(<changelog_file>)
#----------------------------------------------------
# Description:
# Parses a Debian-style debian/changelog file
# - DEBIAN_PROJECT_NAME : package name
# - DEBIAN_PROJECT_EPOCH : epoch (defaults to 0 if not present)
# - DEBIAN_PROJECT_VERSION : upstream version (e.g. 1.2.3)
# - DEBIAN_PROJECT_REVISION : Debian revision (e.g. -1, -2, etc.)
#
# Format of Debian version:
# [epoch:]upstream_version[-debian_revision]
#
# Example:
# some-prj (0.1.0-1) unstable; urgency=medium
# * Initial release
#
# Produces:
# DEBIAN_PROJECT_NAME = some-prj
# DEBIAN_PROJECT_EPOCH = 0
# DEBIAN_PROJECT_VERSION = 0.1.0
# DEBIAN_PROJECT_REVISION = 1
#
# Reference:
# https://www.debian.org/doc/debian-policy/ch-controlfields.html#version
# cmake-format: on

function(parse_debian_changelog CHANGELOG_FILE)
file(READ "${CHANGELOG_FILE}" changelog)

string(REGEX MATCH "^[a-z]+[a-z0-9+-.]+" project_name "${changelog}")

string(REGEX MATCH
"\\\((([0-9]+):)?(([0-9.]+)([A-Za-z0-9.+~]*))(-(([0-9.]*)([A-Za-z0-9.+~]*)))?\\\)"
_ ${changelog})

set(epoch "${CMAKE_MATCH_2}")
set(version "${CMAKE_MATCH_4}")
set(revision "${CMAKE_MATCH_7}")

# Epoch fallback to 0 if not found
if(NOT epoch)
set(epoch "0")
endif()
if(NOT revision)
set(revision "0")
endif()

set(DEBIAN_PROJECT_EPOCH
"${epoch}"
PARENT_SCOPE)
set(DEBIAN_PROJECT_VERSION
"${version}"
PARENT_SCOPE)
set(DEBIAN_PROJECT_REVISION
"${revision}"
PARENT_SCOPE)
set(DEBIAN_PROJECT_NAME
"${project_name}"
PARENT_SCOPE)

message(STATUS "Set project name to: ${project_name}")
message(STATUS "Set project epoch to: ${epoch}")
message(STATUS "Set project version to: ${version}")
message(STATUS "Set project revision to: ${revision}")
endfunction()
Loading