From db8da0538d9e9b738dcf7d57954cd78f3a5a0e6b Mon Sep 17 00:00:00 2001 From: Pavel Zwerschke Date: Fri, 30 Jan 2026 17:40:53 +0100 Subject: [PATCH 1/2] Add CMake example --- docs/_sidebar.json | 3 +- docs/maintainer/example_recipes/cmake.md | 62 ++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 docs/maintainer/example_recipes/cmake.md diff --git a/docs/_sidebar.json b/docs/_sidebar.json index 9cfa20019f0..74e90e8025a 100644 --- a/docs/_sidebar.json +++ b/docs/_sidebar.json @@ -56,7 +56,8 @@ }, "items": [ "maintainer/example_recipes/go", - "maintainer/example_recipes/rust" + "maintainer/example_recipes/rust", + "maintainer/example_recipes/cmake" ] } ] diff --git a/docs/maintainer/example_recipes/cmake.md b/docs/maintainer/example_recipes/cmake.md new file mode 100644 index 00000000000..28a98bcfe45 --- /dev/null +++ b/docs/maintainer/example_recipes/cmake.md @@ -0,0 +1,62 @@ +--- +title: 'CMake packages' +--- + +If you want to package a CMake library to conda-forge, you can use this recipe template: + +```yaml +context: + version: "1.2.3" + +package: + name: example-package + version: ${{ version }} + +source: + url: https://github.com/example-package/example-package/archive/refs/tags/v${{ version }}.tar.gz + sha256: 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef + +build: + number: 0 + script: + content: + - if: unix + then: + - cmake -B build -GNinja $CMAKE_ARGS . + else: + - cmake -B build -GNinja %CMAKE_ARGS% . + - cmake --build build + - cmake --install build + +requirements: + build: + - ${{ stdlib('c') }} + - ${{ compiler('c') }} + - ${{ compiler('cxx') }} # optional + - cmake + - ninja + host: + # put any dependencies here + run_exports: + - ${{ pin_subpackage('example-package', upper_bound='x.x.x') }} + +tests: + - package_contents: + lib: + - example_package + +about: + homepage: https://github.com/example-package/example-package + summary: Summary of the package. + description: | + Description of the package + license: LGPL-3.0-or-later + license_file: + - COPYING + documentation: https://github.com/example-package/example-package + repository: https://github.com/example-package/example-package + +extra: + recipe-maintainers: + - LandoCalrissian +``` From cfc6e49a37b65f6facfa3fd37bbccfa17963cda2 Mon Sep 17 00:00:00 2001 From: Pavel Zwerschke Date: Wed, 11 Feb 2026 15:39:09 +0100 Subject: [PATCH 2/2] review --- docs/maintainer/example_recipes/cmake.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/maintainer/example_recipes/cmake.md b/docs/maintainer/example_recipes/cmake.md index 28a98bcfe45..a57f4bfb70f 100644 --- a/docs/maintainer/example_recipes/cmake.md +++ b/docs/maintainer/example_recipes/cmake.md @@ -23,9 +23,11 @@ build: - if: unix then: - cmake -B build -GNinja $CMAKE_ARGS . + - cmake --build build --parallel ${CPU_COUNT} else: - cmake -B build -GNinja %CMAKE_ARGS% . - - cmake --build build + - cmake --build build --parallel %CPU_COUNT% + - ctest --test-dir build --output-on-failure - cmake --install build requirements: @@ -60,3 +62,15 @@ extra: recipe-maintainers: - LandoCalrissian ``` + +This recipe template supports different features: + +- `$CMAKE_ARGS` (or `%CMAKE_ARGS%` on Windows) is set by conda-forge and contains flags needed for cross-compilation, installation prefix, and other platform-specific settings. Always pass it to the `cmake` configure step. +- `-GNinja` selects the Ninja build system generator, which is faster than the default Make generator. +- `--parallel ${CPU_COUNT}` passes the number of available CPUs to the build step to enable parallel compilation. +- `ctest --test-dir build --output-on-failure` runs the project's test suite during the build phase (while the build directory is still available) and prints output from any failing tests. +- `run_exports` with `pin_subpackage` ensures that downstream packages that depend on this library automatically get a compatible version pinned at build time. + +If your project is a standalone executable rather than a library, you can remove the `run_exports` section and adjust the `package_contents` test to check `bin` instead of `lib`. + +If your project does not use C++, you can remove the `${{ compiler('cxx') }}` line from the build requirements.