Skip to content

Commit

Permalink
CMake use multiple targets in target argument (#14883)
Browse files Browse the repository at this point in the history
* accept lists in target argument

* add test

* minor changes
  • Loading branch information
czoido authored Oct 7, 2023
1 parent f5330d5 commit 4650e12
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
4 changes: 3 additions & 1 deletion conan/tools/cmake/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
33 changes: 33 additions & 0 deletions conans/test/integration/toolchains/cmake/test_cmake.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import textwrap
from string import Template

import pytest

from conans.test.utils.tools import TestClient


Expand Down Expand Up @@ -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

0 comments on commit 4650e12

Please sign in to comment.