8

I have been trying to build Conan packages of my project for a week. I have been reading the documentation but there are many points that I'm still confused about.

There are 4 files that I think are very important:

  • conanfile.py
  • conanfile.txt
  • conan_profile
  • settings.yml

What is the purpose of each file? Where should each file be located? Which ones are interchangeable?

I have the following conanfile.py that generates the Conan package:

from conans import ConanFile, CMake

class mylibConan(ConanFile):
    name = "mylib"
    version = "1.16.0"
    generators = "cmake"
    settings = "os", "arch", "compiler", "build_type"
    options = {"shared": [True, False]}
    default_options = "shared=False"
    exports_sources = ["*"]
    url = ""
    license = ""
    description = "The mylib HAL library."

    def configure(self):
        self.options.shared = False

    def build(self):
        cmake = CMake(self)
        cmake.configure()
        cmake.build()

    def package(self):
        libs_build_dir = "lib_mylib/" + str(self.settings.build_type)
        api_dir = "modules/mylib/lib/api/"
        self.copy(pattern="lib_mylib.lib", dst="lib", src=libs_build_dir)
        self.copy(pattern="*", dst="include", src=api_dir)

    def package_info(self):
        self.cpp_info.includedirs = ['include']
        self.cpp_info.libdirs = ['lib']
        self.cpp_info.libs = ['mylib']

...and the following conanfile.txt in my main project that consumes the Conan package:

[requires]
mylib/1.16.0@demo/testing

[generators]
cmake
visual_studio_multi

I need to define the cl version to be 14.24.28314 so it doesn't conflict with the consuming project.

Where should I define the cl version?

Farahi
  • 95
  • 1
  • 6

1 Answers1

13

The files are:

  • conanfile.py is a Conan "recipe". It declares dependencies, how to build a package from sources. The same recipe can be used to manage different configurations, like different platforms, compilers, build types, etc
  • conanfile.txt is a text simplification of conanfile.py, that can be used exclusively to consume dependencies, but not to create packages. conanfile.py can be used both to consume dependencies and to create packages
  • a profile file is a text file containing configuration values like os=Windows and compiler=gcc. You can pass these values in the command line, but it is better to have them in files, easier to manage and more convenient.
  • settings.yml is a declaration of what values can the settings take. To validate the inputs and make sure there are no typos, and use a common set of configurations so people can collaborate together.

I suggest following the tutorials in the docs, like https://docs.conan.io/en/latest/getting_started.html, or if you are into video-format, this free training is good: https://academy.jfrog.com/path/conan

Regarding the versions, you need to use those defined in the settings, for Visual Studio you need to use 14, 15, etc. The new msvc compiler setting, experimental, will be using the compiler version, like 19.xx. In general, it is not needed to specify the compiler version down to the patch, because this is mostly for the binary model, and it is typically not needed to go to that level. If you want to learn how to customize the settings value, read this section

drodri
  • 5,157
  • 15
  • 21
  • According to the link, the `settings.yml` file resides in the `user/.conan` folder. But my conan package source code and the consuming project code both reside in git repos which will be downloaded by other developers. What effect would `settings.yml` have then? – Farahi Oct 27 '21 at 14:52
  • You can manage all configuration items like settings, profiles, hooks, remotes, conf, etc, with ``conan config install``. This allows to share and sync all those things across developer machines and CI machines. – drodri Oct 27 '21 at 17:15