Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake use multiple targets in target argument #14883

Merged
merged 3 commits into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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