Repository: conan-io/conan
Pull request: [PkgConfigDeps] Added new property `component_version`
Changelog: Feature: Added new property `component_version` for `PkgConfigDeps` and legacy `PkgConfig`.
Changelog: Feature: Changed `.pc` file description field for components in `PkgConfigDeps`.
Closes: https://github.com/conan-io/conan/issues/10629
Docs: https://github.com/conan-io/docs/pull/2433

- [x] Refer to the issue that supports this Pull Request.
- [x] If the issue has missing info, explain the purpose/use case/pain/need that covers this Pull Request.
- [x] I've read the [Contributing guide](https://github.com/conan-io/conan/blob/develop/.github/CONTRIBUTING.md).
- [x] I've followed the PEP8 style guides for Python code.
- [ ] I've opened another PR in the Conan docs repo to the ``develop`` branch, documenting this one. 

<sup>**Note:** By default this PR will skip the slower tests and will use a limited set of python versions. Check [here](https://github.com/conan-io/conan/blob/develop/.github/PR_INCREASE_TESTING.md) how to increase the testing level by writing some tags in the current PR body text.</sup>


Problem statement:
[bug] PkgConfigDeps: component version not honored
<!--
  Please don't forget to update the issue title.
  Include all applicable information to help us reproduce your problem.

  To help us debug your issue please explain:
-->

### Environment Details (include every applicable attribute)
  * Operating System+version: macOS Monterey
  * Compiler+version: apple-clang 13.0
  * Conan version: 1.45.0
  * Python version: 3.9.10

### Steps to reproduce (Include if Applicable)

- `conan install ffmpeg/4.4@ -g PkgConfigDeps`
- inspect pc files, all versions are set to 4.4 => not good
- `conan install ffmpeg/4.4@ -g pkg_config`
- inspect pc files, many versions are different because ffmpeg recipe set version of each component with a custom value => good

### Logs (Executed commands with output) (Include/Attach if Applicable)

For example here the content of `libavdevice.pc` (avdevice is a component of ffmpeg)

from `PkgConfigDeps` generator:

```
prefix=/Users/spaceim/.conan/data/ffmpeg/4.4/_/_/package/90fa4cf4928013c69bdbdd0bf4bac261ff5e5328
libdir1=${prefix}/lib
includedir1=${prefix}/include

Name: libavdevice
Description: Conan component: libavdevice
Version: 4.4
Libs: -L"${libdir1}" -lavdevice -framework CoreFoundation -framework Foundation -framework CoreGraphics -framework OpenGL -framework AppKit -framework AVFoundation -framework CoreAudio -F /Users/charpentiera/.conan/data/ffmpeg/4.4/_/_/package/90fa4cf4928013c69bdbdd0bf4bac261ff5e5328/Frameworks 
Cflags: -I"${includedir1}" 
Requires: libavutil libavfilter libswscale libavformat libavcodec libswresample libpostproc
```

from `pkg_config` generator:

```
prefix=/Users/spaceim/.conan/data/ffmpeg/4.4/_/_/package/90fa4cf4928013c69bdbdd0bf4bac261ff5e5328
libdir=${prefix}/lib
includedir=${prefix}/include

Name: ffmpeg-libavdevice
Description: Conan package: ffmpeg-libavdevice
Version: 58.13.100
Libs: -L"${libdir}" -lavdevice  -Wl,-rpath,"${libdir}" -framework CoreFoundation -framework Foundation -framework CoreGraphics -framework OpenGL -framework AppKit -framework AVFoundation -framework CoreAudio
Cflags: -I"${includedir}"
Requires: libavutil libavfilter libswscale libavformat libavcodec libswresample libpostproc
```

Hints from issue discussion:

Commit message: Added custom versions and descriptions for components

Patch to review:
diff --git a/conan/tools/gnu/pkgconfigdeps/pc_files_creator.py b/conan/tools/gnu/pkgconfigdeps/pc_files_creator.py
index 3a33bc83d5c..7a7213dbb96 100644
--- a/conan/tools/gnu/pkgconfigdeps/pc_files_creator.py
+++ b/conan/tools/gnu/pkgconfigdeps/pc_files_creator.py
@@ -33,7 +33,7 @@ def _get_aliases_pc_files_and_content(conanfile, dep, aliases_info, root_pc_file
     return pc_files
 
 
-def _get_components_pc_files_and_content(conanfile, dep, components_info):
+def _get_components_pc_files_and_content(conanfile, dep, package_info, components_info):
     """
     Get the PC files and content for dependency's components
     """
@@ -41,7 +41,7 @@ def _get_components_pc_files_and_content(conanfile, dep, components_info):
     # Loop through all the package's components
     for pc_info_component in components_info:
         # Get the *.pc file content for each component
-        description = "Conan component: %s" % pc_info_component.name
+        description = "Conan component: %s-%s" % (package_info.name, pc_info_component.name)
         pc_name, pc_content = get_pc_filename_and_content(
             conanfile,
             dep,
@@ -71,7 +71,7 @@ def _get_package_with_components_pc_files_and_content(conanfile, dep, package_in
     """
     pc_files = {}
     # First, let's load all the components PC files
-    pc_files.update(_get_components_pc_files_and_content(conanfile, dep, components_info))
+    pc_files.update(_get_components_pc_files_and_content(conanfile, dep, package_info, components_info))
     description = "Conan package: %s" % package_info.name
     pc_name, pc_content = get_alias_pc_filename_and_content(
         dep,
diff --git a/conan/tools/gnu/pkgconfigdeps/pc_files_templates.py b/conan/tools/gnu/pkgconfigdeps/pc_files_templates.py
index e1d2d937162..d3c48097b59 100644
--- a/conan/tools/gnu/pkgconfigdeps/pc_files_templates.py
+++ b/conan/tools/gnu/pkgconfigdeps/pc_files_templates.py
@@ -88,8 +88,8 @@ def _get_formatted_dirs(folders, prefix_path_):
 
 def get_pc_filename_and_content(conanfile, dep, name, requires, description, cpp_info=None):
     package_folder = dep.package_folder
-    version = dep.ref.version
     cpp_info = cpp_info or dep.cpp_info
+    version = cpp_info.get_property("pkg_config_version") or dep.ref.version
 
     prefix_path = package_folder.replace("\\", "/")
     libdirs = _get_formatted_dirs(cpp_info.libdirs, prefix_path)
diff --git a/conans/test/functional/toolchains/gnu/test_pkgconfigdeps.py b/conans/test/functional/toolchains/gnu/test_pkgconfigdeps.py
index f37f8429506..469beb7320d 100644
--- a/conans/test/functional/toolchains/gnu/test_pkgconfigdeps.py
+++ b/conans/test/functional/toolchains/gnu/test_pkgconfigdeps.py
@@ -192,7 +192,7 @@ def package_info(self):
     assert "Name: pkg" in pc_content
 
 
-def test_custom_content_components():
+def test_custom_content_and_version_components():
     conanfile = textwrap.dedent("""
         from conans import ConanFile
         from conans.tools import save
@@ -204,6 +204,8 @@ class PkgConfigConan(ConanFile):
             def package_info(self):
                 self.cpp_info.components["mycomponent"].set_property("pkg_config_custom_content",
                                                                      "componentdir=${prefix}/mydir")
+                self.cpp_info.components["mycomponent"].set_property("pkg_config_version",
+                                                                     "19.8.199")
         """)
     client = TestClient()
     client.save({"conanfile.py": conanfile})
@@ -211,6 +213,7 @@ def package_info(self):
     client.run("install pkg/0.1@ -g PkgConfigDeps")
     pc_content = client.load("pkg-mycomponent.pc")
     assert "componentdir=${prefix}/mydir" in pc_content
+    assert "Version: 19.8.199" in pc_content
 
 
 def test_pkg_with_public_deps_and_component_requires():
@@ -419,7 +422,7 @@ def package_info(self):
     client.run("install .")
 
     pc_content = client.load("compo1.pc")
-    assert "Description: Conan component: compo1" in pc_content
+    assert "Description: Conan component: pkg_other_name-compo1" in pc_content
     assert "Requires" not in pc_content
 
     pc_content = client.load("compo1_alias.pc")


Code review comments:
diff_hunk: @@ -88,8 +88,8 @@ def _get_formatted_dirs(folders, prefix_path_):
 
 def get_pc_filename_and_content(conanfile, dep, name, requires, description, cpp_info=None):
     package_folder = dep.package_folder
-    version = dep.ref.version
     cpp_info = cpp_info or dep.cpp_info
+    version = cpp_info.get_property("pkg_config_version") or dep.ref.version
path: conan/tools/gnu/pkgconfigdeps/pc_files_templates.py
text: @user1:
better ``component_version`` just in case some other build system wants it too.