c++cmakeconancl

What is the difference between conanfile.py, conanfile.txt, conanprofile and settings.yml?


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:

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?


Solution

  • The files are:

    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