From 1c3b3b3b4a52c93120e58e6596eb6bbc327ca7c1 Mon Sep 17 00:00:00 2001 From: PerseoGI Date: Mon, 10 Jun 2024 11:00:30 +0200 Subject: [PATCH] Remove find_package generation on test_package of cmake_lib template On test_package/CMakeLists.txt should not appear any find_package of transitive dependencies (dependencies of the currently tested package) Delegate on conan cmake generators to find dependencies. Also, ordered optional requirements and build_requirement methods on template --- conan/internal/api/new/cmake_lib.py | 33 +++++++++++------------------ 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/conan/internal/api/new/cmake_lib.py b/conan/internal/api/new/cmake_lib.py index 56ea6693571..a92a9305217 100644 --- 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}}) """