conan.io - header only package

c++, conan

Solution

Just a minor clarification, I guess you meant that library foo is required by bar.

Every package has to be created, even if it is a header only library. When you `conan export` it copies the source code into the recipe (the other alternative would be using the `source()` method to retrieve the source code), but the package still has to be created.

The `build()` method is not necessary, as there is nothing to build, but you should add the `package()` method to your recipe, something like:

def package(self):
   self.copy("*.h", dst="include", src="include")

Then you have to create the package. This can be done with several methods, one would be to install the foo package:

$ conan install foo/0.0.1@steazzalini/testing --build

But this is typically not necessary, as you can also build it when calling the install from the consumer project (the bar one):

$ conan install . --build

There is also an option, the `build_policy` that can be added to recipes, and is well suited for header only libraries. It can be `missing` or `always`. The latter is useful when creating packages from the latest git (master/head..) commit of a project. Using this policy, the consumers doesn't have to explicitely call `--build` to specify that the package has to be created. So the recipe could be something like:

from conans import ConanFile, CMake

class FooConan(ConanFile):
    name = "foo"
    version = "0.0.1"
    exports = "*"
    build_policy = "missing"

    def package(self):
       self.copy("*.h", dst="include", src="include")

Finally, you might be interested in the `$ conan new foo/0.0.1@steazzalini/testing -i` command, that will create a `conanfile.py` for you with some of these things. The `-t` option for such command is useful to create a `test_package`, a utility for creating and testing packages, to ensure the package is correct. Have a look at http://docs.conan.io/en/latest/packaging/testing.html#automatically-creating-and-testing-packages

UPDATE: conan docs got a new section specific for header-only libraries: http://docs.conan.io/en/latest/howtos/header_only.html

Problem

I'm trying to create a simple demo header only library called foo and require it another library called bar. The structure of foo is this: foo/include/foo.hpp - just a test header file... foo/conanfile.py ``` from conans import ConanFile, CMake class FooConan(ConanFile): name = "foo" version = "0.0.1" exports = "*" ``` export it using: ``` conan export steazzalini/testing ``` bar/conanfile.txt ``` [requires] foo/0.0.1@steazzalini/testing [generators] cmake ``` conan install fails saying: ``` ERROR: Can't find a 'foo/0.0.1@steazzalini/testing' package for the specified options and settings - Try to build from sources with "--build foo" parameter - If it fails, you could try to contact the package author , report your configuration and try to collaborate to support it. Package configuration: - Settings: - Options: ``` Thanks in advance for the help!

Original source