- integrations
- CMake
- Reference
- Discovery examples
Discovery examples
Two more of the tested projects in examples/, included verbatim; the others are on the examples page.
Project-shipped index snapshot
Section titled “Project-shipped index snapshot”The reproducible-first default: a committed .ocx/ directory freezes every floating-tag resolution in the project, no digests in the CMake code, and the refresh stays a deliberate reviewed step.
cmake_minimum_required(VERSION 3.19)project(ocx_example_frozen_index LANGUAGES NONE)
enable_testing()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../..")include(ocx)
# Fail-fast when the snapshot is missing, and lock the discovered .ocx/# into OCX_INDEX for this directory and below. (Each ocx_package would# also discover it on its own - FIND REQUIRED makes the intent explicit.)ocx_index(FIND REQUIRED)
# Floating tag, no INDEX argument, no digests: resolves frozen from the# committed snapshot (.ocx/ocx.sh/p/jqlang/jq.json).ocx_package(NAME jq PACKAGE ocx.sh/jqlang/jq:latest BINS jq NO_ROOT)
add_test(NAME jq_frozen COMMAND ${OCX_JQ_RUN_JQ} -n -e "1 == 1")
# Deliberate refresh flow: the module composes the command, the caller# decides how it runs - here a build target. Never wired up automatically:# a refresh that runs on its own would paper over drift instead of# surfacing it.ocx_index(UPDATE_COMMAND refresh)add_custom_target(index-update COMMAND ${refresh} COMMAND ${CMAKE_COMMAND} -E echo "index snapshot refreshed - review the diff and commit the result" VERBATIM)Highlights:
ocx_index(FIND REQUIRED)fails fast when the snapshot is missing and locks the discovery result intoOCX_INDEX; eachocx_packagewould also discover.ocx/on its own.ocx_index(UPDATE_COMMAND refresh)composes the refresh command; theindex-updatetarget is this project’s choice of how to run it — never wired up automatically.
Classic discovery (find_package)
Section titled “Classic discovery (find_package)”The find-module entry point for projects that want a system ocx to win: PATH / -DOCX_EXECUTABLE first, pinned bootstrap only as the explicit -DOCX_BOOTSTRAP=ON fallback.
cmake_minimum_required(VERSION 3.15)project(ocx_example_find_package LANGUAGES NONE)
enable_testing()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../..")find_package(ocx REQUIRED)
message(STATUS "example: ocx ${OCX_VERSION_STRING} at ${OCX_EXECUTABLE}")
add_test(NAME ocx_version COMMAND ocx::ocx version)