Skip to content

ekala-project/corepkgs / .agents/skills/cmake

Package a CMake-based project for corepkgs. Use when a source tree has a CMakeLists.txt — covers the minimal derivation, cmakeEntries, cross-compilation, and diagnosing CMake configure failures.

FileKindSize
SKILL.mdskill md2.7 KB
---
name: cmake
description: Package a CMake-based project for corepkgs. Use when a source tree has a CMakeLists.txt — covers the minimal derivation, cmakeEntries, cross-compilation, and diagnosing CMake configure failures.
---

# CMake Build System

## Minimal Example

```nix
{
  lib,
  stdenv,
  fetchFromGitHub,
  cmake,
}:

stdenv.mkDerivation (finalAttrs: {
  pname = "example";
  version = "1.0.0";

  src = fetchFromGitHub {
    owner = "example";
    repo = "example";
    tag = "v${finalAttrs.version}";
    hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
  };

  nativeBuildInputs = [
    cmake
    cmake.configurePhaseHook  # Required
  ];

  meta = {
    description = "Example CMake package";
    license = lib.licenses.mit;
  };
})
```

## Essential Requirements

**Always include** `cmake.configurePhaseHook` in `nativeBuildInputs`.

- `cmake` alone provides the cmake binary and the setup hook (`setup-hook.sh`),
  which defines all `cmakeEntries` helpers (`setCMakeEntry`, `prependCMakeEntry`,
  `concatCMakeEntryFlagsTo`, etc.) and `cmakeConfigurePhase`.
- `cmake.configurePhaseHook` replaces the default configure phase with
  `cmakeConfigurePhase`, which assembles `cmakeEntries` + `cmakeFlags` into the
  final cmake invocation. Without it, the configure phase is the generic
  autotools-style one and cmake entries/flags are ignored.

## Common Patterns

### With Dependencies

```nix
nativeBuildInputs = [
  cmake
  cmake.configurePhaseHook
  pkg-config
];

buildInputs = [
  zlib
  openssl
];
```

### CMake Entries (Preferred)

Use `cmakeEntries` to specify CMake `-D` cache entries as a structured attrset.
Booleans are automatically converted to `ON`/`OFF`.

```nix
cmakeEntries = {
  BUILD_SHARED_LIBS = true;
  ENABLE_TESTS = false;
  CMAKE_INSTALL_LIBDIR = "lib";
};
```

### CMake Flags (non-`-D` only)

`cmakeFlags` is reserved for non-`-D` flags (warning suppression, generator
selection, source-dir overrides, unset flags). **All `-D` entries must use
`cmakeEntries`.**

```nix
cmakeFlags = [
  "-Wno-dev"
  "-H.."
  "-UCMAKE_INSTALL_LIBDIR"  # unset (-U), not a -D flag
];
```

Both can be used together. `cmakeEntries` entries are emitted first, then
`cmakeFlags` / `cmakeFlagsArray` are appended.

### Cross-Compilation

```nix
strictDeps = true;

nativeBuildInputs = [ cmake cmake.configurePhaseHook pkg-config ];
buildInputs = [ zlib ];
depsBuildBuild = [ pkg-config ];
```

## Troubleshooting

**CMake can't find dependencies:**
```nix
cmakeEntries = {
  ZLIB_ROOT = "${zlib}";
  OPENSSL_ROOT_DIR = "${openssl}";
};
```

**Library install to lib64:**
```nix
cmakeEntries = {
  CMAKE_INSTALL_LIBDIR = "lib";
};
```

**Install prefix issues:**
```nix
cmakeEntries = {
  CMAKE_INSTALL_PREFIX = "${placeholder "out"}";
};
```
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall