Repository: conan-io/conan

Issue:
[question] CLI command to discover the cmake_find_package filename from the Conan package name?
The `cmake_find_package` generator writes a Find Module file that defines a target in a namespace. Each of these three names (filename, namespace, target) are [configurable](https://github.com/conan-io/conan/issues/7254) in `cpp_info`. For example,

```python
        self.cpp_info.filename['cmake_find_package'] = 'BoostFile'
        self.cpp_info.names['cmake_find_package'] = 'BoostNamespace'
        self.cpp_info.name = 'BoostTarget'
```

will generate a file named `FindBoostFile.cmake` that is used like this:

```cmake
find_package(BoostFile)
target_link_libraries(${target} BoostNamespace::BoostTarget)
```

Is there a CLI command that can print out these values given a package reference? Something like

```
$ conan inspect -a cpp_info.names.cmake_find_package boost/1.73.0@
```


Discussion:
I think this should be updated in the ``markdown`` generator: https://docs.conan.io/en/latest/reference/generators/markdown.html
(up to my knowledge this ``markdown`` generator has not been updated yet to account for these changes)

Using it would be:

```
$ conan install boost/1.73.0@ -g=markdown
```
And you get the file with the instructions for the different generators. 
That's ok for a human, but I'm looking for something that can be easily consumed by a script.
Ok, lets add that data to the ``json`` generator, something like from:

```json
  "dependencies": [
    {
      "version": "1.2.11",

      "exelinkflags": [],
      "frameworks": [],
      "framework_paths": [],
      "cppflags": [],
      "name": "zlib"
    }
  ],
```
Add:
```json
  "dependencies": [
    {
      "version": "1.2.11",

      "exelinkflags": [],
      "frameworks": [],
      "framework_paths": [],
      "cppflags": [],
      "name": "zlib"
      "names": {"cmake_find_package": "xxxx", "pkg_config": "yyyy"}
      "filenames": {"cmake_find_package": "zzzz"}
    }
  ],
```


Resolving patch:
diff --git a/conans/client/generators/json_generator.py b/conans/client/generators/json_generator.py
--- a/conans/client/generators/json_generator.py
+++ b/conans/client/generators/json_generator.py
@@ -13,7 +13,7 @@ def serialize_cpp_info(cpp_info):
         "libs",
         "system_libs",
         "defines", "cflags", "cxxflags", "sharedlinkflags", "exelinkflags",
-        "frameworks", "framework_paths"
+        "frameworks", "framework_paths", "names", "filenames"
     ]
     res = {}
     for key in keys:
diff --git a/conans/client/generators/markdown.py b/conans/client/generators/markdown.py
--- a/conans/client/generators/markdown.py
+++ b/conans/client/generators/markdown.py
@@ -53,18 +53,21 @@
 
 generator_cmake_find_package_tpl = textwrap.dedent("""
     ### Generator ``cmake_find_package``
+    {% set cmake_find_package_name = cpp_info.get_name("cmake_find_package") %}
+    {% set cmake_find_package_filename = cpp_info.get_filename("cmake_find_package") %}
+    Generates the file Find{{ cmake_find_package_filename }}.cmake
 
     Add these lines to your *CMakeLists.txt*:
 
     ```cmake
-    find_package({{ cpp_info.get_filename("cmake_find_package") }})
+    find_package({{ cmake_find_package_filename }})
 
     # Use the global target
-    target_link_libraries(<library_name> {{ cpp_info.get_name("cmake_find_package") }}::{{ cpp_info.get_name("cmake_find_package") }})
+    target_link_libraries(<library_name> {{ cmake_find_package_name }}::{{ cmake_find_package_name }})
     {% if cpp_info.components %}
     # Or link just one of its components
     {% for cmp_name, cmp_cpp_info in cpp_info.components.items() -%}
-    target_link_libraries(<library_name> {{ cpp_info.get_name("cmake_find_package") }}::{{ cmp_cpp_info.get_name("cmake_find_package") }})
+    target_link_libraries(<library_name> {{ cmake_find_package_name }}::{{ cmp_cpp_info.get_name("cmake_find_package") }})
     {% endfor %}
     {%- endif %}
     ```


Test patch:
diff --git a/conans/test/functional/generators/json_test.py b/conans/test/functional/generators/json_test.py
--- a/conans/test/functional/generators/json_test.py
+++ b/conans/test/functional/generators/json_test.py
@@ -69,14 +69,14 @@ def test_multiconfig(self):
             class Lib(ConanFile):
                 settings = "os", "arch"
                 generators = "json"
-                
+
                 def package_info(self):
                     self.env_info.MY_ENV_VAR = "foo"
                     self.user_info.my_var = "my_value"
-                    
+
                     self.cpp_info.debug.defines = ["LIB_DEBUG"]
                     self.cpp_info.release.defines = ["LIB_RELEASE"]
-                    
+
                     self.cpp_info.debug.libs = ["Hello_d"]
                     self.cpp_info.release.libs = ["Hello"]
             """)
