conan-io / cmake-conan

CMake wrapper for conan C and C++ package manager
MIT License
814 stars 247 forks source link
c cmake cmake-wrapper conan cpp package-manager

cmake-conan

Build Status

CMake dependency provider for the Conan C and C++ package manager.

⚠️ Important: Conan 2 is the recommended production version for cmake-conan.
The cmake-conan integration in this develop2 branch for Conan 2 using CMake dependency providers, even if not released as 1.0 yet, is more stable, production-ready and recommended than the legacy cmake-conan for Conan 1. Please update to Conan 2 and the new cmake-conan integration in this develop2 branch.

Quickstart with Conan 2.0

Prerequisites:

First, clone this repository in the develop2 branch.

git clone https://github.com/conan-io/cmake-conan.git -b develop2

Example project

This repository contains a CMakeLists.txt with an example project that depends on fmt.

cd cmake-conan/example
mkdir build
cmake -B build -S . -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=../conan_provider.cmake -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release

In your own project

cd [your-project]
mkdir build
cmake -B build -S . -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=[path-to-cmake-conan]/conan_provider.cmake -DCMAKE_BUILD_TYPE=Release

Known limitations with Conan 2.0

Customizing Conan profiles

The CMake-Conan dependency provider will create a Conan profile where the settings (os, arch, compiler, build_type) are retrieved from what CMake has detected for the current build. Conan uses two profiles for dependencies, the host and the build profiles. You can read more about them here. In CMake-Conan, the default behaviour is as follows:

Please note that for the above to work, a default profile must already exist. If it doesn't, cmake-conan will invoke Conan's autodetection mechanism which tries to guess the system defaults.

If you need to customize the profile, you can do so by modifying the value of CONAN_HOST_PROFILE and CONAN_BUILD_PROFILE and passing them as CMake cache variables. Some examples:

Customizing the invocation of Conan install

The CMake-Conan dependency provider will autodetect and pass the profile information as described above. If the conan install command invocation needs to be customized further, the CONAN_INSTALL_ARGS variable can be used.

Development, contributors

There are some tests, you can run in python, with pytest, for example:

$ pytest -rA