From e25ff3e1cb9f986de6ef1a47bd4025f20b7dc11c Mon Sep 17 00:00:00 2001 From: czoido Date: Tue, 27 Apr 2021 18:42:39 +0200 Subject: [PATCH 1/8] add docs --- reference/conanfile/attributes.rst | 72 ++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/reference/conanfile/attributes.rst b/reference/conanfile/attributes.rst index 26f6377fddf..a45b8749e40 100644 --- a/reference/conanfile/attributes.rst +++ b/reference/conanfile/attributes.rst @@ -1028,6 +1028,78 @@ has **the same default directories**. Dependencies among components and to components of other requirements can be defined using the ``requires`` attribute and the name of the component. The dependency graph for components will be calculated and values will be aggregated in the correct order for each field. +There is a new way of setting and accessing ``filenames``, ``names`` and ``build_modules`` starting +in Conan 1.36 using new ``set_property`` and ``get_property`` methods of the ``cpp_info`` object: + +.. code-block:: python + + def set_property(self, property_name, value, generator=None) + def get_property(self, property_name, generator=None): + +New properties ``cmake_target_name``, ``cmake_file_name``, ``pkg_config_name`` and +``cmake_build_modules`` are defined to allow migrating ``names``, ``filenames`` and ``build_modules`` +properties to this model. +In Conan 2.0 this will be the default way of setting these properties and also passing custom +properties to generators. + +For example, setting some cpp_info properties with the current model: + +.. code-block:: python + + def package_info(self): + ... + self.cpp_info.filenames["cmake_find_package"] = "MyFileName" + self.cpp_info.filenames["cmake_find_package_multi"] = "MyFileName" + self.cpp_info.components["mycomponent"].names["cmake_find_package"] = "mycomponent-name" + self.cpp_info.components["mycomponent"].names["cmake_find_package_multi"] = "mycomponent-name" + self.cpp_info.components["mycomponent"].build_modules.append(os.path.join("lib", "mypkg_bm.cmake")) + ... + self.cpp_info.components["mycomponent"].names["pkg_config"] = "mypkg-config-name" + +Could be declared like this in the new one: + +.. code-block:: python + + def package_info(self): + ... + self.cpp_info.set_property("cmake_file_name", "MyFileName") + self.cpp_info.components["mycomponent"].set_property("cmake_target_name", "mycomponent-name") + self.cpp_info.components["mycomponent"].set_property("cmake_build_modules", [os.path.join("lib", "mypkg_bm.cmake")]) + self.cpp_info.components["mycomponent"].set_property("custom_name", "mycomponent-name", "custom_generator") + ... + self.cpp_info.components["mycomponent"].set_property("pkg_config_name", "mypkg-config-name") + +New properties defined: +- **cmake_file_name** property will affect all cmake generators that accept the ``filenames`` +property (``cmake_find_package`` and ``cmake_find_package_multi``). +- **cmake_target_name** property will affect all cmake generators that accept the ``names`` +property (``cmake``, ``cmake_multi``, ``cmake_find_package``, ``cmake_find_package_multi`` and ``cmake_paths``). +- **cmake_build_modules** property will replace the ``build_modules`` property. +- **pkg_config_name** property will set the ``names`` property for ``pkg_config`` generator. + +There's also a new property called ``pkg_config_custom_content`` defined for the ``pkg_config`` +generator that can be set and will add user defined content to the files created by this generator. + +.. code-block:: python + + def package_info(self): + custom_content = textwrap.dedent(\""" + datadir=${prefix}/share + schemasdir=${datadir}/mylib/schemas + bindir=${prefix}/bin + \""") + self.cpp_info.set_property("pkg_config_custom_content", custom_content) + +All of these properties, but ``cmake_file_name`` can be defined at global ``cpp_info`` level or at +component level. + +.. warning:: + + Using ``set_property`` and ``get_property`` is a **experimental** feature subject to breaking + changes in future releases. Although this is an experimental feature, the use of the feature + using ``scm_to_conandata`` is considered stable. + + .. seealso:: Read :ref:`package_information_components` and :ref:`method_package_info` to learn more. From b7d46fa6897fd8806793773c792e67333847f039 Mon Sep 17 00:00:00 2001 From: czoido Date: Tue, 27 Apr 2021 18:52:54 +0200 Subject: [PATCH 2/8] fix format --- reference/conanfile/attributes.rst | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/reference/conanfile/attributes.rst b/reference/conanfile/attributes.rst index a45b8749e40..807775a7d2d 100644 --- a/reference/conanfile/attributes.rst +++ b/reference/conanfile/attributes.rst @@ -1070,12 +1070,13 @@ Could be declared like this in the new one: self.cpp_info.components["mycomponent"].set_property("pkg_config_name", "mypkg-config-name") New properties defined: + - **cmake_file_name** property will affect all cmake generators that accept the ``filenames`` -property (``cmake_find_package`` and ``cmake_find_package_multi``). -- **cmake_target_name** property will affect all cmake generators that accept the ``names`` -property (``cmake``, ``cmake_multi``, ``cmake_find_package``, ``cmake_find_package_multi`` and ``cmake_paths``). + property (*cmake_find_package* and *cmake_find_package_multi*). +- **cmake_target_name** property will affect all cmake generators that accept the ``names`` property + (*cmake*, *cmake_multi*, *cmake_find_package*, *cmake_find_package_multi* and *cmake_paths*). - **cmake_build_modules** property will replace the ``build_modules`` property. -- **pkg_config_name** property will set the ``names`` property for ``pkg_config`` generator. +- **pkg_config_name** property will set the ``names`` property for *pkg_config* generator. There's also a new property called ``pkg_config_custom_content`` defined for the ``pkg_config`` generator that can be set and will add user defined content to the files created by this generator. From d3f824b4dbe355c4e0690e2a86efcd7bf41285c2 Mon Sep 17 00:00:00 2001 From: czoido Date: Tue, 27 Apr 2021 18:56:03 +0200 Subject: [PATCH 3/8] minor changes --- reference/conanfile/attributes.rst | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/reference/conanfile/attributes.rst b/reference/conanfile/attributes.rst index 807775a7d2d..271ff10e389 100644 --- a/reference/conanfile/attributes.rst +++ b/reference/conanfile/attributes.rst @@ -1084,11 +1084,7 @@ generator that can be set and will add user defined content to the files created .. code-block:: python def package_info(self): - custom_content = textwrap.dedent(\""" - datadir=${prefix}/share - schemasdir=${datadir}/mylib/schemas - bindir=${prefix}/bin - \""") + custom_content = "datadir=${prefix}/share" self.cpp_info.set_property("pkg_config_custom_content", custom_content) All of these properties, but ``cmake_file_name`` can be defined at global ``cpp_info`` level or at From c21352282dfdf75b237f54ad7ab30b8caf2dad95 Mon Sep 17 00:00:00 2001 From: czoido Date: Tue, 27 Apr 2021 18:56:51 +0200 Subject: [PATCH 4/8] minor format changes --- reference/conanfile/attributes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference/conanfile/attributes.rst b/reference/conanfile/attributes.rst index 271ff10e389..213d3699f5a 100644 --- a/reference/conanfile/attributes.rst +++ b/reference/conanfile/attributes.rst @@ -1078,7 +1078,7 @@ New properties defined: - **cmake_build_modules** property will replace the ``build_modules`` property. - **pkg_config_name** property will set the ``names`` property for *pkg_config* generator. -There's also a new property called ``pkg_config_custom_content`` defined for the ``pkg_config`` +There's also a new property called ``pkg_config_custom_content`` defined for the *pkg_config* generator that can be set and will add user defined content to the files created by this generator. .. code-block:: python From 12f327e185b7ba988a622936e4b3f64326313e62 Mon Sep 17 00:00:00 2001 From: czoido Date: Tue, 27 Apr 2021 18:58:07 +0200 Subject: [PATCH 5/8] minor changes --- reference/conanfile/attributes.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/reference/conanfile/attributes.rst b/reference/conanfile/attributes.rst index 213d3699f5a..2386cc9835b 100644 --- a/reference/conanfile/attributes.rst +++ b/reference/conanfile/attributes.rst @@ -1093,8 +1093,7 @@ component level. .. warning:: Using ``set_property`` and ``get_property`` is a **experimental** feature subject to breaking - changes in future releases. Although this is an experimental feature, the use of the feature - using ``scm_to_conandata`` is considered stable. + changes in future releases. .. seealso:: From c253538039369bd3215e32fdf31dd98322f8fee7 Mon Sep 17 00:00:00 2001 From: czoido Date: Tue, 27 Apr 2021 18:59:24 +0200 Subject: [PATCH 6/8] minor fix --- reference/conanfile/attributes.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reference/conanfile/attributes.rst b/reference/conanfile/attributes.rst index 2386cc9835b..17debfa82ff 100644 --- a/reference/conanfile/attributes.rst +++ b/reference/conanfile/attributes.rst @@ -1092,8 +1092,8 @@ component level. .. warning:: - Using ``set_property`` and ``get_property`` is a **experimental** feature subject to breaking - changes in future releases. + Using ``set_property`` and ``get_property`` methods for ``cpp_info`` is an **experimental** + feature subject to breaking changes in future releases. .. seealso:: From 6b0841e0358be528c601a0e342c0dadd41310d32 Mon Sep 17 00:00:00 2001 From: Carlos Zoido Date: Wed, 28 Apr 2021 08:27:48 +0200 Subject: [PATCH 7/8] Update reference/conanfile/attributes.rst Co-authored-by: James --- reference/conanfile/attributes.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/reference/conanfile/attributes.rst b/reference/conanfile/attributes.rst index 17debfa82ff..06731f7db60 100644 --- a/reference/conanfile/attributes.rst +++ b/reference/conanfile/attributes.rst @@ -1042,6 +1042,7 @@ properties to this model. In Conan 2.0 this will be the default way of setting these properties and also passing custom properties to generators. +For most cases, it is recommended not to use the ``generator`` argument. The properties are generic for build systems, and different generators that integrate with a given build system could be reading such generic properties. For example, setting some cpp_info properties with the current model: .. code-block:: python From a6753d23d96001d402272408b76a327b6edb9327 Mon Sep 17 00:00:00 2001 From: Carlos Zoido Date: Wed, 28 Apr 2021 08:29:14 +0200 Subject: [PATCH 8/8] Update reference/conanfile/attributes.rst --- reference/conanfile/attributes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference/conanfile/attributes.rst b/reference/conanfile/attributes.rst index 06731f7db60..afdd9a301a4 100644 --- a/reference/conanfile/attributes.rst +++ b/reference/conanfile/attributes.rst @@ -1080,7 +1080,7 @@ New properties defined: - **pkg_config_name** property will set the ``names`` property for *pkg_config* generator. There's also a new property called ``pkg_config_custom_content`` defined for the *pkg_config* -generator that can be set and will add user defined content to the files created by this generator. +generator that will add user defined content to the *.pc* files created by this generator. .. code-block:: python