All jobs

Add Conan 2 Packaging to a CMake C++ Library

Yes. An agent writes a conanfile.py and test_package for your CMake library, wires conan create into CI, and opens a PR showing the package builds and links.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent reads how the library is built and installed before it writes a conanfile. In a project like jarro2783/cxxopts, the library is one header, include/cxxopts.hpp, whose version lives in three #define CXXOPTS__VERSION_ lines (3.3.1 at the time of reading). CMakeLists.txt declares cmake_minimum_required(VERSION 3.5...3.19), includes cmake/cxxopts.cmake, reads the version from the header with cxxopts_getversion, and exposes options CXXOPTS_BUILD_EXAMPLES, CXXOPTS_BUILD_TESTS, CXXOPTS_ENABLE_INSTALL, CXXOPTS_ENABLE_WARNINGS and CXXOPTS_USE_UNICODE_HELP, the first four on when the project is standalone. cxxopts_install_logic writes cxxopts-config.cmake from packaging/cxxopts-config.cmake.in, a cxxopts.pc from packaging/pkgconfig.pc.in, exports the cxxopts::cxxopts target, installs the header under CMAKE_INSTALL_INCLUDEDIR and configures CPack for a libcxxopts-dev package. test/find-package-test/CMakeLists.txt already proves the installed package works: it calls find_package(cxxopts REQUIRED) and builds src/example.cpp against cxxopts::cxxopts. The README carries a Conan badge pointing at the conan-center package, but the repository itself has no conanfile.py; it does have meson.build, BUILD.bazel and a .tipi directory for other build systems.

The conanfile mirrors what CMake already does rather than inventing a second build. conanfile.py at the root sets name to cxxopts, reads the version from the header in set_version with the same regular expression the CMake and Meson helpers use, so the version stays single-sourced, and declares package_type = "header-library" with no_copy_source = True. exports_sources lists the header, CMakeLists.txt, cmake/, include/CMakeLists.txt, packaging/ and LICENSE. layout uses cmake_layout; generate writes a CMakeToolchain with CXXOPTS_BUILD_EXAMPLES, CXXOPTS_BUILD_TESTS and CXXOPTS_ENABLE_WARNINGS off and CXXOPTS_ENABLE_INSTALL on; build and package run the project's own CMake configure and install. package_info sets the cmake_file_name and cmake_target_name properties to cxxopts and cxxopts::cxxopts and pkg_config_name to cxxopts, empties bindirs and libdirs since nothing is compiled, and package_id calls self.info.clear() so one package serves every compiler. A unicode option maps to CXXOPTS_USE_UNICODE_HELP and adds the ICU requirement only when set; validate enforces C++11 with check_min_cppstd.

A test_package directory makes conan create prove the result. Its CMakeLists.txt calls find_package(cxxopts REQUIRED) and builds the repository's own src/example.cpp against cxxopts::cxxopts, the same check test/find-package-test makes against a CMake install, and its conanfile.py runs the example binary in test(). In .github/workflows, a new conan.yml job installs Conan with pip, runs conan profile detect --force and conan create . --build=missing on ubuntu-latest, so a pull request that breaks the packaging fails the job. The existing cmake.yml matrix across GCC 9, GCC 10, Clang, macOS and Windows and the meson.yml and cifuzz.yml workflows are untouched.

The proof is the conan create output. The agent runs it in the sandbox, shows the package being built, the test package compiling example.cpp and the binary running --help, then runs conan create . -o unicode=True --build=missing to show the ICU path configures. It also runs the project's normal cmake configure and ctest to show the new files changed nothing for existing users, and explains in the pull request how this in-repo conanfile differs from the conan-center one: a fork or an unreleased commit can be packaged with conan create or conan export immediately, without waiting for a center update.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Add Conan 2 packaging to this CMake C++ library. Read CMakeLists.txt, the cmake/ helpers, the packaging templates, the install and find_package tests, the README and the CI workflows first. Write a conanfile.py at the repository root that reads the version from where the build already defines it, uses the project's own CMake configure and install through cmake_layout, CMakeToolchain and CMake, declares the right package_type, sets the cmake_file_name, cmake_target_name and pkg_config_name properties to match the installed config files, and maps existing CMake options to Conan options. Add a test_package that finds the package and builds an example against it, and a CI job that runs conan create. Run conan create locally with the default and non-default options and include the output. Do not change the existing CMake, Meson or Bazel builds. Open a pull request.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

What comes back is a pull request adding conanfile.py, a test_package directory with its own conanfile.py and CMakeLists.txt, a .github/workflows/conan.yml job, and a short section in the README on conan create. CMakeLists.txt, cmake/cxxopts.cmake, meson.build and BUILD.bazel are unchanged, and the .gitignore gains the Conan build directories if it did not cover them.

The description quotes the conan create output for both option sets, the test package's build and run, and the unchanged ctest summary from the normal CMake build. The full output is in the transcript at GET /o/{org}/sessions/{id}/messages.

Before merging, a reviewer compares the conanfile's package_info against packaging/cxxopts-config.cmake.in to confirm the target names agree, decides whether the unicode option should default on or off, and whether the CI job should also run on macOS and Windows. A follow-up message to the same session can add a conan upload step to the release workflow for a private remote.

Run it on every C++ library you publish

A team with several CMake libraries starts one run per repository with one POST /o/{org}/sessions each, the repository in resources and this prompt as input. Each run reads its own install logic, so a compiled library gets a conanfile with shared and fPIC options and real libdirs, while a header-only one gets the cleared package id, and each opens its own pull request.

Send a request_id, a UUID v5 of the repository's full name, so a retried call returns the run it already started. The key's webhook_url reports when each run the key starts finishes, with the run's final answer in result.

The use case this job follows, with its automation and trigger: Hand off a long task.

Why run it on Rush?

A conanfile that works is one that reuses the project's real CMake install and names the same targets the config files export; a conanfile written from a template silently diverges and consumers find out at link time. The agent reads the install logic, the packaging templates and the existing find_package test, and writes the conanfile to match, then runs conan create with each option in a sandbox of its own and keeps the output.

The pull request carries the proof, so the review is a read of two small Python files and one workflow. Several libraries can be packaged at once, each in its own sandbox, each with its own pull request.

Frequently asked questions

The library is already on conan-center. Why have a conanfile in the repository?

The center's package tracks released versions. An in-repo conanfile lets anyone package the current commit or a fork with conan create . or conan export ., use it in a private remote, and test a change against a consumer before a release. The agent notes the center package in the README section it adds so the two are not confused.

Does the conanfile duplicate the build logic?

No. It calls the project's own CMake configure and install through the CMake helper with a generated toolchain, and only turns the existing options off or on. The version is read from the same header the CMake and Meson helpers read, so there is one place to bump it.

What does test_package check?

That a consumer can find_package(cxxopts) through Conan's generated config, compile the repository's own example against the cxxopts::cxxopts target and run it. It is the same check the repository's find-package-test makes against a CMake install, now run by conan create.

Why clear the package id?

A header-only package has no compiled artifacts, so its contents are the same for every compiler, architecture and build type. self.info.clear() tells Conan that one binary package serves all of them, which avoids a rebuild per profile.

More CMake jobs

More jobs like this: Hand off a long task

Keep reading