Repository: conan-io/conan

Issue:
[feature] Add '--strip' option to cmake install
### What is your suggestion?

Can you add a parameter to `cmake.install` function in order to be able to strip binaries before install ?

install and strip were added to CMake about 4 years ago, and if I got it correctly in version 3.15
https://gitlab.kitware.com/cmake/cmake/-/merge_requests/3069

Strip is very useful to remove debug symbols (actually all DWARF extension) from binaries and especially release binaries.

I tried many options to make it work with conan, but without success, so I think adding this option as a parameter to `install` function in `cmake` tool will be the best solution instead of some workarounds.

### Have you read the CONTRIBUTING guide?

- [X] I've read the CONTRIBUTING guide

Discussion:
CLAassistant: [![CLA assistant check](https://cla-assistant.io/pull/badge/not_signed)](https://cla-assistant.io/conan-io/conan?pullRequest=14167) <br/>Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our [Contributor License Agreement](https://cla-assistant.io/conan-io/conan?pullRequest=14167) before we can accept your contribution.<br/><sub>You have signed the CLA already but the status is still pending? Let us [recheck](https://cla-assistant.io/check/conan-io/conan?pullRequest=14167) it.</sub>
sagi-ottopia: Hi,
Regarding a `conf` value, I think it should be easy to add it to the PR as well. I will look for some example and will update the PR accordingly.

Regarding unittests, sure.

memsharded: > Regarding a conf value, I think it should be easy to add it to the PR as well. I will look for some example and will update the PR accordingly.

Only if it makes sense as a use case, is it something that you will prefer over modifying the recipes? Is it something that makes sense to do for all packages in the graph or is it something specific to some?

I am adding @jcar87 for some feedback about this use case too.
sagi-ottopia: > > Regarding a conf value, I think it should be easy to add it to the PR as well. I will look for some example and will update the PR accordingly.
> 
> Only if it makes sense as a use case, is it something that you will prefer over modifying the recipes? Is it something that makes sense to do for all packages in the graph or is it something specific to some?
> 
> I am adding @jcar87 for some feedback about this use case too.

I think it makes sense, 
because when using the a conf value I can add it just in my Release builds profile without the need to have something like the following in my `conanfile.py`: 
```
do_strip = False
if self.settings.build_type == 'Release':
   do_strip = True
...
cmake.install(strip=do_strip)
```


memsharded: > if self.settings.build_type == 'Release':

Ok, makes sense, though nowadays, I'd expect that ``Release`` builds already don't contain any debug information to be stripped, I understand it might not be the case for all platforms and tools, so I am ok with making this a opt-in conf.
sagi-ottopia: Hi @memsharded,
saw that you added this into 2.0.8 timeline, 
is it possible to merge it also to 1.XX  latest version ? 
Thanks.
memsharded: Yes, sorry, didn't check the target branch. Moved it to 1.61, and then I will merge it myself to 2.0 branch (2.0.8 will probably be out earlier than 1.61)

Patch:
diff --git a/conan/tools/cmake/cmake.py b/conan/tools/cmake/cmake.py
index d52a8ecb4..6dd77ac82 100644
--- a/conan/tools/cmake/cmake.py
+++ b/conan/tools/cmake/cmake.py
@@ -147,6 +147,10 @@ class CMake(object):
         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)


Test patch:
diff --git a/conans/test/unittests/tools/cmake/test_cmake_install.py b/conans/test/unittests/tools/cmake/test_cmake_install.py
index 273c38835..8fd6d45c4 100644
--- a/conans/test/unittests/tools/cmake/test_cmake_install.py
+++ b/conans/test/unittests/tools/cmake/test_cmake_install.py
@@ -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