Repository: conan-io/conan-center-index

Issue:
[package] gtest/1.11.0: CMakeDeps + Conan 1.42 uses incorrect names for CMake config file, namespace, and gtest component
### Package and Environment Details (include every applicable attribute)
  * Package Name/Version: **gtest/3.1.0**
  * Operating System+version: **Fedora Silverblue 35**
  * Compiler+version: **GCC 11**
  * Conan version: **conan 1.42.0**
  * Python version: **Python 3.10.0**


### Conan profile (output of `conan profile show default` or `conan profile show <profile>` if custom profile is in use)
```
[settings]
os=Linux
arch=x86_64
compiler=gcc
compiler.version=11
compiler.libcxx=libstdc++11
compiler.cppstd=17
build_type=Debug
[options]
[conf]
[build_requires]
[env]
```


### Steps to reproduce (Include if Applicable)

Use the `CMakeToolchain` / `CMakeDeps` generator for a project and add `ms-gsl` as a `requires`.
In your `CMakeLists.txt` use `find_package(GTest)` and it will not be found during CMake's configure stage.
This is because the package is now named `gtest` instead, which is unexpected.
I don't think the component name for `libgtest` or the namespace for the CMake targets will be correct now either for the CMakeDeps generator.

### Logs (Include/Attach if Applicable)
<details><summary>Click to expand log</summary>

```
CMake Error at src/CMakeLists.txt:21 (add_executable):
  Target "TestDriver" links to target "GTest::gtest_main" but the target was
  not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?
CMake Error at src/CMakeLists.txt:21 (add_executable):
  Target "TestDriver" links to target "GTest::gtest_main" but the target was
  not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?
```

</details>



Discussion:

Resolving patch:
diff --git a/recipes/gtest/all/conanfile.py b/recipes/gtest/all/conanfile.py
--- a/recipes/gtest/all/conanfile.py
+++ b/recipes/gtest/all/conanfile.py
@@ -3,7 +3,7 @@
 import os
 import functools
 
-required_conan_version = ">=1.33.0"
+required_conan_version = ">=1.36.0"
 
 
 class GTestConan(ConanFile):
@@ -143,11 +143,10 @@ def _postfix(self):
         return self.options.debug_postfix if self.settings.build_type == "Debug" else ""
 
     def package_info(self):
-        self.cpp_info.names["cmake_find_package"] = "GTest"
-        self.cpp_info.names["cmake_find_package_multi"] = "GTest"
-        self.cpp_info.components["libgtest"].names["cmake_find_package"] = "gtest"
-        self.cpp_info.components["libgtest"].names["cmake_find_package_multi"] = "gtest"
-        self.cpp_info.components["libgtest"].names["pkg_config"] = "gtest"
+        self.cpp_info.set_property("cmake_file_name", "GTest")
+        self.cpp_info.set_property("cmake_target_name", "GTest")
+        self.cpp_info.components["libgtest"].set_property("cmake_target_name", "gtest")
+        self.cpp_info.components["libgtest"].set_property("pkg_config_name", "gtest")
         self.cpp_info.components["libgtest"].libs = ["gtest{}".format(self._postfix)]
         if self.settings.os == "Linux":
             self.cpp_info.components["libgtest"].system_libs.append("pthread")
@@ -165,21 +164,18 @@ def package_info(self):
                     self.cpp_info.components["libgtest"].defines.append("GTEST_HAS_TR1_TUPLE=0")
 
         if not self.options.no_main:
+            self.cpp_info.components["gtest_main"].set_property("cmake_target_name", "gtest_main")
+            self.cpp_info.components["gtest_main"].set_property("pkg_config_name", "gtest_main")
             self.cpp_info.components["gtest_main"].libs = ["gtest_main{}".format(self._postfix)]
             self.cpp_info.components["gtest_main"].requires = ["libgtest"]
-            self.cpp_info.components["gtest_main"].names["cmake_find_package"] = "gtest_main"
-            self.cpp_info.components["gtest_main"].names["cmake_find_package_multi"] = "gtest_main"
-            self.cpp_info.components["gtest_main"].names["pkg_config"] = "gtest_main"
 
         if self.options.build_gmock:
-            self.cpp_info.components["gmock"].names["cmake_find_package"] = "gmock"
-            self.cpp_info.components["gmock"].names["cmake_find_package_multi"] = "gmock"
-            self.cpp_info.components["gmock"].names["pkg_config"] = "gmock"
+            self.cpp_info.components["gmock"].set_property("cmake_target_name", "gmock")
+            self.cpp_info.components["gmock"].set_property("pkg_config_name", "gmock")
             self.cpp_info.components["gmock"].libs = ["gmock{}".format(self._postfix)]
             self.cpp_info.components["gmock"].requires = ["libgtest"]
             if not self.options.no_main:
-                self.cpp_info.components["gmock_main"].names["cmake_find_package"] = "gmock_main"
-                self.cpp_info.components["gmock_main"].names["cmake_find_package_multi"] = "gmock_main"
-                self.cpp_info.components["gmock_main"].names["pkg_config"] = "gmock_main"
+                self.cpp_info.components["gmock_main"].set_property("cmake_target_name", "gmock_main")
+                self.cpp_info.components["gmock_main"].set_property("pkg_config_name", "gmock_main")
                 self.cpp_info.components["gmock_main"].libs = ["gmock_main{}".format(self._postfix)]
                 self.cpp_info.components["gmock_main"].requires = ["gmock"]


Test patch: