Convert Figma logo to code with AI

conan-io logoconan

Conan - The open-source C and C++ package manager

8,199
979
8,199
1,241

Top Related Projects

22,999

C++ Library Manager for Windows, Linux, and MacOS

1,495

Repo for NuGet Client issues

41,118

🍺 The missing package manager for macOS (or Linux)

6,398

A system-level, binary package and environment manager running on all major operating systems and platforms.

4,255

A flexible package manager that supports multiple versions, configurations, platforms, and compilers.

Quick Overview

Conan is a decentralized package manager for C and C++ that simplifies the process of managing dependencies in software projects. It allows developers to define, create, and share packages, making it easier to reuse code and manage complex dependency trees across different platforms and build systems.

Pros

  • Cross-platform compatibility, supporting Windows, Linux, macOS, and more
  • Integration with various build systems (CMake, Visual Studio, Makefiles, etc.)
  • Decentralized architecture, allowing for private and public package repositories
  • Extensible through custom commands, hooks, and plugins

Cons

  • Learning curve for developers new to package management in C/C++
  • Requires additional setup and configuration compared to traditional dependency management
  • Some packages may not be available or up-to-date in public repositories
  • Can add complexity to smaller projects with few dependencies

Code Examples

  1. Creating a Conan package:
from conans import ConanFile, CMake

class MyLibraryConan(ConanFile):
    name = "mylibrary"
    version = "1.0.0"
    settings = "os", "compiler", "build_type", "arch"
    options = {"shared": [True, False]}
    default_options = {"shared": False}
    generators = "cmake"

    def source(self):
        self.run("git clone https://github.com/user/mylibrary.git")

    def build(self):
        cmake = CMake(self)
        cmake.configure(source_folder="mylibrary")
        cmake.build()

    def package(self):
        self.copy("*.h", dst="include", src="mylibrary/include")
        self.copy("*.lib", dst="lib", keep_path=False)
        self.copy("*.dll", dst="bin", keep_path=False)
        self.copy("*.so", dst="lib", keep_path=False)
        self.copy("*.dylib", dst="lib", keep_path=False)
        self.copy("*.a", dst="lib", keep_path=False)

    def package_info(self):
        self.cpp_info.libs = ["mylibrary"]
  1. Consuming a Conan package:
from conans import ConanFile, CMake

class MyProjectConan(ConanFile):
    settings = "os", "compiler", "build_type", "arch"
    requires = "mylibrary/1.0.0"
    generators = "cmake"

    def build(self):
        cmake = CMake(self)
        cmake.configure()
        cmake.build()
  1. Installing dependencies:
conan install . --build=missing

Getting Started

  1. Install Conan:
pip install conan
  1. Create a conanfile.txt in your project directory:
[requires]
zlib/1.2.11

[generators]
cmake
  1. Install dependencies:
conan install . --build=missing
  1. Use the installed packages in your CMakeLists.txt:
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_executable(myapp main.cpp)
target_link_libraries(myapp ${CONAN_LIBS})

Competitor Comparisons

22,999

C++ Library Manager for Windows, Linux, and MacOS

Pros of vcpkg

  • Simpler setup and usage, especially for Windows developers
  • Tighter integration with Visual Studio and CMake
  • Supports a wide range of platforms, including mobile and embedded systems

Cons of vcpkg

  • Less flexible dependency management compared to Conan
  • Limited support for versioning and conflict resolution
  • Slower package installation process, especially for large projects

Code Comparison

vcpkg:

find_package(CURL CONFIG REQUIRED)
target_link_libraries(main PRIVATE CURL::libcurl)

Conan:

from conans import ConanFile, CMake

class MyProject(ConanFile):
    requires = "libcurl/7.79.1"
    generators = "cmake"

Both vcpkg and Conan are package managers for C and C++ libraries, but they have different approaches to dependency management. vcpkg is more straightforward for Windows developers and integrates well with Visual Studio, while Conan offers more flexibility and advanced features for managing complex dependencies across multiple platforms.

vcpkg uses a simpler model where packages are installed globally on the system, making it easier to set up but potentially leading to conflicts. Conan, on the other hand, uses a more sophisticated approach with virtual environments and versioning, allowing for better isolation and reproducibility.

In terms of usage, vcpkg typically requires less configuration, as shown in the CMake example above. Conan requires more setup but provides greater control over dependencies and build configurations.

1,495

Repo for NuGet Client issues

