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}}) """