Pack CMake - BredaUniversityGames/JenkinsLib GitHub Wiki

cmake.pack()

Packages build output using CPack. Supports both preset-based packaging (from CMakePresets.json) and manual CPack invocation using the build context.

Usage

With presets:

stages {
    git.sync()
    cmake.build()
    cmake.pack()
    // ...
}

Standalone (configures and builds automatically if needed):

stages {
    git.sync()
    cmake.pack()
    // ...
}

Manual mode (no presets):

stages {
    git.sync()
    cmake.build()
    cmake.pack()
    // ...
}

Parameters

Preset Mode

When CMakePresets.json contains packagePresets:

Parameter Default Description
CMAKE_PACKAGE_PRESET (first preset) CPack preset (dropdown populated from CMakePresets.json)

Manual Mode

When no package presets are found:

Parameter Default Description
CMAKE_CPACK_GENERATOR ZIP CPack generator (ZIP, NSIS, WIX, NuGet, 7Z, TGZ)
CMAKE_CPACK_ARGS (empty) Additional CPack arguments

Note: In manual mode, cmake.pack() requires cmake.build() to run first so it can read the build directory and configuration from context.

How It Works

Preset Mode

  1. Looks up the package preset's configurePreset in CMakePresets.json
  2. If the package preset's configure preset differs from the build preset's configure preset (or no build was run), automatically runs configure + build
  3. Matches the package preset's configurations list (e.g., ["Release"]) against available build presets to build only the required configurations
  4. Runs cpack --preset <preset>

Manual Mode

  1. Reads ctx.cmakeBuildDir and ctx.buildConfig from the build stage context
  2. Runs cpack -G <generator> -B <buildDir>/_packages -C <config>

Self-Contained Pack Builds

When cmake.pack() is used without a preceding cmake.build(), the pack stage automatically configures and builds the project using the package preset's configurePreset. Only build presets matching the package preset's configurations are built, avoiding unnecessary work.

Troubleshooting

Issue Solution
"requires cmake.build() to run first" In manual mode, add cmake.build() before cmake.pack()
"CPack project name not specified" The project was not configured before packing; ensure cmake.build() runs first or that your package preset has a valid configurePreset
No package preset dropdown Ensure your CMakePresets.json contains non-hidden packagePresets
"has no configurePreset defined" Add a configurePreset field to your package preset in CMakePresets.json
"No build preset found for configure preset" Ensure a buildPreset exists that references the same configurePreset and matches the required configurations
⚠️ **GitHub.com Fallback** ⚠️