Pros of NuGet

  • Tighter integration with Microsoft ecosystem (.NET, Visual Studio)
  • Simpler setup and usage for .NET developers
  • Larger package ecosystem for .NET libraries

Cons of NuGet

  • Limited to .NET ecosystem, less versatile for cross-platform development
  • Less granular control over dependencies and versions
  • Fewer features for managing native dependencies

Code Comparison

NuGet package reference in a .NET project file:

<ItemGroup>
  <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

Conan package reference in a conanfile.txt:

[requires]
boost/1.75.0
zlib/1.2.11

[generators]
cmake

NuGet focuses on .NET packages and integrates seamlessly with Visual Studio and .NET projects. It's easier to use for .NET developers but lacks cross-platform versatility. Conan, on the other hand, offers more flexibility for C and C++ projects across different platforms and build systems.

NuGet's package references are typically added directly to project files, while Conan uses separate conanfile.txt or conanfile.py files to manage dependencies. This reflects their different approaches to package management and target ecosystems.

41,118

🍺 The missing package manager for macOS (or Linux)

Pros of Homebrew

  • Broader package management for macOS and Linux, not limited to C/C++ dependencies
  • Simpler installation process and user-friendly command-line interface
  • Large community and extensive package repository

Cons of Homebrew

  • Less focused on C/C++ dependency management compared to Conan
  • Limited cross-platform support, primarily targeting macOS
  • Less granular control over package versions and configurations

Code Comparison

Conan:

from conans import ConanFile, CMake

class MyLibConan(ConanFile):
    name = "MyLib"
    version = "1.0"
    settings = "os", "compiler", "build_type", "arch"
    generators = "cmake"

Homebrew:

class MyLib < Formula
  desc "My library"
  homepage "https://example.com/mylib"
  url "https://example.com/mylib-1.0.tar.gz"
  sha256 "abcdef1234567890abcdef1234567890"

  depends_on "cmake" => :build
end

Both Conan and Homebrew serve as package managers, but they have different focuses. Conan specializes in C/C++ dependency management with fine-grained control over configurations, while Homebrew offers a more general-purpose package management solution for macOS and Linux systems. The code examples demonstrate the different approaches: Conan uses a Python-based recipe system, while Homebrew employs Ruby-based formulae for package definitions.

6,398

A system-level, binary package and environment manager running on all major operating systems and platforms.

Pros of conda

  • Broader ecosystem support, including data science and machine learning packages
  • Cross-platform package management for multiple programming languages
  • Robust environment management capabilities

Cons of conda

  • Larger installation size and potentially slower package resolution
  • Less focused on C/C++ dependency management compared to Conan
  • Can be more complex for projects primarily focused on C/C++ development

Code comparison

Conda environment creation:

name: myenv
channels:
  - conda-forge
dependencies:
  - python=3.8
  - numpy
  - pandas

Conan package definition:

from conans import ConanFile

class MyLibConan(ConanFile):
    name = "MyLib"
    version = "1.0"
    settings = "os", "compiler", "build_type", "arch"
    requires = "boost/1.74.0"

Both Conda and Conan serve as package managers, but they cater to different primary use cases. Conda is more general-purpose and widely used in data science, while Conan specializes in C and C++ dependency management. The choice between them depends on the specific project requirements and the ecosystem you're working in.

4,255

A flexible package manager that supports multiple versions, configurations, platforms, and compilers.

Pros of Spack

  • Broader language support, including scientific computing languages
  • Built-in support for HPC environments and supercomputers
  • More flexible package specification system, allowing for multiple versions and variants

Cons of Spack

  • Steeper learning curve due to its more complex package specification system
  • Slower package installation process compared to Conan
  • Less focus on C/C++ ecosystems, which are Conan's primary targets

Code Comparison

Spack package definition:

class Boost(Package):
    homepage = "https://www.boost.org"
    url      = "https://boostorg.jfrog.io/artifactory/main/release/1.76.0/source/boost_1_76_0.tar.bz2"

    version('1.76.0', sha256='f0397ba6e982c4450f27bf32a2a83292aba035b827a5623a14636ea583318c41')

    depends_on('python')
    depends_on('zlib')

    def install(self, spec, prefix):
        ./bootstrap.sh --prefix={prefix}
        ./b2 install

Conan package definition:

class BoostConan(ConanFile):
    name = "boost"
    version = "1.76.0"
    
    def requirements(self):
        self.requires("zlib/1.2.11")

    def source(self):
        tools.get(f"https://boostorg.jfrog.io/artifactory/main/release/{self.version}/source/boost_{self.version.replace('.', '_')}.tar.bz2")

    def build(self):
        self.run("./bootstrap.sh")
        self.run("./b2 install")

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

