Repository: conan-io/conan

Issue:
[question] Should `cmake_additional_variables_prefixes` generate `{{prefix}}_FOUND` and `{{prefix}}_VERSION`?
### What is your question?

In https://github.com/conan-io/conan-center-index/pull/26063, a gap in the current CMakeDeps `cmake_additional_variables_prefixes` property shows up:
* Upstream defines uppercase variants of the `FOUND` and `VERSION` variables, alongside the rest of them, so I used `cmake_additional_variables_prefixes` to generate those.
* This works great, up until the point where any of the `FOUND`/`VERSION` variables is used. Conan does not generate them by default, leaving CMake to do it on its own

But a issue arises as `cmake_additional_variables_prefixes` does not generate extra versions of `FOUND` and `VERSION`, which forces me to define them in the `CMakeToolchain` to make the recipe compile

cc/ @franramirez688 

### Have you read the CONTRIBUTING guide?

- [X] I've read the CONTRIBUTING guide


Discussion:
Just to make sure, the ``_FOUND`` variables are only generated for the modules, but not for Config files:
```python
{% if is_module %}
        include(FindPackageHandleStandardArgs)
        set({{ file_name }}_FOUND 1)
```
Is this issue related to modules? Does curl uses zstd by default using a module and not a config.cmake file?
The issue is quite widely applicable, I would say. There's a number of recipes on CCI that export a CMake config and also upper-case CMake vars:
- [armadillo](https://github.com/conan-io/conan-center-index/blob/4efceac27ba196eecfdc46a2c33f160e4ae9c65e/recipes/armadillo/all/conanfile.py#L277)
- [bullet3](https://github.com/conan-io/conan-center-index/blob/3fb408360d68e044c15a312368297fb915ea16a2/recipes/bullet3/all/conanfile.py#L111)
- [ceres-solver](https://github.com/conan-io/conan-center-index/blob/820caa09286da3bece144fa048d34becf0afc2e5/recipes/ceres-solver/all/conanfile.py#L190)
- [freetype](https://github.com/conan-io/conan-center-index/blob/f8968bc222c8effd238145574a5e1388e2729a48/recipes/freetype/all/conanfile.py#L197)
- [gnutls](https://github.com/conan-io/conan-center-index/blob/907566c43fa3ca9d9b557ac36dcef66f45de6825/recipes/gnutls/all/conanfile.py#L165)
- [jasper](https://github.com/conan-io/conan-center-index/blob/32afcc5104da40da6d68d4854050ea571e310377/recipes/jasper/all/conanfile.py#L109)
- [libgeotiff](https://github.com/conan-io/conan-center-index/blob/3714523d7e8505d15bf04563fb444f5889ff9be3/recipes/libgeotiff/all/conanfile.py#L84)
- [ncurses](https://github.com/conan-io/conan-center-index/blob/e149e5799e85ab72a3e2442481ca272a7f3be9a8/recipes/ncurses/all/cmake/conan-official-ncurses-targets.cmake#L2)
- [openal](https://github.com/conan-io/conan-center-index/blob/e632033a4731f550f9c1e88c8c295cb887c90d3b/recipes/openal/all/conanfile.py#L124)
- [openal-soft](https://github.com/conan-io/conan-center-index/blob/f9857f420dc1c6dcb480087317f4463c57af2adf/recipes/openal-soft/all/conanfile.py#L115)
- [openjpeg](https://github.com/conan-io/conan-center-index/blob/06810c49553ef32bc841cad062ec751ead6ed022/recipes/openjpeg/all/conanfile.py#L104)
- [openscenegraph](https://github.com/conan-io/conan-center-index/blob/0992b51e2fe337e594f2c57bf6c01ee4d733165a/recipes/openscenegraph/all/conan-official-osg-variables.cmake#L6)
- [openssl](https://github.com/conan-io/conan-center-index/blob/ded30bad06df7d6780ab111d849ed4d999467376/recipes/openssl/3.x.x/conanfile.py#L582)
- [osgearth](https://github.com/conan-io/conan-center-index/blob/a5c72115f31af2e4e442497ed1bf33eca88cbb21/recipes/osgearth/all/CMakeLists.txt#L26)
- [xapian-core](https://github.com/conan-io/conan-center-index/blob/2951f07531c537efd3fd16dda122dced7b932f6b/recipes/xapian-core/all/conanfile.py#L172)
- [xz_utils](https://github.com/conan-io/conan-center-index/blob/3c02bbbd21224bbf3d362a3d00e2f1103d80be0b/recipes/xz_utils/all/conanfile.py#L183)

Also, a sizable fraction of patches on CCI are for injecting Conan dependencies into CMake projects, where the project does something like `find_package(Eigen ...)` and then continues to use it like `if(EIGEN_FOUND) ...`. It could be worked around by setting `deps.set_property("eigen", "cmake_find_mode", "module")`, but it would be great if that could be avoided.

On the other hand, generating `XYZ_FOUND` and `XYZ_VERSION` might indeed be somewhat difficult for CMakeDeps, since it's something that is handled by CMake itself, usually.



Patch:
diff --git a/conan/tools/cmake/cmakedeps/templates/config.py b/conan/tools/cmake/cmakedeps/templates/config.py
index 1fc1d61d12e..f7e9fe1ba60 100644
--- a/conan/tools/cmake/cmakedeps/templates/config.py
+++ b/conan/tools/cmake/cmakedeps/templates/config.py
@@ -112,5 +112,12 @@ def template(self):
                                           REQUIRED_VARS {{ file_name }}_VERSION
                                           VERSION_VAR {{ file_name }}_VERSION)
         mark_as_advanced({{ file_name }}_FOUND {{ file_name }}_VERSION)
+
+        {% for prefix in additional_variables_prefixes %}
+        set({{ prefix }}_FOUND 1)
+        set({{ prefix }}_VERSION "{{ version }}")
+        mark_as_advanced({{ prefix }}_FOUND {{ prefix }}_VERSION)
+        {% endfor %}
+
         {% endif %}
         """)


Test patch:
diff --git a/test/integration/toolchains/cmake/cmakedeps/test_cmakedeps.py b/test/integration/toolchains/cmake/cmakedeps/test_cmakedeps.py
index 43e203488ff..457300b91bd 100644
--- a/test/integration/toolchains/cmake/cmakedeps/test_cmakedeps.py
+++ b/test/integration/toolchains/cmake/cmakedeps/test_cmakedeps.py
@@ -715,6 +715,7 @@ def test_cmakedeps_set_legacy_variable_name():
     conanfile = base_conanfile + """
     def package_info(self):
         self.cpp_info.set_property("cmake_file_name", "CMakeFileName")
+        self.cpp_info.set_property("cmake_find_mode", "both")
     """
     client.save({"dep/conanfile.py": conanfile})
     client.run("create dep")
@@ -725,6 +726,9 @@ def package_info(self):
     cmake_variables = ["VERSION_STRING", "INCLUDE_DIRS", "INCLUDE_DIR", "LIBRARIES", "DEFINITIONS"]
     for variable in cmake_variables:
         assert f"CMakeFileName_{variable}" in dep_config
+    dep_find = client.load("FindCMakeFileName.cmake")
+    for variable in cmake_variables:
+        assert f"CMakeFileName_{variable}" in dep_find
 
     consumer_conanfile = textwrap.dedent("""
         from conan import ConanFile
@@ -752,6 +756,16 @@ def generate(self):
         assert f"PREFIX_{variable}" in dep_config
         assert f"prefix_{variable}" in dep_config
 
+    dep_find = client.load(os.path.join("consumer", "FindCMakeFileName.cmake"))
+    for variable in cmake_variables:
+        assert f"CMakeFileName_{variable}" in dep_find
+        assert f"PREFIX_{variable}" in dep_find
+        assert f"prefix_{variable}" in dep_find
+    assert "set(prefix_FOUND 1)" in dep_find
+    assert "set(PREFIX_FOUND 1)" in dep_find
+    assert 'set(prefix_VERSION "1.0")' in dep_find
+    assert 'set(PREFIX_VERSION "1.0")' in dep_find
+
     conanfile = base_conanfile + """
     def package_info(self):
         self.cpp_info.set_property("cmake_file_name", "NewCMakeFileName")
@@ -901,10 +915,10 @@ def generate(self):
              """)})
     tc.run("create dep")
     tc.run("install .")
-    targetsData = tc.load("depTargets.cmake")
-    assert "add_library(dep::dep" in targetsData
-    assert "add_library(alias" in targetsData
-    assert "add_library(dep::other_name" in targetsData
+    targets_data = tc.load("depTargets.cmake")
+    assert "add_library(dep::dep" in targets_data
+    assert "add_library(alias" in targets_data
+    assert "add_library(dep::other_name" in targets_data
 
-    assert "add_library(component_alias" in targetsData
-    assert "add_library(dep::my_aliased_component" in targetsData
+    assert "add_library(component_alias" in targets_data
+    assert "add_library(dep::my_aliased_component" in targets_data