@@ -139,3 +139,27 @@ def package_info(self):
         my_json = json.loads(my_json)
         self.assertListEqual(my_json["dependencies"][0]["libs"], ["LIB1"])
         self.assertListEqual(my_json["dependencies"][0]["system_libs"], ["SYSTEM_LIB1"])
+
+    def test_generate_json_filenames(self):
+        conanfile = textwrap.dedent("""
+            from conans import ConanFile
+            class HelloConan(ConanFile):
+                def package_info(self):
+                    self.cpp_info.filenames['cmake_find_package'] = 'FooBar'
+                    self.cpp_info.names['cmake_find_package'] = 'foobar'
+                    self.cpp_info.names['cmake_find_package_multi'] = 'foobar_multi'
+                    self.cpp_info.names['pkg_config'] = 'foobar_cfg'
+            """)
+        client = TestClient()
+        client.save({"conanfile.py": conanfile})
+        client.run("create . bar/0.1.0@user/testing")
+        client.run("install bar/0.1.0@user/testing -g json")
+        conan_json = client.load("conanbuildinfo.json")
+        content = json.loads(conan_json)
+
+        deps = content["dependencies"][0]
+        self.assertEqual("foobar", deps["names"]["cmake_find_package"])
+        self.assertEqual("foobar_multi", deps["names"]["cmake_find_package_multi"])
+        self.assertEqual("foobar_cfg", deps["names"]["pkg_config"])
+        self.assertEqual("FooBar", deps["filenames"]["cmake_find_package"])
+        self.assertEqual("bar", deps["name"])
diff --git a/conans/test/functional/generators/markdown_test.py b/conans/test/functional/generators/markdown_test.py
new file mode 100644
--- /dev/null
+++ b/conans/test/functional/generators/markdown_test.py
@@ -0,0 +1,27 @@
+import textwrap
+import unittest
+
+from conans.test.utils.tools import TestClient
+from conans.client.tools.files import load
+
+
+class MarkDownGeneratorTest(unittest.TestCase):
+
+    def test_cmake_find_filename(self):
+        conanfile = textwrap.dedent("""
+                    from conans import ConanFile
+                    class HelloConan(ConanFile):
+                        def package_info(self):
+                            self.cpp_info.filenames['cmake_find_package'] = 'FooBar'
+                            self.cpp_info.names['cmake_find_package'] = 'foobar'
+                            self.cpp_info.names['cmake_find_package_multi'] = 'foobar_multi'
+                            self.cpp_info.names['pkg_config'] = 'foobar_cfg'
+                    """)
+        client = TestClient()
+        client.save({"conanfile.py": conanfile})
+        client.run("create . bar/0.1.0@user/testing")
+        client.run("install bar/0.1.0@user/testing -g markdown")
+        content = client.load("bar.md")
+
+        self.assertIn("Generates the file FindFooBar.cmake", content)
+        self.assertIn("find_package(FooBar)", content)