JFrog | Conan 2.0 Logo

Conan

Decentralized, open-source (MIT), C/C++ package manager.

Conan is a package manager for C and C++ developers:

  • It is fully decentralized. Users can host their packages on their servers, privately. Integrates with Artifactory and Bintray.
  • Portable. Works across all platforms, including Linux, OSX, Windows (with native and first-class support, WSL, MinGW), Solaris, FreeBSD, embedded and cross-compiling, docker, WSL
  • Manage binaries. It can create, upload and download binaries for any configuration and platform, even cross-compiling, saving lots of time in development and continuous integration. The binary compatibility can be configured and customized. Manage all your artifacts in the same way on all platforms.
  • Integrates with any build system, including any proprietary and custom one. Provides tested support for major build systems (CMake, MSBuild, Makefiles, Meson, etc).
  • Extensible: Its Python-based recipes, together with extension points allow for great power and flexibility.
  • Large and active community, especially in GitHub (https://github.com/conan-io/conan) and Slack (https://cppalliance.org/slack/ #conan channel). This community also creates and maintains packages in ConanCenter and Bincrafters repositories in Bintray.
  • Stable. Used in production by many companies, since 1.0 there is a commitment not to break package recipes and documented behavior.

This is the developer/maintainer documentation. For user documentation, go to https://docs.conan.io

Setup

You can run Conan from source in Windows, MacOS, and Linux:

  • Install pip following pip docs.

  • Clone Conan repository:

    $ git clone https://github.com/conan-io/conan.git conan-io
    

    Note: repository directory name matters, some directories are known to be problematic to run tests (e.g. conan). conan-io directory name was tested and guaranteed to be working.

  • Install in editable mode

    $ cd conan-io && sudo pip install -e .
    

    If you are in Windows, using sudo is not required. Some Linux distros won't allow you to put Python packages in editable mode in the root Python installation, and creating a virtual environment venv first, is mandatory.

  • You are ready, try to run Conan:

    $ conan --help
    
    Consumer commands
      install    Installs the requirements specified in a recipe (conanfile.py or conanfile.txt).
      ...
    
      Conan commands. Type "conan <command> -h" for help
    

Contributing to the project

Feedback and contribution are always welcome in this project. Please read our contributing guide. Also, if you plan to contribute, please add some testing for your changes. You can read the Conan tests guidelines section for some advice on how to write tests for Conan.

Running the tests

Install Python requirements

$ python -m pip install -r conans/requirements.txt
$ python -m pip install -r conans/requirements_server.txt
$ python -m pip install -r conans/requirements_dev.txt

If you are not on Windows and you are not using a Python virtual environment, you will need to run these commands using sudo.

Before you can run the tests, you need to set a few environment variables first.

$ export PYTHONPATH=$PYTHONPATH:$(pwd)

On Windows it would be (while being in the Conan root directory):

$ set PYTHONPATH=.

Conan test suite defines and configures some required tools (CMake, Ninja, etc) in the conftest.py and allows to define a custom conftest_user.py. Some specific versions, like cmake>=3.15 are necessary.

You can run the tests like this:

$ python -m pytest .

A few minutes later it should print OK:

............................................................................................
----------------------------------------------------------------------
Ran 146 tests in 50.993s

OK

To run specific tests, you can specify the test name too, something like:

$ python -m pytest test/functional/command/export_test.py::TestRevisionModeSCM::test_revision_mode_scm -s

The -s argument can be useful to see some output that otherwise is captured by pytest.

Also, you can run tests against an instance of Artifactory. Those tests should add the attribute artifactory_ready.

$ python -m pytest . -m artifactory_ready

Some environment variables have to be defined to run them. For example, for an Artifactory instance that is running on the localhost with default user and password configured, the variables could take the values:

$ export CONAN_TEST_WITH_ARTIFACTORY=1
$ export ARTIFACTORY_DEFAULT_URL=http://localhost:8081/artifactory
$ export ARTIFACTORY_DEFAULT_USER=admin
$ export ARTIFACTORY_DEFAULT_PASSWORD=password

ARTIFACTORY_DEFAULT_URL is the base URL for the Artifactory repo, not one for a specific repository. Running the tests with a real Artifactory instance will create repos on the fly so please use a separate server for testing purposes.

License

MIT LICENSE