Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation for components and cmake_find_package generator #1722

Merged
merged 3 commits into from
Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions creating_packages/package_information.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,30 @@ Declaration of requires from other packages is also allowed:
...
requires = "zlib/1.2.11", "openssl/1.1.1g"

def package_info(self):
self.cpp_info.components["comp1"].requires = ["zlib::zlib"] # Depends on all components in zlib package
self.cpp_info.components["comp2"].requires = ["comp1", "openssl::ssl"] # Depends on ssl component in openssl package
def package_info(self):
self.cpp_info.components["comp1"].requires = ["zlib::zlib"] # Depends on all components in zlib package
self.cpp_info.components["comp2"].requires = ["comp1", "openssl::ssl"] # Depends on ssl component in openssl package

By default, components **won't link against any other package required by the recipe**. The requires list has to be **populated explicitly**
with the list of components from other packages to use: it can be the full requirement (``zlib::zlib``) or a single component
(``openssl::ssl``).

.. important::

Components information is still not available from the generators' side. We are planning to complete this feature in next releases.
The information of components is aggregated to the *global* ``cpp_info`` scope and the usage of components should be transparent.

Consumers can get this information via ``self.deps_cpp_info`` as usual and use it in the ``build()`` method of any dependent recipe:

.. code-block:: python

class PocoTimerConan(ConanFile):
...
requires = "zlib/1.2.11", "openssl/1.0.2u"
...

Currently, the information of components is not lost but aggregated to the *global* scope and the usage of components should be
transparent right now.
def build(self):
# Get the include directories of the SSL component of openssl package
self.deps_cpp_info["openssl"].components["ssl"].include_paths

.. seealso::

Expand Down
4 changes: 3 additions & 1 deletion reference/conanfile/attributes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,9 @@ absolute paths, and ``name`` and ``version`` attributes:
+-----------------------------------------------+---------------------------------------------------------------------+
| self.deps_cpp_info["dep"].version | Get the version of the "dep" package |
+-----------------------------------------------+---------------------------------------------------------------------+
| self.deps_cpp_info["dep"].components | | **[Experimental]** Dictionary with different components a package |
| | | may have: libraries, executables... |
+-----------------------------------------------+---------------------------------------------------------------------+

To get a list of all the dependency names from ```deps_cpp_info```, you can call the `deps` member:

Expand Down Expand Up @@ -1023,7 +1026,6 @@ root folder of the package:
# Get the sharedlinkflags property from OpenSSL package
self.deps_cpp_info["openssl"].sharedlinkflags


.. _env_info_attributes_reference:

env_info
Expand Down
19 changes: 17 additions & 2 deletions reference/generators/cmake_find_package.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ utilities exported by the package available for consumers just by setting `find_
Moreover, this also adjusts `CMAKE_MODULE_PATH` and `CMAKE_PREFIX_PATH` to the values declared by the package in ``cpp_info.buildirs``, so
modules in those directories can be found.

Target in Find<PKG-NAME>.cmake
------------------------------
Targets in Find<PKG-NAME>.cmake
-------------------------------

A target named ``<PKG-NAME>::<PKG-NAME>`` target is generated with the following properties adjusted:

Expand All @@ -67,3 +67,18 @@ A target named ``<PKG-NAME>::<PKG-NAME>`` target is generated with the following
The targets are transitive. So, if your project depends on a packages ``A`` and ``B``, and at the same time
``A`` depends on ``C``, the ``A`` target will contain automatically the properties of the ``C`` dependency, so
in your `CMakeLists.txt` file you only need to ``find_package(A)`` and ``find_package(B)``.

Components
++++++++++

If a recipe uses components, the targets generated will be ``<PKG-NAME>::<COMP-NAME>`` with the following properties adjusted:

- ``INTERFACE_INCLUDE_DIRECTORIES``: Containing all the include directories of the component.
- ``INTERFACE_LINK_DIRECTORIES``: Containing all the lib directories of the component.
- ``INTERFACE_LINK_LIBRARIES``: Containing the targets to link the component to (includes component's libraries and dependencies).
- ``INTERFACE_COMPILE_DEFINITIONS``: Containing the definitions of the component.
- ``INTERFACE_COMPILE_OPTIONS``: Containing the compile options of the component.

Moreover, a global target ``<PKG-NAME>::<PKG-NAME>`` will be declared with the following properties adjusted:

- ``INTERFACE_LINK_LIBRARIES``: Containing all the component targets to link the global target to (includes package's components only).