[cmake] CPMUtil rewrite of the day number 852 (#4130)

Composite PR for several changes to CPMUtil, most notably:
- https://git.crueter.xyz/CMake/CPMUtil/pulls/19
- https://git.crueter.xyz/CMake/CPMUtil/pulls/22
- https://git.crueter.xyz/CMake/CPMUtil/pulls/24
- https://git.crueter.xyz/CMake/CPMUtil/pulls/25

These contain a lot of changes that generally simplify control flow and improve ease-of-use. Read those descriptions and patchsets for more info.

Signed-off-by: crueter <crueter@eden-emu.dev>
Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4130
Reviewed-by: CamilleLaVey <camillelavey99@gmail.com>
Reviewed-by: MaranBr <maranbr@eden-emu.dev>
This commit is contained in:
crueter 2026-07-06 23:11:39 +02:00
commit 66b073ab8d
No known key found for this signature in database
GPG key ID: 425ACD2D4830EBC6
45 changed files with 2291 additions and 2977 deletions

View file

@ -1,20 +0,0 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 16c6092..9e75548 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,7 +8,14 @@ project(adrenotools LANGUAGES CXX C)
set(GEN_INSTALL_TARGET OFF CACHE BOOL "")
-add_subdirectory(lib/linkernsbypass)
+include(CPM)
+set(CPM_USE_LOCAL_PACKAGES OFF)
+
+CPMAddPackage(
+ NAME linkernsbypass
+ URL "https://github.com/bylaws/liblinkernsbypass/archive/aa3975893d.zip"
+ URL_HASH SHA512=43d3d146facb7ec99d066a9b8990369ab7b9eec0d5f9a67131b0a0744fde0af27d884ca1f2a272cd113718a23356530ed97703c8c0659c4c25948d50c106119e
+)
set(LIB_SOURCES src/bcenabler.cpp
src/driver.cpp

View file

@ -0,0 +1,26 @@
From 52bbc5af6523daa22ad62fe4b84bc8d623d11a53 Mon Sep 17 00:00:00 2001
From: crueter <crueter@eden-emu.dev>
Date: Fri, 26 Jun 2026 01:09:40 -0400
Subject: [PATCH] use cpmfile def for linkernsbypass
---
CMakeLists.txt | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 16c6092..85b242c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,7 +8,8 @@ project(adrenotools LANGUAGES CXX C)
set(GEN_INSTALL_TARGET OFF CACHE BOOL "")
-add_subdirectory(lib/linkernsbypass)
+include(CPMUtil)
+AddJsonPackage(linkernsbypass)
set(LIB_SOURCES src/bcenabler.cpp
src/driver.cpp
--
2.54.0

View file

@ -270,7 +270,7 @@ if (ANDROID AND YUZU_DOWNLOAD_ANDROID_VVL)
set(abi ${CMAKE_ANDROID_ARCH_ABI})
set(vvl_lib_path "${CMAKE_CURRENT_SOURCE_DIR}/src/android/app/src/main/jniLibs/${abi}/")
file(COPY "${VVL_SOURCE_DIR}/${abi}/libVkLayer_khronos_validation.so"
file(COPY "${vulkan-validation-layers_SOURCE_DIR}/${abi}/libVkLayer_khronos_validation.so"
DESTINATION "${vvl_lib_path}")
endif()

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -3,11 +3,10 @@
"hash": "1229f345b014f7ca544dedb4edb3311e41ba736f9aa9a67f88b5f26f3c983288c6bb6cdedcfb0b8a02c63088a37e6a0d7ba97d9c2a4d721b213916327cffe28a",
"min_version": "0.9.1",
"repo": "lioncash/biscuit",
"tag": "v%VERSION%",
"version": "0.19.0"
"version": "v0.19.0"
},
"boost": {
"artifact": "%TAG%-cmake.tar.xz",
"artifact": "%VERSION%-cmake.tar.xz",
"find_args": "CONFIG OPTIONAL_COMPONENTS headers context system fiber filesystem",
"hash": "6ae6e94664fe7f2fb01976b59b276ac5df8085c7503fa829d810fbfe495960cfec44fa2c36e2cb23480bc19c956ed199d4952b02639a00a6c07625d4e7130c2d",
"min_version": "1.57",
@ -16,15 +15,13 @@
"0001-clang-cl.patch"
],
"repo": "boostorg/boost",
"tag": "boost-%VERSION%",
"version": "1.90.0"
"version": "boost-1.90.0"
},
"boost_headers": {
"bundled": true,
"hash": "4ef845775e2277a8104ded6ddf749aa262ce52cf8438042869a048f9a0156dd772fbbcfa74efa1378fecef339b7286f6fe4b4feb5c45d49966b35d08e3e83507",
"repo": "boostorg/headers",
"tag": "boost-%VERSION%",
"version": "1.90.0"
"version": "boost-1.90.0"
},
"catch2": {
"hash": "7eea385d79d88a5690cde131fe7ccda97d5c54ea09d6f515000d7bf07c828809d61c1ac99912c1ee507cf933f61c1c47ecdcc45df7850ffa82714034b0fccf35",
@ -34,8 +31,7 @@
"0001-solaris-isnan-fix.patch"
],
"repo": "catchorg/Catch2",
"tag": "v%VERSION%",
"version": "3.13.0"
"version": "v3.13.0"
},
"cpp-jwt": {
"find_args": "CONFIG",
@ -48,8 +44,7 @@
"0001-fix-missing-decl.patch"
],
"repo": "arun11299/cpp-jwt",
"sha": "7f24eb4c32",
"version": "1.5.1"
"version": "7f24eb4c32"
},
"cubeb": {
"find_args": "CONFIG",
@ -61,31 +56,26 @@
"BUNDLE_SPEEX ON"
],
"repo": "mozilla/cubeb",
"sha": "fa02160712",
"version": "0.0.0"
"version": "fa02160712"
},
"discord-rpc": {
"find_args": "MODULE",
"hash": "8213c43dcb0f7d479f5861091d111ed12fbdec1e62e6d729d65a4bc181d82f48a35d5fd3cd5c291f2393ac7c9681eabc6b76609755f55376284c8a8d67e148f3",
"package": "DiscordRPC",
"repo": "eden-emulator/discord-rpc",
"sha": "0d8b2d6a37",
"version": "3.4.1"
"version": "0d8b2d6a37"
},
"enet": {
"find_args": "MODULE",
"hash": "a0d2fa8c957704dd49e00a726284ac5ca034b50b00d2b20a94fa1bbfbb80841467834bfdc84aa0ed0d6aab894608fd6c86c3b94eee46343f0e6d9c22e391dbf9",
"min_version": "1.3",
"repo": "lsalzman/enet",
"tag": "v%VERSION%",
"version": "1.3.18"
"version": "v1.3.18"
},
"ffmpeg": {
"bundled": true,
"hash": "ed177621176b3961bdcaa339187d3a7688c1c8b060b79c4bb0257cbc67ad7021ae5d5adca5303b45625abbbe3d9aafdd87ce777b8690ac295290d744c875489a",
"repo": "FFmpeg/FFmpeg",
"sha": "c7b5f1537d",
"version": "8.0.1"
"version": "c7b5f1537d"
},
"ffmpeg-ci": {
"ci": true,
@ -99,23 +89,20 @@
"hash": "f0da82c545b01692e9fd30fdfb613dbb8dd9716983dcd0ff19ac2a8d36f74beb5540ef38072fdecc1e34191b3682a8542ecbf3a61ef287dbba0a2679d4e023f2",
"min_version": "8",
"repo": "fmtlib/fmt",
"tag": "%VERSION%",
"version": "12.1.0"
},
"frozen": {
"hash": "b8dfe741c82bc178dfc9749d4ab5a130cee718d9ee7b71d9b547cf5f7f23027ed0152ad250012a8546399fcc1e12187efc68d89d6731256c4d2df7d04eef8d5c",
"package": "frozen",
"repo": "serge-sans-paille/frozen",
"sha": "61dce5ae18",
"version": "1.2.0"
"version": "61dce5ae18"
},
"gamemode": {
"find_args": "MODULE",
"hash": "e87ec14ed3e826d578ebf095c41580069dda603792ba91efa84f45f4571a28f4d91889675055fd6f042d7dc25b0b9443daf70963ae463e38b11bcba95f4c65a9",
"min_version": "1.7",
"repo": "FeralInteractive/gamemode",
"sha": "ce6fe122f3",
"version": "1.8.2"
"version": "ce6fe122f3"
},
"httplib": {
"find_args": "MODULE GLOBAL",
@ -128,23 +115,20 @@
"0001-mingw.patch"
],
"repo": "yhirose/cpp-httplib",
"tag": "v%VERSION%",
"version": "0.46.0"
"version": "v0.46.0"
},
"lagoon": {
"hash": "b9380f99c6effaeccc6d8f81d4942e852c11ad28613df637e155451556ae5826f93765bee57a5c87a9740d2bd1db463ad0f55a947772fe9d57eeabae3efa373e",
"repo": "loongson-community/lagoon",
"tag": "%VERSION%",
"version": "1.0.0"
},
"libadrenotools": {
"hash": "f6526620cb752876edc5ed4c0925d57b873a8218ee09ad10859ee476e9333259784f61c1dcc55a2bcba597352d18aff22cd2e4c1925ec2ae94074e09d7da2265",
"patches": [
"0001-linkerns-cpm.patch"
"0001-use-cpmfile-def-for-linkernsbypass.patch"
],
"repo": "eden-emulator/libadrenotools",
"sha": "8ba23b42d7",
"version": "1.0.0"
"version": "8ba23b42d7"
},
"libusb": {
"find_args": "MODULE",
@ -153,53 +137,52 @@
"0001-netbsd-gettime.patch"
],
"repo": "libusb/libusb",
"tag": "v%VERSION%",
"version": "1.0.29"
"version": "v1.0.29"
},
"linkernsbypass": {
"bundled": "true",
"hash": "bbe3f1f08e2bc7172b36e8f052912cc374289fc9a8e5a39ae7547a0c232de8f57ba24883451896b7a9a5d1be0e4de5c5b0f70c2022eda18d7d5a754847521800",
"repo": "bylaws/liblinkernsbypass",
"version": "aa3975893d"
},
"llvm-mingw": {
"artifact": "clang-rt-builtins.tar.zst",
"git_host": "git.eden-emu.dev",
"hash": "d902392caf94e84f223766e2cc51ca5fab6cae36ab8dc6ef9ef6a683ab1c483bfcfe291ef0bd38ab16a4ecc4078344fa8af72da2f225ab4c378dee23f6186181",
"repo": "eden-emu/llvm-mingw",
"tag": "%VERSION%",
"version": "20250828"
},
"lz4": {
"hash": "35c21a5d9cfb5bbf314a5321d02b36819491d2ee3cf8007030ca09d13ca4dae672247b7aeab553e973093604fc48221cb03dc92197c6efe8fc3746891363fdab",
"name": "lz4",
"repo": "lz4/lz4",
"sha": "ebb370ca83",
"source_subdir": "build/cmake",
"version": "1.10.0"
"version": "ebb370ca83"
},
"moltenvk": {
"artifact": "MoltenVK-macOS.tar",
"bundled": true,
"hash": "5695b36ca5775819a71791557fcb40a4a5ee4495be6b8442e0b666d0c436bec02aae68cc6210183f7a5c986bdbec0e117aecfad5396e496e9c2fd5c89133a347",
"repo": "V380-Ori/Ryujinx.MoltenVK",
"tag": "v%VERSION%-ryujinx",
"version": "1.4.1"
"version": "v1.4.1-ryujinx"
},
"nlohmann": {
"hash": "6cc1e86261f8fac21cc17a33da3b6b3c3cd5c116755651642af3c9e99bb3538fd42c1bd50397a77c8fb6821bc62d90e6b91bcdde77a78f58f2416c62fc53b97d",
"min_version": "3.8",
"package": "nlohmann_json",
"repo": "nlohmann/json",
"tag": "v%VERSION%",
"version": "3.12.0"
"version": "v3.12.0"
},
"oaknut": {
"hash": "9697e80a7d5d9bcb3ce51051a9a24962fb90ca79d215f1f03ae6b58da8ba13a63b5dda1b4dde3d26ac6445029696b8ef2883f4e5a777b342bba01283ed293856",
"min_version": "2.0.1",
"repo": "eden-emulator/oaknut",
"tag": "v%VERSION%",
"version": "2.0.3"
"version": "v2.0.3"
},
"oboe": {
"bundled": true,
"hash": "ce4011afe7345370d4ead3b891cd69a5ef224b129535783586c0ca75051d303ed446e6c7f10bde8da31fff58d6e307f1732a3ffd03b249f9ef1fd48fd4132715",
"repo": "google/oboe",
"tag": "%VERSION%",
"version": "1.10.0"
},
"openssl": {
@ -210,8 +193,7 @@
"0001-add-bundled-cert.patch"
],
"repo": "openssl/openssl",
"tag": "openssl-%VERSION%",
"version": "3.6.2"
"version": "openssl-3.6.2"
},
"openssl-ci": {
"ci": true,
@ -234,7 +216,6 @@
"0004-use-shell-wrapper.patch"
],
"repo": "jimmy-park/openssl-cmake",
"tag": "%VERSION%",
"version": "3.6.2"
},
"opus": {
@ -250,8 +231,7 @@
"0002-no-install.patch"
],
"repo": "xiph/opus",
"sha": "a3f0ec02b3",
"version": "1.5.2"
"version": "a3f0ec02b3"
},
"quazip": {
"hash": "609c240c7f029ac26a37d8fbab51bc16284e05e128b78b9b9c0e95d083538c36047a67d682759ac990e4adb0eeb90f04f1ea7fe2253bbda7e7e3bcce32e53dd8",
@ -264,16 +244,14 @@
],
"package": "QuaZip-Qt6",
"repo": "stachenov/quazip",
"sha": "2e95c9001b",
"version": "1.5"
"version": "2e95c9001b"
},
"sdl3": {
"hash": "df5a323af7ac366661a3c0e887969c72584d232f3cc211419d59b0487b620b6b2859d4549c9e8df002ee489290062e466fcfddf7edc0872a37b1f2845e81c0f3",
"min_version": "3.2.10",
"package": "SDL3",
"repo": "libsdl-org/SDL",
"tag": "release-%VERSION%",
"version": "3.4.8"
"version": "release-3.4.8"
},
"sdl3-ci": {
"ci": true,
@ -288,19 +266,16 @@
"hash": "b937c18a7b6277d77ca7ebfb216af4984810f77af4c32d101b7685369a4bd5eb61406223f82698e167e6311a728d07415ab59639fdf19eff71ad6dc2abfda989",
"package": "SimpleIni",
"repo": "brofield/simpleini",
"tag": "v%VERSION%",
"version": "4.25"
"version": "v4.25"
},
"sirit": {
"artifact": "sirit-source-%VERSION%.tar.zst",
"find_args": "CONFIG",
"hash": "b7cd6885acae3fc8698288d19febba0dd45e4a02a2b6563d2eb995a988d0847046e8d16a5dea7e0bf832b4321bcec134cdbafc553f6ede039e4cf34525c5dce5",
"options": [
"SIRIT_USE_SYSTEM_SPIRV_HEADERS ON"
],
"repo": "eden-emulator/sirit",
"tag": "v%VERSION%",
"version": "1.0.5",
"hash": "10b3ff60bdcad428bb4f54360ff749212333a1d24c0b3ed99e466b1bfcf99d2db6cf596c0f965854a2095dfef9b7ce4e045edb070fa9f76eb3b295ab03a4a293"
"version": "v1.0.5"
},
"sirit-ci": {
"ci": true,
@ -310,13 +285,13 @@
"version": "1.0.5"
},
"spirv-headers": {
"hash": "cae8cd179c9013068876908fecc1d158168310ad6ac250398a41f0f5206ceff6469e2aaeab9c820bce9d1b08950c725c89c46e94b89a692be9805432cf749396",
"hash": "d624371dd455c66a300344c89812598ffe11b5eedba555779f789e85c29dc67317741858c60e0744a1e6755cc0d2759b8659f0674f4cc31479c4cb6fc25ed23b",
"options": [
"SPIRV_WERROR OFF"
],
"package": "SPIRV-Headers",
"repo": "KhronosGroup/SPIRV-Headers",
"sha": "04f10f650d"
"version": "vulkan-sdk-1.4.341.0"
},
"tzdb": {
"artifact": "%VERSION%.tar.gz",
@ -324,7 +299,6 @@
"hash": "cce65a12bf90f4ead43b24a0b95dfad77ac3d9bfbaaf66c55e6701346e7a1e44ca5d2f23f47ee35ee02271eb1082bf1762af207aad9fb236f1c8476812d008ed",
"package": "nx_tzdb",
"repo": "eden-emu/tzdb_to_nx",
"tag": "%VERSION%",
"version": "230326"
},
"unordered-dense": {
@ -336,46 +310,40 @@
"0001-avoid-memset-when-clearing-an-empty-table.patch"
],
"repo": "martinus/unordered_dense",
"sha": "7b55cab841",
"version": "4.8.1"
"version": "7b55cab841"
},
"vulkan-headers": {
"hash": "d2846ea228415772645eea4b52a9efd33e6a563043dd3de059e798be6391a8f0ca089f455ae420ff22574939ed0f48ed7c6ff3d5a9987d5231dbf3b3f89b484b",
"min_version": "1.4.317",
"package": "VulkanHeaders",
"repo": "KhronosGroup/Vulkan-Headers",
"tag": "v%VERSION%",
"version": "1.4.345"
"version": "v1.4.345"
},
"vulkan-memory-allocator": {
"find_args": "CONFIG",
"hash": "deb5902ef8db0e329fbd5f3f4385eb0e26bdd9f14f3a2334823fb3fe18f36bc5d235d620d6e5f6fe3551ec3ea7038638899db8778c09f6d5c278f5ff95c3344b",
"package": "VulkanMemoryAllocator",
"repo": "GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator",
"tag": "v%VERSION%",
"version": "3.3.0"
"version": "v3.3.0"
},
"vulkan-utility-libraries": {
"hash": "114f6b237a6dcba923ccc576befb5dea3f1c9b3a30de7dc741f234a831d1c2d52d8a224afb37dd57dffca67ac0df461eaaab6a5ab5e503b393f91c166680c3e1",
"package": "VulkanUtilityLibraries",
"repo": "KhronosGroup/Vulkan-Utility-Libraries",
"tag": "v%VERSION%",
"version": "1.4.345"
"version": "v1.4.345"
},
"vulkan-validation-layers": {
"artifact": "android-binaries-%VERSION%.zip",
"artifact": "android-binaries-%NUMERIC_VERSION%.zip",
"hash": "8812ae84cbe49e6a3418ade9c458d3be6d74a3dffd319d4502007b564d580998056e8190414368ec11b27bc83993c7a0dad713c31bcc3d9553b51243efee3753",
"package": "VVL",
"numeric_version": "1.4.341.0",
"repo": "KhronosGroup/Vulkan-ValidationLayers",
"tag": "vulkan-sdk-%VERSION%",
"version": "1.4.341.0"
"version": "vulkan-sdk-%NUMERIC_VERSION%"
},
"xbyak": {
"hash": "b6475276b2faaeb315734ea8f4f8bd87ededcee768961b39679bee547e7f3e98884d8b7851e176d861dab30a80a76e6ea302f8c111483607dde969b4797ea95a",
"package": "xbyak",
"repo": "herumi/xbyak",
"tag": "v%VERSION%",
"version": "7.35.2"
"version": "v7.35.2"
},
"zlib": {
"hash": "16fea4df307a68cf0035858abe2fd550250618a97590e202037acd18a666f57afc10f8836cbbd472d54a0e76539d0e558cb26f059d53de52ff90634bbf4f47d4",
@ -386,8 +354,7 @@
],
"package": "ZLIB",
"repo": "madler/zlib",
"tag": "v%VERSION%",
"version": "1.3.2"
"version": "v1.3.2"
},
"zstd": {
"find_args": "MODULE",
@ -397,8 +364,7 @@
"ZSTD_BUILD_SHARED OFF"
],
"repo": "facebook/zstd",
"sha": "b8d6101fba",
"source_subdir": "build/cmake",
"version": "1.5.7"
"version": "b8d6101fba"
}
}

