Repository: conan-io/conan

Issue:
[bug] cmake_lib template adds find_package to all requirements in test_package
### Describe the bug

Environment: everyone
OS: everyone

The `cmake_lib` template of `conan new` command does generate not invalid CMake code, but redundant. 
On `test_package/CMakeLists.txt` it generates  `find_package` directives of every dependency passed as `-d requires` parameter and it should only generate the `find_package` of the main package, delegating the finding of transitive dependencies to the original package.


### How to reproduce it

```sh
$ conan new cmake_lib -d name=sdk -d version=1.0 -d requires="lib_a/1.0" -d requires="lib_b/1.0"
```

```
File saved: CMakeLists.txt
File saved: conanfile.py
File saved: include/sdk.h
File saved: src/sdk.cpp
File saved: test_package/CMakeLists.txt
File saved: test_package/conanfile.py
File saved: test_package/src/example.cpp
```

```sh
$ cat test_package/CMakeLists.txt
```
```
cmake_minimum_required(VERSION 3.15)
project(PackageTest CXX)

find_package(sdk CONFIG REQUIRED)

find_package(lib_a CONFIG REQUIRED)    # This find_packages are incorrect. 
find_package(lib_b CONFIG REQUIRED)    # Conan should delegate on sdk generator to find their transitive dependencies


add_executable(example src/example.cpp)
target_link_libraries(example sdk::sdk)
```


Discussion:

Resolving patch:
diff --git a/conan/internal/api/new/cmake_lib.py b/conan/internal/api/new/cmake_lib.py
--- a/conan/internal/api/new/cmake_lib.py
+++ b/conan/internal/api/new/cmake_lib.py
@@ -32,7 +32,18 @@ def configure(self):
 
     def layout(self):
         cmake_layout(self)
-
+    {% if requires is defined %}
+    def requirements(self):
+        {% for require in requires -%}
+        self.requires("{{ require }}")
+        {% endfor %}
+    {%- endif %}
+    {%- if tool_requires is defined %}
+    def build_requirements(self):
+        {% for require in tool_requires -%}
+        self.tool_requires("{{ require }}")
+        {% endfor %}
+    {%- endif %}
     def generate(self):
         deps = CMakeDeps(self)
         deps.generate()
@@ -51,20 +62,6 @@ def package(self):
     def package_info(self):
         self.cpp_info.libs = ["{{name}}"]
 
-    {% if requires is defined -%}
-    def requirements(self):
-        {% for require in requires -%}
-        self.requires("{{ require }}")
-        {% endfor %}
-    {%- endif %}
-
-    {% if tool_requires is defined -%}
-    def build_requirements(self):
-        {% for require in tool_requires -%}
-        self.tool_requires("{{ require }}")
-        {% endfor %}
-    {%- endif %}
-
 '''
 
 cmake_v2 = """cmake_minimum_required(VERSION 3.15)
@@ -270,12 +267,6 @@ def test(self):
 
 find_package({{name}} CONFIG REQUIRED)
 
-{% if requires is defined -%}
-{% for require in requires -%}
-find_package({{as_name(require)}} CONFIG REQUIRED)
-{% endfor %}
-{%- endif %}
-
 add_executable(example src/example.cpp)
 target_link_libraries(example {{name}}::{{name}})
 """
diff --git a/conans/__init__.py b/conans/__init__.py
--- a/conans/__init__.py
+++ b/conans/__init__.py
@@ -2,4 +2,4 @@
 REVISIONS = "revisions"  # Only when enabled in config, not by default look at server_launcher.py
 OAUTH_TOKEN = "oauth_token"
 
-__version__ = '2.4.0'
+__version__ = '2.4.1'


Test patch: