Skip to content

Commit

Permalink
Fixes #14166: Add strip option to cmake.install tool (#14167)
Browse files Browse the repository at this point in the history
* Add strip option to cmake.install tool

* Use conf option to enable cmake strip

* update conf to be install_strip

Co-authored-by: James <memsharded@gmail.com>

* update conf to be install_strip

Co-authored-by: James <memsharded@gmail.com>

---------

Co-authored-by: James <memsharded@gmail.com>
  • Loading branch information
sagi-ottopia and memsharded authored Jul 6, 2023
1 parent ccdd94f commit 0966e79
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
4 changes: 4 additions & 0 deletions conan/tools/cmake/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ def install(self, build_type=None, component=None):
arg_list = ["--install", build_folder, build_config, "--prefix", pkg_folder]
if component:
arg_list.extend(["--component", component])

do_strip = self._conanfile.conf.get("tools.cmake:install_strip", check_type=bool)
if do_strip:
arg_list.append("--strip")
arg_list = " ".join(filter(None, arg_list))
command = "%s %s" % (self._cmake_program, arg_list)
self._conanfile.output.info("CMake command: %s" % command)
Expand Down
31 changes: 30 additions & 1 deletion conans/test/unittests/tools/cmake/test_cmake_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,38 @@ def test_run_install_component():
conanfile.settings = settings
conanfile.folders.set_base_package(temp_folder())

# Choose generator to match generic setttings
# Choose generator to match generic settings
write_cmake_presets(conanfile, "toolchain", "Visual Studio 14 2015", {})
cmake = CMake(conanfile)
cmake.install(component="foo")

assert "--component foo" in conanfile.command


def test_run_install_strip():
"""
Testing that the install/strip rule is called
Issue related: https://github.com/conan-io/conan/issues/14166
"""

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.conf["tools.cmake:install_strip"] = True

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()
assert "--strip" in conanfile.command

0 comments on commit 0966e79

Please sign in to comment.