diff --git a/docs/how_to_add_packages.md b/docs/how_to_add_packages.md index d9991b038412c..c27f81ca28d44 100644 --- a/docs/how_to_add_packages.md +++ b/docs/how_to_add_packages.md @@ -202,6 +202,29 @@ pacman, brew, choco) and install packages which are missing on Conan Center but As example there are [glu](https://github.com/conan-io/conan-center-index/blob/master/recipes/glu/all/conanfile.py) and [OpenGL](https://github.com/conan-io/conan-center-index/blob/master/recipes/opengl/all/conanfile.py). Also, it will require an exception rule for [conan-center hook](https://github.com/conan-io/hooks#conan-center), a [pull request](https://github.com/conan-io/hooks/pulls) should be open to allow it over the KB-H032. +### Verifying Dependency Version + +Some project requirements need to respect a version constraint. This can be enforced in a recipe by accessing the [`deps_cpp_info`](https://docs.conan.io/en/latest/reference/conanfile/attributes.html#deps-cpp-info) attribute. +An exaple of this can be found in the [spdlog recipe](https://github.com/conan-io/conan-center-index/blob/9618f31c4d9b4da5d06f905befe9691cf105a1fc/recipes/spdlog/all/conanfile.py#L92-L94). + +```py +if tools.Version(self.deps_cpp_info["liba"].version) < "7": + raise ConanInvalidConfiguration(f"The project {self.name}/{self.version} requires liba > 7.x") +``` + +In Conan version 1.x this needs to be done in the `build` method, in future release is should be done in the `validate` method. + +### Verifying Dependency Options + +Certain projects are dependant on the configuration (a.k.a options) of a dependency. This can be enforced in a recipe by accessing the [`options`](https://docs.conan.io/en/latest/reference/conanfile/attributes.html#options) attribute. +An example of this can be found in the [kealib recipe](https://github.com/conan-io/conan-center-index/blob/9618f31c4d9b4da5d06f905befe9691cf105a1fc/recipes/kealib/all/conanfile.py#L44-L46). + +```py + def validate(self): + if not self.options["liba"].enable_feature: + raise ConanInvalidConfiguration(f"The project {self.name}/{self.version} requires liba.enable_feature=True.") +``` + ## Test the recipe locally The system will use the [conan-center hook](https://github.com/conan-io/hooks) to perform some quality checks. You can install the hook running: