0

I'm new to conan and I've been going through several youtube videos for Conan and what I'm not clear about how the consumer of the library will know where the library will be hosted. It's an open source c project hosted on github let's say at github.com/username/foo

MyLibrary conanfile.py looks like this

from conans import ConanFile

class Foo(ConanFile):
    def build(self):
        cmake = CMake(self)
        cmake.configure(source_dir="src")
        cmake.build()
        cmake.install()

I understand this conanfile.py should be on the root of my github project.


Users of the Library

I found this file from somewhere that users of the library should having in their root directory.

[requires]
folly/2019.10.21.00

[generators]
cmake
  1. What is folly/2019.10.21.00 in this case?
  2. How my consumer conanfile.txt of MyLibrary should look like?
  3. Please also review my producer file.
  4. Essentially how can I distribute my library

Edit:

for 1) I found the answer here but how do I specify about the github link I've.

AppDeveloper
  • 1,816
  • 7
  • 24
  • 49

2 Answers2

0

I'm not clear about how the consumer of the library will know where the library will be hosted.

The library is downloaded under source method. It's documented here and here

If you want to develop a recipe, I recommend you reading Creating Packages section on docs.

What is folly/2019.10.21.00 in this case? It's the package reference, please, read the Getting Started section.

How my consumer conanfile.txt of MyLibrary should look like?

Basically, it should contain your package reference, and that's it. Please, read conanfile.txt section.

Essentially how can I distribute my library

You have two main options, locally, most common for companies, and globally, usually for Open Source projects.

Uploading Remotes

Uploading to Bintray (global)

Uploading to Artifactory (locally)

As you are starting on Conan right now, please, read carefully the getting started section and follow the guide, it's well explained and also contains a good exercise which helps to understand how Conan works.

After been confident consuming a recipe, I recommend you reading the Creating Packages section, which contains information from the provider perspective.

Reading the documentation is best way to learn, jumping steps will make you more confuse about some features.

Also, there is a good channel for help and discussion on Slack, the channel name is #conan.

uilianries
  • 3,363
  • 15
  • 28
  • Thanks for the explanation, can you please append your answer with a solution, I've posted an answer for that. – AppDeveloper May 20 '20 at 14:29
  • I think they are different questions, I prefer keeping then separated. Anyway, I can't confirm if your recipe is working, but the template is okay. And again, all those information are listed in the links that posted before. – uilianries May 20 '20 at 16:09
0

Can please edit and append it to your answer. Basically I'm looking for a complete solution. Is following correct?

Producer

from conans import ConanFile

class Foo(ConanFile):
    name = "foo"
    version = "0.1"
    license = "MIT"
    url = "https://github.com/username/foo.git"
    description = "My Open Source Library"
    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/username/foo.git")
        tools.replace_in_file("foo/CMakeLists.txt", "PROJECT(MyLibrary)",
                              '''PROJECT(MyLibrary)
        include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
        conan_basic_setup()''')

    def build(self):
        cmake = CMake(self)
        cmake.configure(source_dir="src")
        cmake.build()
        cmake.install()

    def package(self):
        self.copy("*.h", dst="include", src="src")
        self.copy("*hello.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"]

Consumer place following files at the root of the package.

conanfile.py

from conans import ConanFile

class MyConsumer(ConanFile):

    def source(self):
        self.run("git clone https://github.com/username/foo.git")

conanfile.txt

[requires]
foo/1.0.0

Then run

conan install ..
cmake ..
cmake --build .
AppDeveloper
  • 1,816
  • 7
  • 24
  • 49