View file

@ -8,6 +8,7 @@ CPMUtil is a wrapper around CPM that aims to reduce boilerplate and add useful u
- [Common Properties](#common-properties)
- [Standard Packages](#standard-packages)
- [Versioning](#versioning)
- [Artifact Naming Errata](#artifact-naming-errata)
- [Patches](#patches)
- [Pre-built CI Packages](#pre-built-ci-packages)
- [Usage](#usage)
@ -22,12 +23,18 @@ CPMUtil is a wrapper around CPM that aims to reduce boilerplate and add useful u
- [Addendum: Module Path Packages](#addendum-module-path-packages)
- [Example: OpenSSL](#example-openssl)
- [Addendum: Adding Qt](#addendum-adding-qt)
- [Addendum: Package-Specific Overrides](#addendum-package-specific-overrides)
- [Addendum: Supply-Chain Security](#addendum-supply-chain-security)
- [Checksumming](#checksumming)
- [Caching](#caching)
- [Immutable Commit Hashes](#immutable-commit-hashes)
## Global Options
- `CPMUTIL_FORCE_SYSTEM` (default `OFF`): Require all CPM dependencies to use system packages. NOT RECOMMENDED!
- You may optionally override this (section)
- `CPMUTIL_FORCE_SYSTEM` (default `OFF`): Require all CPM dependencies to use system packages.
- You may optionally override this for each package: [Package-Specific Overrides](#addendum-package-specific-overrides)
- `CPMUTIL_FORCE_BUNDLED` (default `ON` on MSVC and Android, `OFF` elsewhere): Require all CPM dependencies to use bundled packages.
- You may optionally override this for each package: [Package-Specific Overrides](#addendum-package-specific-overrides)
- `CPMUTIL_PATCH_DIR` (default `${PROJECT_SOURCE_DIR}/.patch`): Path to patches used in packages. Stored as `<PATCH DIR>/json-package-name/0001-patch-name.patch`, etc.
- `CPM_SOURCE_CACHE` (default `${PROJECT_SOURCE_DIR}/.cache/cpm`): Where downloaded dependencies get stored.
@ -50,23 +57,25 @@ And may optionally define other properties like:
For instance:
```json
"fmt": {
"repo": "fmtlib/fmt",
"tag": "12.1.0",
"hash": "f0da82c545b01692e9fd30fdfb613dbb8dd9716983dcd0ff19ac2a8d36f74beb5540ef38072fdecc1e34191b3682a8542ecbf3a61ef287dbba0a2679d4e023f2",
"min_version": "8",
"options": [
"FMT_TEST ON"
],
"patches": [
"0001-disable-reference-copy.patch"
]
{
"fmt": {
"repo": "fmtlib/fmt",
"version": "12.1.0",
"hash": "f0da8...23f2",
"min_version": "8",
"options": [
"FMT_TEST ON"
],
"patches": [
"0001-disable-reference-copy.patch"
]
}
}
```
Calling `AddJsonPackage(fmt)`:
- Searches for a system package named `fmt` of version 8 or higher
- Searches for a system package named `fmt` of version 8 or higher (`find_package(fmt 8)`)
- If found, uses the system package and caches it for future use
- If not found:
- Downloads fmt 12.1.0 from the GitHub Archive into `.cache/cpm/fmt/12.1.0`
@ -85,63 +94,82 @@ These JSON properties are used by standard and CI packages alike.
- `package`: The package name used by `find_package` to check for the existence of a system package.
- If unset, defaults to the JSON key
- `repo`: The Git repository the package is stored in, if applicable.
- `version`: The version of the package to download. This is required.
- `min_version`: The minimum required version of the package, if a system package is desired.
- `version`: The version of the package. This is required.
- Generally, this should be a 10-wide Git commit hash or Git tag.
- Tags must be fully qualified and include prefixes and suffixes, e.g. `boost-1.88.0`
- `git_host`: The Git host the package is stored in, if applicable. Defaults to `github.com`.
## Standard Packages
Normal packages, like the prior `fmt` example, *must* also define:
- `hash`: The SHA512 hash of the downloaded artifact. CPMUtil generally computes this for you.
- A valid version/URL identifier:
- `url`: Download from a raw URL.
- `sha`: A short or fully-qualified Git commit sha. CPMUtil recommends using 10-character wide shas.
- `tag`: A Git tag. See [Versioning](#versioning) for its relation to `version`.
- `artifact`: A GitHub/Forgejo/Gitea release artifact (requires `tag`). See [Versioning](#versioning) for its relation to `tag` and `version`.
- `hash`: The SHA512 hash of the downloaded artifact. CPMUtil generally computes this for you--if not, use `tools/cpmutil.sh package hash <JSON key>`
- `min_version`: The minimum required version of the package, if a system package is desired.
And may optionally define:
- `url`: Download from a raw URL.
- `artifact`: A GitHub/Forgejo/Gitea release artifact. Requires `repo` to be set and valid.
- `numeric_version`: Replaces `%NUMERIC_VERSION%` in artifact and version definitions; see [Artifact Naming Errata](#artifact-naming-errata).
See [Versioning](#versioning) for version/artifact information.
The following are optional to define:
- `source_subdir`: A subdirectory containing the `CMakeLists.txt` to configure a project. Useful for projects like `zstd`.
- `bundled`: Force the usage of a bundled package. Useful for packages where the system package is broken or nonexistent; e.g. including external fragment shaders.
- `bundled`: Force the usage of a bundled package. Useful for packages where the system package is broken or nonexistent; e.g. external fragment shaders or data archives.
- Note that this will conflict with `CPMUTIL_FORCE_SYSTEM`; for this reason, when using non-library archives, it may be best to allow the user to download and extract the archive manually and specify a local directory to it.
- `find_args`: Additional arguments passed to `find_package`, e.g. `MODULE`
- `patches`: Array of in-tree patches to apply to the downloaded source code. See [#Patches](TODO).
- `options`: Array of CMake options to apply before configuring the package, e.g. `"FMT_TEST ON"`.
### Versioning
When using tags or artifacts, it may be cumbersome to repeat the version multiple times; especially if it's constantly changing. For this purpose, `tag` and `artifact` both support basic version text replacement.
When fetching from a Git repository, there are generally three methods of versioning:
`tag` can use `%VERSION%` to have its version replaced with the `version` defined for the package, e.g. for OpenSSL; when downloading, `tag` will evaluate to `openssl-3.6.2`:
- Commit hashes
- Git tags
- Release artifacts
```json
"openssl": {
"repo": "openssl/openssl",
"version": "3.6.2",
"tag": "openssl-%VERSION%"
}
```
When `repo` is set, `version` field can be set to any commitish value, including commit hashes or Git tags. In the case of artifacts, `version` must be a Git tag, and `artifact` must be set to a release artifact attached to that tag. Many repositories intentionally version the filenames of their release artifacts; for this purpose, CPMUtil allows you to implant the version number into the artifact name. To do so, add `%VERSION%` to the artifact name; CPMUtil will then automatically replace `%VERSION%` with the `version` field. This means that when changing versions, you only need to update the version, not the artifact!
`artifact` also supports `%VERSION%` replacement, and can also use `%TAG%` to be replaced by the computed tag. Take this Boost definition:
Take Boost as an example. The artifact for Boost 1.90.0 is `boost-1.90.0-cmake.tar.xz`, and the tag is `boost-1.90.0`. Thus, we can set the artifact to `%VERSION%-cmake.tar.xz`:
```json
"boost": {
"repo": "boostorg/boost",
"tag": "boost-%VERSION%",
"version": "1.90.0"
"version": "boost-1.90.0",
"artifact": "%VERSION%-cmake.tar.xz"
}
```
Boost's artifact for this version is stored in `boost-1.90.0-cmake.tar.xz`. Notice that the computed tag,`boost-1.90.0`, is in the name of the artifact! Thus, `artifact` can be either:
The artifact will then evaluate as `boost-1.90.0-cmake.tar.xz`.
- `boost-%VERSION%-cmake.tar.xz`
- Or, even simpler: `%TAG%-cmake.tar.xz`
### Artifact Naming Errata
Future updates need only change the `version` identifier, and the artifact and tag will automatically be updated!
While `%VERSION%` replacement is generally good enough for well-packaged projects, occasionally there may be some problematic packages. Take, for instance, Vulkan Validation Layers:
- Tag (`version`): `vulkan-sdk-1.4.341.0`
- Artifact: `android-binaries-1.4.341.0.zip`
Attempting to add version replacement to the artifact definition **would not work here!** In this case, you must utilize the `numeric_version` field described earlier; we would set `numeric_version` to `1.4.341.0` and add `%NUMERIC_VERSION%` replacements into our artifact and version fields:
```json
"vulkan-validation-layers": {
"artifact": "android-binaries-%NUMERIC_VERSION%.zip",
"repo": "KhronosGroup/Vulkan-ValidationLayers",
"version": "vulkan-sdk-%NUMERIC_VERSION%",
"numeric_version": "1.4.341.0"
},
```
`artifact` will thus evaluate to `android-binaries-1.4.341.0.zip`, and `version` to `vulkan-sdk-1.4.341.0`. CPMUtil's auto-updater will also account for this and only update `numeric_version`!
### Patches
CPMUtil is able to apply in-place source tree patches to downloaded packages. These are defined in JSON as an array of names, preferably using `git-format-patch`'s scheme of `<4 digit number>-patch-name.patch`. These are stored in `<CPMUTIL_PATCH_DIR>/<json-key>` (remember that `CPMUTIL_PATCH_DIR` defaults to `$ROOT/.patch`); e.g. `boost` patches would be in `.patch/boost`. Let's say we've made three patches and want to add them; in the Boost JSON definition, we would add:
CPMUtil is able to apply in-place source tree patches to downloaded packages. These are defined in JSON as an array of names, preferably using `git-format-patch`'s scheme of `<4 digit number>-patch-name.patch`.
They are stored in `<CPMUTIL_PATCH_DIR>/<json-key>` (remember that `CPMUTIL_PATCH_DIR` defaults to `$ROOT/.patch`); e.g. `boost` patches would be in `.patch/boost`. Let's say we've made three patches and want to add them; in the Boost JSON definition, we would add:
```json
"patches": [
@ -151,7 +179,7 @@ CPMUtil is able to apply in-place source tree patches to downloaded packages. Th
]
```
Then, when Boost is downloaded, it will apply these patches in order to the source tree.
Then, when Boost is downloaded, it will apply these patches to the source tree in the order they are defined (compound/dependent patches are okay!). Note that when you add, remove, or modify patches, CPMUtil will invalidate your downloaded cache and re-fetch the source.
To learn how to make patches, see [Addendum: Making Patches](#addendum-making-patches).
@ -199,12 +227,9 @@ If you're only concerned with basic usage, you can stop reading. For more advanc
CPMUtil stores downloaded packages within `.cache/cpm` by default (see `CPM_SOURCE_CACHE`). Subdirectories stored within are lowercase representations of the `find_package` name for the package; for instance, a `vulkan-headers` definition with `package: "VulkanHeaders"` would be stored in `.cache/cpm/vulkanheaders`.
Within these subdirectories, additional directories are created for each individual version:
Within these subdirectories, additional directories are created for each individual version, corresponding directly to their `version` field. CI packages use `<platform>-<architecture>-<version>` unconditionally.
- A four-character shorthand of `sha`, if defined
- If `sha` is not defined, the fully qualified `version` is used
CI packages use `<platform>-<architecture>-<version>` unconditionally.
To see the cache directory for a given package, use `tools/cpmutil.sh package dir <JSON key>`.
## Addendum: Making Patches
@ -242,7 +267,7 @@ If you are packaging a project that uses CPMUtil, read this!
For sandboxed environments (e.g. Gentoo, nixOS) you must install all dependencies to the system beforehand and set `-DCPMUTIL_FORCE_SYSTEM=ON`. If a dependency is missing, get creating!
Alternatively, if CPMUtil pulls in a package that has no suitable way to install or use a system version, download it separately and pass `-DPackageName_DIR=/path/to/downloaded/dir` (e.g. shaders)
Alternatively, if CPMUtil pulls in a package that has no suitable way to install or use a system version, download it separately and pass `-D<PackageName>_CUSTOM_DIR=/path/to/downloaded/dir`.
### Unsandboxed
@ -263,14 +288,12 @@ Using the prior Vulkan example:
"repo": "KhronosGroup/Vulkan-Headers",
"package": "VulkanHeaders",
"min_version": "1.4.317",
"version": "1.4.342",
"tag": "v%VERSION%"
"version": "v1.4.342"
},
"vulkan-utility-libraries": {
"repo": "KhronosGroup/Vulkan-Utility-Libraries",
"package": "VulkanUtilityLibraries",
"version": "1.4.342",
"tag": "v%VERSION%"
"version": "v1.4.342"
}
```
@ -318,3 +341,32 @@ AddQt(QDash-CI/Qt 6.11.1)
```
Then, call `find_package(Qt6 ...)` and it will pull Qt from your downloaded source.
## Addendum: Package-Specific Overrides
There are three variables that CPMUtil defines for each package; these can be overriden by the user or in your CMake. `package` refers either to the `package` value in the JSON, or the package's JSON key if unset (see `package` in [Common Properties](#common-properties)):
- `<package>_FORCE_BUNDLED`: Forcefully bundle the package. This has the same effect as `CPMUTIL_FORCE_BUNDLED`, but only for this package.
- `<package>_FORCE_BUNDLED`: Forcefully use the system package, failing if it can't be found. This has the same effect as `SYSTEM`, but only for this package.
- `<package>_CUSTOM_DIR`: Path to an extracted copy of the package. CPMUtil will not attempt to download the package and will instead use the custom directory.
- For an example, see [CPMUtil's test case](https://git.crueter.xyz/CMake/CPMUtil/src/branch/master/tests/dir/CMakeLists.txt)
Additionally, in CMake, you can add `FORCE_BUNDLED_PACKAGE ON` to your `AddJsonPackage` command--note that you will have to use the `NAME <key>` syntax as described in [Module Path Packages](#addendum-module-path-packages). This will overrule *all* other overrides, including `CPMUTIL_FORCE_SYSTEM` and `<package>_FORCE_SYSTEM`--use with caution!
## Addendum: Supply-Chain Security
Many package managers suffer from the issue of supply chain security, specifically in regards to silent overwrites of existing packages or archives, e.g. tag sliding and artifact overwriting. CPMUtil has three methods to protect against this.
### Checksumming
CPMUtil *requires* SHA512 checksums for standard packages, and soon will for CI packages as well. If an attacker or compromised account slides a tag, overwrites a release artifact, or otherwise attempts to compromise anything that CPMUtil may fetch, **CPMUtil will not allow the download to continue!** This means that consumers of your build system can **only** download an artifact if the contents of the artifact are *exactly* indentical to what it was when it was configured--any changes at all will be rejected by CPMUtil.
### Caching
CPMUtil uses a mutable cache system, stored by default in `.cache/cpm`. Dependencies are downloaded and extracted here, and can be reused infinitely. This means that, for instance, if a package is compromised but you already have a cached local copy, you won't have to worry at all!
### Immutable Commit Hashes
CPMUtil is capable of using immutable Git commit hashes for its artifacts. These are (barring SHA1 collisions) completely immune to supply chain attacks--that is, unless the entire root server gets compromised to serve infected artifacts/source code; at which point there are much larger issues to worry about. This means that once you set a package to use a Git commit hash for its version, **it will stay the same forever**. This is useful if you want to ensure that consumers are never faced with download failures stemming from hash mismatches in case of compromised artifacts.
Do note, however, that this will render the package incompatible with CPMUtil's built-in auto-updater, so you will have to manually update the package.

3
tools/cpm/cmake/README.md Executable file
View file

@ -0,0 +1,3 @@
# CPMUtil CMake Test Scripts
Testing out some CMake scripting functionality.

341
tools/cpm/cmake/ScriptUtils.cmake Executable file
View file

@ -0,0 +1,341 @@
#!/usr/bin/env -S cmake -P
# SPDX-FileCopyrightText: Copyright 2026 crueter
# SPDX-License-Identifier: LGPL-3.0-or-later
cmake_minimum_required(VERSION 3.31)
# TODO: Account for CPMConfig.cmake
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR})
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMakeModules)
set(CPMUTIL_ROOT ${CMAKE_SOURCE_DIR})
include(CPMUtil)
# Parse the JSON object for a given key.
macro(parse_key key)
get_json_object(${key})
set(JSON_NAME ${key})
parse_object(${object})
endmacro()
# Get a package's effective URL, for an already parsed object
function(get_package_url_object out)
if (${url})
set(${out} "${url}")
else()
get_package_url(URL_OUT "${out}"
GIT_HOST "${git_host}"
REPO "${repo}"
VERSION "${version}"
ARTIFACT "${artifact}"
PACKAGE "${package}")
endif()
return(PROPAGATE ${out})
endfunction()
# Fetch a package from an already-parsed object.
function(fetch_package_object)
set(optionArgs FORCE)
cmake_parse_arguments(ARG "${optionArgs}" "" "" ${ARGN})
if (${url})
set(pkg_url "${url}")
else()
get_package_url(URL_OUT pkg_url
GIT_HOST "${git_host}"
REPO "${repo}"
VERSION "${version}"
ARTIFACT "${artifact}"
PACKAGE "${package}")
endif()
if (DEFINED CACHE_PATH_OVERRIDE)
set(cache_path ${CACHE_PATH_OVERRIDE})
else()
get_cache_path(${package} ${version} cache_path)
endif()
set(fetch_args
URL "${pkg_url}"
HASH "${hash}"
PATH "${cache_path}"
PATCHES ${patches})
if(ARG_FORCE)
list(APPEND fetch_args FORCE)
endif()
fetch_package(${fetch_args})
endfunction()
# Format the cpmfile. Requires one of: jq, python, perl
# If you don't have any of those, sorry not sorry.
# Maybe I should make a shell-based alternative.
function(format_cpmfile)
# jq is the preferred formatter since it's the fastest
cpm_find_program(JQ_EXECUTABLE jq)
if (JQ_EXECUTABLE)
set(command ${JQ_EXECUTABLE} --indent 4 -S .)
else()
# Python is simple and works
find_package(Python 3.5 COMPONENTS Interpreter QUIET)
if (Python_FOUND)
set(command ${Python_EXECUTABLE} -m json.tool
--indent 4 --sort-keys)
else()
# json_pp (part of perl) also works well
cpm_find_program(JSONPP_EXECUTABLE json_pp)
if (JSONPP_EXECUTABLE)
set(json_opts "indent" "indent_length=4" "canonical"
"space_after=1" "space_before=0")
string(JOIN "," json_opts_str ${json_opts})
set(command ${JSONPP_EXECUTABLE} -f json -t json -json_opt
"${json_opts_str}")
else()
fatal("Fatal: could not find one of jq, Python, or perl"
"(json_pp). Install one of these packages to use"
"CPMUtil's tooling. If they ARE installed, your"
"CMake installation is broken.")
endif()
endif()
endif()
get_cpmfile_path(file)
mktempdir(TMP)
set(tmp_file ${TMP}/cpmfile.json)
execute_process(COMMAND ${command}
INPUT_FILE ${file}
OUTPUT_FILE ${tmp_file})
# TODO: error handling, mv, cp?
file(COPY_FILE ${tmp_file} ${file})
file(REMOVE_RECURSE ${TMP})
endfunction()
# Computes expected SHA512 hash of a package
function(get_package_hash url out)
mktempdir(TMP)
get_filename_component(filename ${url} NAME)
set(file ${TMP}/${filename})
cpm_download("${url}" "${file}")
file(SHA512 ${file} ${out})
file(REMOVE_RECURSE ${TMP})
return(PROPAGATE ${out})
endfunction()
# Download and put the content into a variable.
function(cpm_download_var url out)
mktempdir(TMP)
set(file ${TMP}/tmp)
cpm_download("${url}" "${file}")
file(READ ${file} ${out})
file(REMOVE_RECURSE ${TMP})
return(PROPAGATE ${out})
endfunction()
# Check if a URL request succeeds without actually saving anything
function(cpm_url_exists url out)
foreach(i RANGE 5)
file(DOWNLOAD "${url}" STATUS ret LOG log TIMEOUT 10)
list(GET ret 0 code)
if (code EQUAL 0)
set(${out} TRUE)
break()
else()
if (log MATCHES "HTTP/[0-9.]+ (429|403)")
sleep(5)
continue()
endif()
set(${out} FALSE)
break()
endif()
endforeach()
return(PROPAGATE ${out})
endfunction()
# Get latest tag for a package.
# Requires an already-parsed object
function(get_latest_tag out)
# TODO: Ci packages
if (NOT repo OR ci)
set(${out} null)
return(PROPAGATE ${out})
endif()
# first determine if this is a tag or not
if (git_host STREQUAL github.com)
set(api "https://api.github.com/repos/${repo}")
set(check_endpoint "/git/refs/tags")
else()
set(api "https://${git_host}/api/v1/repos/${repo}")
set(check_endpoint "/tags")
endif()
# artifacts must only check releases
if ("${artifact}" STREQUAL "")
set(json_key name)
set(endpoint "/tags")
else()
set(json_key tag_name)
set(endpoint "/releases")
set(check_endpoint "/releases/tags")
endif()
cpm_url_exists("${api}${check_endpoint}/${version}" is_tag)
if (NOT is_tag)
set(${out} null)
return(PROPAGATE ${out})
endif()
# strip out prefixes e.g. boost-, openssl-, v
# NOTE: subrels e.g. -1 at the end may cause issues.
string(REGEX REPLACE "[^0-9.-]" "" t_numeric_version "${version}")
string(REGEX REPLACE "-$|^-" "" t_numeric_version "${numeric_version}")
# now api req
cpm_download_var("${api}${endpoint}" tags)
string(JSON len LENGTH ${tags})
math(EXPR last_index "${len} - 1")
set(greatest_version_numeric ${t_numeric_version})
set(greatest_version ${version})
foreach(i RANGE ${last_index})
string(JSON tag_obj GET "${tags}" ${i})
string(JSON tag_name GET "${tag_obj}" ${json_key})
# same as above
string(REGEX REPLACE "[^0-9.-]" "" numeric_tag "${tag_name}")
string(REGEX REPLACE "-$|^-" "" numeric_tag "${numeric_tag}")
if (numeric_tag VERSION_GREATER_EQUAL greatest_version_numeric)
set(greatest_version_numeric ${numeric_tag})
set(greatest_version ${tag_name})
endif()
endforeach()
# numeric version replacement
if (numeric_version)
set(${out} ${greatest_version_numeric})
else()
set(${out} ${greatest_version})
endif()
return(PROPAGATE ${out})
endfunction()
# TODO(crueter): Combine these
# Update hash and version of a package
# Outputs the updated object
function(modify_package object version hash out)
string(JSON new_object SET "${object}" hash "\"${hash}\"")
string(JSON new_object SET "${new_object}" version "\"${version}\"")
set(${out} "${new_object}")
return(PROPAGATE ${out})
endfunction()
# Update hash and numeric_version of a package
# Outputs the updated object
function(modify_package_numeric object version hash out)
string(JSON new_object SET "${object}" hash "\"${hash}\"")
string(JSON new_object SET "${new_object}" numeric_version "\"${version}\"")
set(${out} "${new_object}")
return(PROPAGATE ${out})
endfunction()
function(get_cpmfile_keys out)
get_cpmfile_content(object)
string(JSON len LENGTH ${object})
math(EXPR last_index "${len} - 1")
foreach(i RANGE ${last_index})
string(JSON key MEMBER ${object} ${i})
list(APPEND ${out} ${key})
endforeach()
return(PROPAGATE ${out})
endfunction()
function(parse_script_args out)
if(PRINT_USAGE)
usage()
cmake_language(EXIT 0)
endif()
if(NOT CMAKE_SCRIPT_MODE_FILE OR NOT CMAKE_ARGC)
set(${out} "" PARENT_SCOPE)
return()
endif()
set(found_script FALSE)
set(idx 0)
get_filename_component(script_name "${CMAKE_SCRIPT_MODE_FILE}" NAME)
while(idx LESS CMAKE_ARGC)
if(found_script)
set(arg "${CMAKE_ARGV${idx}}")
if(NOT arg STREQUAL "--")
list(APPEND positional_args ${arg})
endif()
elseif(CMAKE_ARGV${idx} STREQUAL CMAKE_SCRIPT_MODE_FILE)
set(found_script TRUE)
else()
get_filename_component(arg_name "${CMAKE_ARGV${idx}}" NAME)
if(arg_name STREQUAL script_name)
set(found_script TRUE)
endif()
endif()
math(EXPR idx "${idx} + 1")
endwhile()
if(ALL_PACKAGES AND NOT NO_ALL)
get_cpmfile_keys(all_keys)
if(NO_CI)
set(filtered_keys)
foreach(key ${all_keys})
parse_key(${key})
if(NOT ci)
list(APPEND filtered_keys ${key})
endif()
endforeach()
set(positional_args ${filtered_keys})
else()
set(positional_args ${all_keys})
endif()
endif()
set(${out} ${positional_args} PARENT_SCOPE)
endfunction()
# Convert a CMake list to a JSON array
function(list_to_array list out)
set(${out} "[]")
set(idx 0)
foreach(elem ${list})
string(JSON ${out} SET ${${out}} "${idx}" "\"${elem}\"")
math(EXPR idx "${idx} + 1")
endforeach()
return(PROPAGATE ${out})
endfunction()

11
tools/cpm/cmake/format.cmake Executable file
View file

@ -0,0 +1,11 @@
#!/usr/bin/env -S cmake -P
# SPDX-FileCopyrightText: Copyright 2026 crueter
# SPDX-License-Identifier: LGPL-3.0-or-later
cmake_minimum_required(VERSION 3.31)
include(${CMAKE_CURRENT_LIST_DIR}/ScriptUtils.cmake)
# TODO: Run some sanity checks e.g. patches exist, etc.
format_cpmfile()

24
tools/cpm/cmake/ls.cmake Executable file
View file

@ -0,0 +1,24 @@
#!/usr/bin/env -S cmake -P
# SPDX-FileCopyrightText: Copyright 2026 crueter
# SPDX-License-Identifier: LGPL-3.0-or-later
cmake_minimum_required(VERSION 3.31)
include(${CMAKE_CURRENT_LIST_DIR}/ScriptUtils.cmake)
set(NO_ALL TRUE)
function(usage)
echo([=[
Usage: cpmutil.sh ls
List all packages in the cpmfile.
]=])
endfunction()
get_cpmfile_keys(keys)
foreach(key ${keys})
echo("${key}")
endforeach()

View file

@ -0,0 +1,104 @@
#!/usr/bin/env -S cmake -P
# SPDX-FileCopyrightText: Copyright 2026 crueter
# SPDX-License-Identifier: LGPL-3.0-or-later
cmake_minimum_required(VERSION 3.31)
include(${CMAKE_CURRENT_LIST_DIR}/../ScriptUtils.cmake)
function(usage)
echo([=[
Usage: add.cmake [OPTIONS...]
Internal use only.
]=])
endfunction()
if (NOT DEFINED KEY)
fatal("KEY is required")
endif()
if (NOT DEFINED REPO)
fatal("REPO is required")
endif()
if (NOT DEFINED VERSION)
fatal("VERSION is required")
endif()
if (NOT DEFINED CI)
set(CI FALSE)
endif()
# construct json
set(object "{}")
macro(add key val)
set(${key} ${val})
string(JSON object SET ${object} ${key} "\"${val}\"")
endmacro()
add(repo ${REPO})
add(version ${VERSION})
if (DEFINED GIT_HOST AND NOT "${GIT_HOST}" STREQUAL github.com)
add(git_host ${GIT_HOST})
else()
set(git_host github.com)
endif()
if (DEFINED PACKAGE)
add(package ${PACKAGE})
else()
set(package ${KEY})
endif()
if (DEFINED FIND_ARGS)
add(find_args "${FIND_ARGS}")
endif()
if (DEFINED MIN_VERSION)
add(min_version ${MIN_VERSION})
endif()
if (DEFINED ARTIFACT)
add(artifact ${ARTIFACT})
endif()
if (CI)
add(ci true)
if (DEFINED DISABLED_PLATFORMS)
list_to_array(${DISABLED_PLATFORMS} json_disabled)
string(JSON object SET "${object}" disabled_platforms "${json_disabled}")
endif()
else()
if (DEFINED OPTIONS)
list_to_array(${OPTIONS} json_options)
string(JSON object SET "${object}" options "${json_options}")
endif()
# get hash
get_package_url_object(pkg_url)
get_package_hash("${pkg_url}" pkg_hash)
add(hash ${pkg_hash})
endif()
echo("\"${KEY}\": ${object}")
# now write
get_cpmfile_content(cpmfile)
# update cached cpmfile content
string(JSON cpmfile SET "${cpmfile}" "${KEY}" "${object}")
# write cached cpmfile
get_cpmfile_path(file)
file(WRITE ${file} "${cpmfile}")
format_cpmfile()
echo("-- Added ${KEY}")

View file

@ -0,0 +1,33 @@
#!/usr/bin/env -S cmake -P
# SPDX-FileCopyrightText: Copyright 2026 crueter
# SPDX-License-Identifier: LGPL-3.0-or-later
cmake_minimum_required(VERSION 3.31)
include(${CMAKE_CURRENT_LIST_DIR}/../ScriptUtils.cmake)
function(usage)
echo([=[
Usage: cpmutil.sh package dir [-a|--all] [PACKAGE]...
Get the local directory for the specified packages.
Options:
-a, --all Operate on all packages in this project.
]=])
endfunction()
parse_script_args(args)
# TODO: CI packages.
foreach(key ${args})
parse_key(${key})
# Guh.
get_cache_path(${package} ${version} cache_path)
cmake_path(ABSOLUTE_PATH cache_path NORMALIZE OUTPUT_VARIABLE abs_path)
echo("${key}: ${abs_path}")
endforeach()

View file

@ -0,0 +1,34 @@
#!/usr/bin/env -S cmake -P
# SPDX-FileCopyrightText: Copyright 2026 crueter
# SPDX-License-Identifier: LGPL-3.0-or-later
cmake_minimum_required(VERSION 3.31)
include(${CMAKE_CURRENT_LIST_DIR}/../ScriptUtils.cmake)
function(usage)
echo([=[
Usage: cpmutil.sh package fetch [-a|--all] [PACKAGE]...
Fetch the specified package or packages from their defined download locations.
If the package is already cached, it will not be re-fetched.
Options:
-a, --all Operate on all packages in this project.
]=])
endfunction()
set(NO_CI TRUE)
parse_script_args(args)
foreach(key ${args})
if (ci)
continue()
endif()
parse_key(${key})
echo("-- ${key}")
fetch_package_object()
endforeach()

View file

@ -0,0 +1,59 @@
#!/usr/bin/env -S cmake -P
# SPDX-FileCopyrightText: Copyright 2026 crueter
# SPDX-License-Identifier: LGPL-3.0-or-later
cmake_minimum_required(VERSION 3.31)
include(${CMAKE_CURRENT_LIST_DIR}/../ScriptUtils.cmake)
function(usage)
echo([=[
Usage: cpmutil.sh package hash [-a|--all] [PACKAGE]...
Check the hash of a specific package or packages.
If a hash mismatch occurs, this script will update the package's hash.
Options:
-a, --all Operate on all packages in this project.
Note that this procedure will usually take a long time
depending on the number and size of dependencies.
]=])
endfunction()
set(NO_CI TRUE)
parse_script_args(args)
get_cpmfile_content(cpmfile)
foreach(key ${args})
if (ci)
continue()
endif()
parse_key("${key}")
echo("-- ${key}")
get_package_url_object(pkg_url)
get_package_hash("${pkg_url}" pkg_hash)
if (pkg_hash STREQUAL hash)
echo("Hashes match")
else()
echo_error("Hash mismatch")
echo_error("Expected: ${hash}")
echo_error("Got: ${pkg_hash}")
modify_package("${object}" "${version}" "${pkg_hash}" new_object)
# update cached cpmfile content
string(JSON cpmfile SET "${cpmfile}" "${key}" "${new_object}")
echo("Corrected hash for ${key}")
endif()
endforeach()
# write cached cpmfile
get_cpmfile_path(file)
file(WRITE ${file} "${cpmfile}")
format_cpmfile()

View file

@ -0,0 +1,155 @@
#!/usr/bin/env -S cmake -P
# SPDX-FileCopyrightText: Copyright 2026 crueter
# SPDX-License-Identifier: LGPL-3.0-or-later
cmake_minimum_required(VERSION 3.31)
include(${CMAKE_CURRENT_LIST_DIR}/../ScriptUtils.cmake)
function(usage)
echo([=[
Usage: cpmutil.sh package patch [PACKAGE]
Create an in-tree patch for the specified package.
]=])
endfunction()
set(NO_ALL TRUE)
# arg parsing
parse_script_args(args)
list(LENGTH args arg_len)
if(arg_len GREATER 0)
list(GET args 0 KEY)
endif()
if (NOT KEY)
fatal("You must provide a key")
endif()
if (NOT DEFINED DESCRIPTION)
fatal("No description provided")
endif()
parse_key(${KEY})
get_cache_path(${package} ${version} local_cache)
if (NOT EXISTS ${local_cache})
fatal("${package} is not fetched locally")
endif()
# get last patch number + 1
list(LENGTH patches patches_len)
math(EXPR last_index "${patches_len} - 1")
list(GET patches ${last_index} patch)
string(REGEX MATCH "[0-9][0-9][0-9][0-9]" number "${patch}")
math(EXPR new_patchnum "${number} + 1")
# now pad it for filename usage
set(padded "0000${new_patchnum}")
string(LENGTH ${padded} total_len)
math(EXPR start_index "${total_len} - 4")
string(SUBSTRING ${padded} ${start_index} 4 padded_patch_number)
# this requires Git
find_package(Git REQUIRED)
# fetch temporary package
mktempdir(TMP)
set(CACHE_PATH_OVERRIDE ${TMP}/local)
fetch_package_object()
# make patch dir
set(patch_dir "${CPMUTIL_PATCH_DIR}/${KEY}")
file(MAKE_DIRECTORY "${patch_dir}")
# git stuff
macro(git_cmd out out_status)
echo("${GIT_EXECUTABLE} ${ARGN}")
# TODO: error handling
execute_process(COMMAND ${GIT_EXECUTABLE} ${ARGN}
WORKING_DIRECTORY ${CACHE_PATH_OVERRIDE}
OUTPUT_VARIABLE ${out}
RESULT_VARIABLE ${out_status})
endmacro()
# initialize
git_cmd(_ _ init)
git_cmd(_ _ add -A)
git_cmd(_ _ commit -m init)
git_cmd(_ _ "--work-tree=${local_cache}" add -A)
# check for diffs
git_cmd(_ diff_status diff --cached --quiet)
git_cmd(out _ diff)
if (diff_status EQUAL 0)
echo(${out})
echo_error("No differences found between local copy and source")
file(REMOVE_RECURSE ${TMP})
cmake_language(EXIT 1)
endif()
# prompt for patch description
git_cmd(_ commit_status commit -m "${DESCRIPTION}")
# format patch
git_cmd(patch_content _ format-patch -1 HEAD --stdout)
# now get patch name...
# strip out existing numeric prefix
string(REGEX REPLACE "^[0-9][0-9][0-9][0-9]-" "" name_part "${DESCRIPTION}")
# spaces to dashes
string(REPLACE " " "-" name_part "${name_part}")
# strip out non-alphanumeric or dash characters
string(REGEX REPLACE "[^a-zA-Z0-9-]" "" name_part "${name_part}")
# collapse consecutive dashes
string(REGEX REPLACE "-+" "-" name_part "${name_part}")
# strip leading/trailing dashes
string(REGEX REPLACE "^-|-$" "" name_part "${name_part}")
if (NOT name_part)
set(name_part "patch")
echo_error("Warning: could not determine patch name")
endif()
# Truncate to 49 chars (60 - num prefix - `.patch` suffix)
string(SUBSTRING "${name_part}" 0 49 name_part)
# And remove any trailing dashes
string(REGEX REPLACE "-$" "" name_part "${name_part}")
# now construct and save patch
set(patch_name "${padded_patch_number}-${name_part}.patch")
file(WRITE "${patch_dir}/${patch_name}" "${patch_content}")
echo("-- Patch created at ${patch_dir}/${patch_name}")
file(REMOVE_RECURSE ${TMP})
# Now add to cpmfile.
get_cpmfile_content(content)
# Build new patches JSON array
set(new_patches "[")
if(patches)
string(JSON existing GET "${content}" "${KEY}" "patches")
string(JSON len LENGTH "${existing}")
math(EXPR range_end "${len} - 1")
foreach(idx RANGE ${range_end})
string(JSON val GET "${existing}" ${idx})
string(APPEND new_patches "\"${val}\",")
endforeach()
endif()
string(APPEND new_patches "\"${patch_name}\"]")
# Update the cpmfile
string(JSON content SET "${content}" "${KEY}" patches "${new_patches}")
get_cpmfile_path(file_path)
file(WRITE "${file_path}" "${content}")
format_cpmfile()

View file

@ -0,0 +1,34 @@
#!/usr/bin/env -S cmake -P
# SPDX-FileCopyrightText: Copyright 2026 crueter
# SPDX-License-Identifier: LGPL-3.0-or-later
cmake_minimum_required(VERSION 3.31)
include(${CMAKE_CURRENT_LIST_DIR}/../ScriptUtils.cmake)
function(usage)
echo([=[
Usage: cpmutil.sh package reset [-a|--all] [PACKAGE]...
Reset a locally fetched package to its original state.
This is most useful for dropping any changes you've made.
Options:
-a, --all Operate on all packages in this project.
]=])
endfunction()
set(NO_CI TRUE)
parse_script_args(args)
foreach(key ${args})
if (ci)
continue()
endif()
parse_key(${key})
echo("-- ${key}")
fetch_package_object(FORCE)
endforeach()

View file

@ -0,0 +1,31 @@
#!/usr/bin/env -S cmake -P
# SPDX-FileCopyrightText: Copyright 2026 crueter
# SPDX-License-Identifier: LGPL-3.0-or-later
cmake_minimum_required(VERSION 3.31)
include(${CMAKE_CURRENT_LIST_DIR}/../ScriptUtils.cmake)
function(usage)
echo([=[
Usage: cpmutil.sh package rm [PACKAGE]...
Delete a package or packages' cpmfile definition.
]=])
endfunction()
set(NO_ALL TRUE)
parse_script_args(args)
get_cpmfile_content(object)
# Remove key
foreach(key ${args})
string(JSON object REMOVE "${object}" ${key})
endforeach()
# write
get_cpmfile_path(file)
file(WRITE ${file} "${object}")
format_cpmfile()

View file

@ -0,0 +1,97 @@
#!/usr/bin/env -S cmake -P
# SPDX-FileCopyrightText: Copyright 2026 crueter
# SPDX-License-Identifier: LGPL-3.0-or-later
cmake_minimum_required(VERSION 3.31)
include(${CMAKE_CURRENT_LIST_DIR}/../ScriptUtils.cmake)
function(usage)
echo([=[
Usage: cpmutil.sh package update [-a|--all] [-c|--commit] [PACKAGE]...
Check for updates for a package or packages.
Options:
-a, --all Operate on all packages in this project.
-c, --commit Automatically generate a commit message
]=])
endfunction()
set(NO_CI TRUE)
parse_script_args(args)
get_cpmfile_content(cpmfile)
set(update_log "")
set(changed FALSE)
foreach(key ${args})
parse_key(${key})
get_latest_tag(tag)
if (${tag} STREQUAL null)
continue()
elseif(NOT ${tag} STREQUAL ${version})
if (numeric_version)
set(old_version ${numeric_version})
echo("${key}: ${old_version} -> ${tag}")
set(numeric_version ${tag})
get_json_element("${object}" version version)
else()
set(old_version ${version})
echo("${key}: ${old_version} -> ${tag}")
set(version ${tag})
endif()
get_json_element("${object}" artifact artifact)
# Redo version replacements
process_version_replacements()
get_package_url_object(pkg_url)
get_package_hash("${pkg_url}" pkg_hash)
if (numeric_version)
modify_package_numeric("${object}"
"${tag}" "${pkg_hash}" new_object)
else()
modify_package("${object}" "${tag}" "${pkg_hash}" new_object)
endif()
# update cached cpmfile content
string(JSON cpmfile SET "${cpmfile}" "${key}" "${new_object}")
# used for commit
string(APPEND update_log "* ${key}: ${old_version} -> ${tag}\n")
set(changed TRUE)
else()
echo("${key}: Up to date")
endif()
endforeach()
get_cpmfile_path(file)
file(WRITE ${file} "${cpmfile}")
format_cpmfile()
if(MAKE_COMMIT AND changed)
mktempdir(TMP)
find_package(Git QUIET)
if (NOT Git_FOUND)
fatal("Git is required to be installed for --commit,"
"but it could not be found.")
endif()
set(msg_file ${TMP}/commit_msg.txt)
file(WRITE ${msg_file} "Update dependencies\n\n${update_log}")
execute_process(COMMAND ${GIT_EXECUTABLE} add cpmfile.json
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
execute_process(COMMAND ${GIT_EXECUTABLE} commit -F ${msg_file}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
file(REMOVE_RECURSE ${TMP})
endif()

View file

@ -0,0 +1,28 @@
#!/usr/bin/env -S cmake -P
# SPDX-FileCopyrightText: Copyright 2026 crueter
# SPDX-License-Identifier: LGPL-3.0-or-later
cmake_minimum_required(VERSION 3.31)
include(${CMAKE_CURRENT_LIST_DIR}/../ScriptUtils.cmake)
function(usage)
echo([=[
Usage: cpmutil.sh package url [-a|--all] [PACKAGE]...
Get the download URL for the specified packages.
Options:
-a, --all Operate on all packages in this project.
]=])
endfunction()
parse_script_args(args)
foreach(key ${args})
parse_key(${key})
get_package_url_object(pkg_url)
echo("${key}: ${pkg_url}")
endforeach()

Some files were not shown because too many files have changed in this diff Show more