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: add support for cli_args in install() #14397

Merged
merged 1 commit into from
Jul 30, 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
10 changes: 9 additions & 1 deletion conan/tools/cmake/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def build(self, build_type=None, target=None, cli_args=None, build_tool_args=Non
self._conanfile.output.info("Running CMake.build()")
self._build(build_type, target, cli_args, build_tool_args)

def install(self, build_type=None, component=None):
def install(self, build_type=None, component=None, cli_args=None):
"""
Equivalent to run ``cmake --build . --target=install``
Expand All @@ -172,6 +172,9 @@ def install(self, build_type=None, component=None):
It can fail if the build is single configuration (e.g. Unix Makefiles),
as in that case the build type must be specified at configure time,
not build type.
:param cli_args: A list of arguments ``[arg1, arg2, ...]`` for the underlying
build system that will be passed to the command line:
``cmake --install ... arg1 arg2``
"""
self._conanfile.output.info("Running CMake.install()")
mkdir(self._conanfile, self._conanfile.package_folder)
Expand All @@ -193,6 +196,11 @@ def install(self, build_type=None, component=None):
if do_strip:
arg_list.append("--strip")

if cli_args:
if "--install" in cli_args:
raise ConanException("Do not pass '--install' argument to 'install()'")
arg_list.extend(cli_args)

arg_list = " ".join(filter(None, arg_list))
command = "%s %s" % (self._cmake_program, arg_list)
self._conanfile.run(command)
Expand Down
56 changes: 56 additions & 0 deletions conans/test/unittests/tools/cmake/test_cmake_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,59 @@ def test_run_install_strip():
cmake = CMake(conanfile)
cmake.install()
assert "--strip" in conanfile.command


def test_run_install_cli_args():
"""
Testing that the passing cli_args to install works
Issue related: https://github.com/conan-io/conan/issues/14235
"""

settings = Settings.loads(get_default_settings_yml())
settings.os = "Linux"
settings.arch = "x86_64"
settings.build_type = "Release"
settings.compiler = "gcc"
settings.compiler.version = "11"

conanfile = ConanFileMock()

conanfile.conf = Conf()

conanfile.folders.generators = "."
conanfile.folders.set_base_generators(temp_folder())
conanfile.settings = settings
conanfile.folders.set_base_package(temp_folder())

write_cmake_presets(conanfile, "toolchain", "Unix Makefiles", {})
cmake = CMake(conanfile)
cmake.install(cli_args=["--prefix=/tmp"])
assert "--prefix=/tmp" in conanfile.command


def test_run_install_cli_args_strip():
"""
Testing that the install/strip rule is called when using cli_args
Issue related: https://github.com/conan-io/conan/issues/14235
"""

settings = Settings.loads(get_default_settings_yml())
settings.os = "Linux"
settings.arch = "x86_64"
settings.build_type = "Release"
settings.compiler = "gcc"
settings.compiler.version = "11"

conanfile = ConanFileMock()

conanfile.conf = Conf()

conanfile.folders.generators = "."
conanfile.folders.set_base_generators(temp_folder())
conanfile.settings = settings
conanfile.folders.set_base_package(temp_folder())

write_cmake_presets(conanfile, "toolchain", "Unix Makefiles", {})
cmake = CMake(conanfile)
cmake.install(cli_args=["--strip"])
assert "--strip" in conanfile.command