tree: 46b3670aaa44aa3775fa321d3cd2c06e1793eea7 [search]
  1. cmake/
  2. tests/
  3. CMakeLists.txt
  4. README.md
plugins/sourcelume-cmake-module/README.md

Apache Sourcelume CMake Module (sourcelume-cmake-module)

CMake module for automating generating, validating, and submitting Apache Sourcelume specification records to a Sourcelume Registry for C/C++ projects.

Overview

The sourcelume-cmake-module extracts project metadata (coordinates, project name, version, license, git origin, author/vendor), generates canonical Sourcelume 0.0.1 Provenance Records, validates them against the registry schema, and publishes them to the registry.

Quickstart & Usage

1. In your CMakeLists.txt

Include the module or find package:

cmake_minimum_required(VERSION 3.19)
project(my-cpp-project VERSION 1.0.0 LANGUAGES CXX)

# Include Sourcelume module
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(Sourcelume)

# Enable Sourcelume targets
sourcelume_enable(
    REGISTRY_URL "http://localhost:8082"
    LICENSE "Apache-2.0"
    LICENSE_CATEGORY "open-source"
    LICENSE_NOTE "Apache-2.0 verified C++ project"
    DATASET_IDENTIFIER "sourcelume://datasets/my-cpp-dataset-v1"
    DATASET_NAME "My C++ Example Dataset"
)

Or, after installing the module (cmake -B build && cmake --install build), load it with find_package:

find_package(Sourcelume 0.0.1 REQUIRED)  # add the install prefix to CMAKE_PREFIX_PATH
sourcelume_enable(LICENSE "Apache-2.0")

DRY_RUN, FAIL_ON_ERROR and ALLOW_CONFLICT take TRUE or FALSE (for example DRY_RUN TRUE). A keyword with no value means TRUE; an empty value leaves the option unset.

2. Available CMake Custom Targets

When sourcelume_enable() is configured, the following targets are registered in your build system:

TargetDescription
sourcelume_generate / sourcelume-generateGenerates provenance-record.json spec file from CMake project metadata.
sourcelume_validate / sourcelume-validateValidates the spec against the registry's /records/validate endpoint.
sourcelume_publish / sourcelume-publishSubmits the generated spec to the registry (POST /records).

To execute targets using CMake:

# 1. Configure build directory
cmake -B build

# 2. Generate Provenance Record
cmake --build build --target sourcelume_generate

# 3. Validate against Sourcelume Registry
cmake --build build --target sourcelume_validate

# 4. Publish to Registry
cmake --build build --target sourcelume_publish

3. Building & Testing this Module

To build and run tests for the sourcelume-cmake-module itself:

# Configure with testing enabled
cmake -B build -DBUILD_TESTING=ON

# Generate module provenance record
cmake --build build --target sourcelume_generate

# Execute module test suite
ctest --test-dir build --output-on-failure

4. Dry-Run & Command Line Options

You can pass options via CMake cache flags or environment variables:

# Dry run without network calls
cmake --build build --target sourcelume_publish -- -Dsourcelume.dryRun=true
# Or with environment variable
SOURCELUME_DRY_RUN=1 cmake --build build --target sourcelume_publish

# Override registry endpoint and credentials
SOURCELUME_REGISTRY_URL="https://registry.example.org" \
SOURCELUME_REGISTRY_TOKEN="<token>" \
cmake --build build --target sourcelume_publish

5. Direct Script Execution Mode

You can also run the module standalone via cmake -P:

cmake -DSOURCELUME_ACTION=generate \
      -DSOURCELUME_PROJECT_NAME=my-project \
      -DSOURCELUME_VERSION=1.0.0 \
      -DSOURCELUME_LICENSE=MIT \
      -DSOURCELUME_OUTPUT_FILE=build/sourcelume/provenance-record.json \
      -P cmake/Sourcelume.cmake

Configuration Reference

ParameterEnvironment VariableDefault ValueDescription
REGISTRY_URLSOURCELUME_REGISTRY_URLhttp://localhost:8082URL of the Sourcelume Registry.
USERNAMESOURCELUME_REGISTRY_USERNAME-Registry username for HTTP Basic Auth.
PASSWORDSOURCELUME_REGISTRY_PASSWORD-Registry password for HTTP Basic Auth.
TOKENSOURCELUME_REGISTRY_TOKEN-Bearer token for authentication.
DRY_RUNSOURCELUME_DRY_RUNFALSEIf true, logs payloads without sending to the registry.
FAIL_ON_ERRORSOURCELUME_FAIL_ON_ERRORTRUEIf true, failures abort the build.
OUTPUT_FILESOURCELUME_OUTPUT_FILE${CMAKE_CURRENT_BINARY_DIR}/sourcelume/provenance-record.jsonPath to generated JSON-LD spec.
RECORD_IDSOURCELUME_RECORD_IDurn:sourcelume:cmake:${PROJECT_NAME}:${PROJECT_VERSION}Provenance Record ID.
DATASET_IDENTIFIERSOURCELUME_DATASET_IDENTIFIERsourcelume://cmake/${PROJECT_NAME}Persistent dataset identifier.
DATASET_NAMESOURCELUME_DATASET_NAME${PROJECT_DESCRIPTION} / ${PROJECT_NAME}Dataset title or name.
LICENSESOURCELUME_LICENSEApache-2.0License name, URL, or SPDX IRI.
LICENSE_CATEGORYSOURCELUME_LICENSE_CATEGORYopen-sourceLicense category.
LICENSE_NOTESOURCELUME_LICENSE_NOTE-Note or description regarding dataset licensing.
ORIGINSOURCELUME_ORIGINDerived from git / PROJECT_HOMEPAGE_URLDataset or codebase origin URI.

License

Licensed under the Apache License, Version 2.0.