diff --git a/conan/tools/cmake/cmake.py b/conan/tools/cmake/cmake.py index 55ddbd116be..e9b3fd3e51a 100644 --- a/conan/tools/cmake/cmake.py +++ b/conan/tools/cmake/cmake.py @@ -128,7 +128,9 @@ def _build(self, build_type=None, target=None, cli_args=None, build_tool_args=No args = [] if target is not None: - args = ["--target", target] + target_list = [target] if isinstance(target, str) else target + args.extend(["--target"] + target_list) + if cli_args: args.extend(cli_args) diff --git a/conans/test/integration/toolchains/cmake/test_cmake.py b/conans/test/integration/toolchains/cmake/test_cmake.py index 86ae90d270d..c49c1505624 100644 --- a/conans/test/integration/toolchains/cmake/test_cmake.py +++ b/conans/test/integration/toolchains/cmake/test_cmake.py @@ -1,4 +1,8 @@ import textwrap +from string import Template + +import pytest + from conans.test.utils.tools import TestClient @@ -31,3 +35,32 @@ def run(self, *args, **kwargs): assert "-something" in client.out assert "--testverbose" in client.out assert "-testok" in client.out + + +@pytest.mark.parametrize("argument, output_args", [ + ("'target'", "--target target"), + ("['target']", "--target target"), + ("['target1', 'target2']", "--target target1 target2"), +]) +def test_multiple_targets(argument, output_args): + client = TestClient() + + conanfile_template = Template(textwrap.dedent(""" + from conan import ConanFile + from conan.tools.cmake import CMake + class Pkg(ConanFile): + generators = "CMakeToolchain" + name = "pkg" + version = "0.1" + settings = "os", "compiler", "build_type", "arch" + def build(self): + cmake = CMake(self) + cmake.build(target=${argument}) + + def run(self, *args, **kwargs): + self.output.info("MYRUN: {}".format(*args)) + """)) + conanfile = conanfile_template.substitute(argument=argument) + client.save({"conanfile.py": conanfile}) + client.run("create . ") + assert output_args in client.out