Giter VIP home page Giter VIP logo

cmake-conan's Introduction

cmake-conan

Build Status

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

โš ๏ธ Compatibility with Conan 2.0: integration with Conan 2.0 is currently experimental, may have some limitations, and is subject to change, please read below. The code in this branch only supports Conan 2.0.2 and above - if you need Conan 1.x please check the develop branch.

Quickstart with Conan 2.0

Prerequisites:

  • CMake 3.24
  • Conan 2.0.5
  • A CMake-based project that contains a conanfile.txt or conanfile.py to list the required dependencies.

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

  • Ensure you have placed a conanfile.txt or conanfile.py at the root of your project, listing your requirements. You can see conanfile.txt for an example, or check the Conan documentation for conanfile: .txt docs, .py docs.

  • When first invoking CMake to configure the project, pass -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=[path-to-cmake-conan]/conan_provider.cmake. This will ensure that conan install is invoked from within CMake. This integration does not require making any changes to your CMakeLists.txt scripts.

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

  • Only the CMakeDeps generator is specified - for build settings that would otherwise be provided by CMakeToolchain (for example, the compiler itself or other global build settings) please invoke Conan separately as per documentation.
  • Currently this only works such that Conan can satisfy invocations to CMake's find_package. For dependencies that have logic outside of find_package, for example, by making direct calls to find_program, find_library, find_path or find_file, these may not work correctly.
  • When using a single-configuration CMake generator, you must specify a valid CMAKE_BUILD_TYPE (can't be left blank)
  • Deriving Conan settings is currently only supported on the most common platforms with the most popular compilers.

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:

  • Conan host profile: settings detected from CMake. For anything that cannot be detected from CMake, it falls back to the default Conan profile.
  • Conan build profile: the default Conan profile.

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:

  • -DCONAN_HOST_PROFILE="default;auto-cmake": perform autodetection as described above, and fallback to the default profile for anything else (default behaviour).
  • -DCONAN_HOST_PROFILE=clang16: do not perform autodetection, and use the clang16 profile which must exist in the Conan profiles folder (see docs.)
  • -DCONAN_BUILD_PROFILE="/path/to/profile": alternatively, provide a path to a profile file that may be anywhere in the filesystem.
  • -DCONAN_HOST_PROFILE="default;custom": semi-colon separated list of profiles. A compound profile will be used (see docs) - compunded from left to right, where right has the highest priority.

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.

  • By default, CONAN_INSTALL_ARGS is initialised to pass --build=missing. If you customize this variable, please be aware that Conan will revert to its default behaviour unless you specify the --build flag.
  • Two arguments are reserved to the dependency provider implementation and must not be set: the path to a conanfile.txt|.py, and the output format (--format).
  • Values are semi-colon separated, e.g. --build=never;--update;--lockfile-out=''

Development, contributors

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

$ pytest -rA

cmake-conan's People

Contributors

memsharded avatar czoido avatar jcar87 avatar ssrobins avatar dvetutnev avatar sixten-hilborn avatar tim-goto avatar kinddragon avatar bilke avatar hwhsu1231 avatar r4zzz4k avatar puetzk avatar juansblanco avatar artalus avatar uilianries avatar chuet-thermo avatar bc-lee avatar tonka3000 avatar cguenthertuchemnitz avatar smessmer avatar gatorque avatar ohanar avatar gabyx avatar bernedom avatar davidzemon avatar bluesolei avatar uoqs avatar samuelmarks avatar sse4 avatar thorntonryan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.