Repository: conan-io/conan
Pull request: [feature] Add generic config for CMake and Meson install strip
Hello!

This PR replaces the current config `tools.cmake:install_strip` with the generic `tools.install:strip`, so it can be used by both `CMake` and `Meson`. The `install_strip` is now marked as deprecated and will warn the user with a message.



Changelog: Feature: Replace `tools.cmake:install_strip` by `tools.install:strip`. Affect both CMake and Meson tool helpers.
Docs: https://github.com/conan-io/docs/pull/4121

closes #18308

- [x] Refer to the issue that supports this Pull Request.
- [x] If the issue has missing info, explain the purpose/use case/pain/need that covers this Pull Request.
- [x] I've read the [Contributing guide](https://github.com/conan-io/conan/blob/develop2/.github/CONTRIBUTING.md).
- [x] I've followed the PEP8 style guides for Python code.
- [x] I've opened another PR in the Conan docs repo to the ``develop`` branch, documenting this one.


Problem statement:
[feature] Meson Tool support specific args like '--strip' when install()
### What is your suggestion?

From meson 0.62, meson install support '--strip', but there are no way to pass it to conan's tools.Meson.
> --tags TAGS                           Install only targets having one of the
                                        given tags. (Since 0.60.0)
  --strip                               Strip targets even if strip option was
                                        not set during configure. (Since 0.62.0)

May be a conf like for cmake:
> tools.cmake:install_strip: Add --strip to cmake.install()

### Have you read the CONTRIBUTING guide?

- [x] I've read the CONTRIBUTING guide

Hints from issue discussion:
Thanks for the feedback @wsw0108 

> do_strip = self._conanfile.conf.get("tools.cmake:install_strip", check_type=bool)

It seems that we would actually want to generalize this into a single ``tools.build:install_strip`` that would apply to different build systems. I'll check the possibility with the team.
the possible approach:

- New generic ``strip`` config
- This will affect both ``cmake`` and ``meson``
- The old ``tools.cmake:install_strip`` keeps working, but can print a ``deprecated`` warning in favor of the new one

Commit message: Improve strip config description

Signed-off-by: Uilian Ries <uilianries@gmail.com>

Patch to review:
diff --git a/conan/internal/model/conf.py b/conan/internal/model/conf.py
index 044fda018b8..04dd8c87da6 100644
--- a/conan/internal/model/conf.py
+++ b/conan/internal/model/conf.py
@@ -86,7 +86,7 @@
     "tools.cmake.cmake_layout:test_folder": "(Experimental) Allow configuring the base folder of the build for test_package",
     "tools.cmake:cmake_program": "Path to CMake executable",
     "tools.cmake.cmakedeps:new": "Use the new CMakeDeps generator",
-    "tools.cmake:install_strip": "Add --strip to cmake.install()",
+    "tools.cmake:install_strip": "(Deprecated) Add --strip to cmake.install(). Use tools.install:strip instead",
     "tools.deployer:symlinks": "Set to False to disable deployers copying symlinks",
     "tools.files.download:retry": "Number of retries in case of failure when downloading",
     "tools.files.download:retry_wait": "Seconds to wait between download attempts",
@@ -135,6 +135,8 @@
     "tools.build:sharedlinkflags": "List of extra flags used by different toolchains like CMakeToolchain, AutotoolsToolchain and MesonToolchain",
     "tools.build:exelinkflags": "List of extra flags used by different toolchains like CMakeToolchain, AutotoolsToolchain and MesonToolchain",
     "tools.build:linker_scripts": "List of linker script files to pass to the linker used by different toolchains like CMakeToolchain, AutotoolsToolchain, and MesonToolchain",
+    # Toolchain installation
+    "tools.install:strip": "(boolean) Strip the binaries when installing them with CMake and Meson",
     # Package ID composition
     "tools.info.package_id:confs": "List of existing configuration to be part of the package ID",
 }
diff --git a/conan/tools/cmake/cmake.py b/conan/tools/cmake/cmake.py
index 4a6a5eca7a5..796013bc882 100644
--- a/conan/tools/cmake/cmake.py
+++ b/conan/tools/cmake/cmake.py
@@ -209,7 +209,12 @@ def install(self, build_type=None, component=None, cli_args=None, stdout=None, s
             arg_list.extend(["--component", component])
         arg_list.extend(self._compilation_verbosity_arg)
 
-        do_strip = self._conanfile.conf.get("tools.cmake:install_strip", check_type=bool)
+        deprecated_install_strip = self._conanfile.conf.get("tools.cmake:install_strip", check_type=bool)
+        if deprecated_install_strip:
+            self._conanfile.output.warning("The 'tools.cmake:install_strip' configuration is deprecated, "
+                                           "use 'tools.install:strip' instead.")
+
+        do_strip = self._conanfile.conf.get("tools.install:strip", check_type=bool)
         if do_strip:
             arg_list.append("--strip")
 
diff --git a/conan/tools/meson/meson.py b/conan/tools/meson/meson.py
index 17fa5924100..9468d6c241e 100644
--- a/conan/tools/meson/meson.py
+++ b/conan/tools/meson/meson.py
@@ -82,6 +82,8 @@ def install(self):
         verbosity = self._install_verbosity
         if verbosity:
             cmd += " " + verbosity
+        if self._install_strip:
+            cmd += " " + self._install_strip
         self._conanfile.run(cmd)
 
     def test(self):
@@ -112,6 +114,15 @@ def _install_verbosity(self):
         verbosity = self._conanfile.conf.get("tools.build:verbosity", choices=("quiet", "verbose"))
         return "--quiet" if verbosity else ""
 
+    @property
+    def _install_strip(self) -> str:
+        """
+        Returns Meson install strip the value based on ``tools.install:strip`` configuration.
+        https://mesonbuild.com/Release-notes-for-0-62-0.html#meson-install-strip
+        """
+        strip = self._conanfile.conf.get("tools.install:strip", check_type=bool)
+        return "--strip" if strip else ""
+
     @property
     def _prefix(self):
         """Generate a valid ``--prefix`` argument value for meson.
diff --git a/test/unittests/tools/cmake/test_cmake_install.py b/test/unittests/tools/cmake/test_cmake_install.py
index d6bf9fa6c87..c084a852e61 100644
--- a/test/unittests/tools/cmake/test_cmake_install.py
+++ b/test/unittests/tools/cmake/test_cmake_install.py
@@ -1,10 +1,14 @@
+import pytest
+
 from conan.internal.default_settings import default_settings_yml
 from conan.tools.cmake import CMake
 from conan.tools.cmake.presets import write_cmake_presets
 from conan.internal.model.conf import Conf
 from conan.internal.model.settings import Settings
-from conan.test.utils.mocks import ConanFileMock
+from conan.test.utils.mocks import ConanFileMock, RedirectedTestOutput
 from conan.test.utils.test_files import temp_folder
+from conan.test.utils.tools import redirect_output
+
 
 
 def test_run_install_component():
@@ -35,8 +39,10 @@ def test_run_install_component():
 
     assert "--component foo" in conanfile.command
 
-
-def test_run_install_strip():
+@pytest.mark.parametrize("config, deprecated",
+                         [("tools.cmake:install_strip", True),
+                          ("tools.install:strip", False),])
+def test_run_install_strip(config, deprecated):
     """
     Testing that the install/strip rule is called
     Issue related: https://github.com/conan-io/conan/issues/14166
@@ -52,7 +58,7 @@ def test_run_install_strip():
     conanfile = ConanFileMock()
 
     conanfile.conf = Conf()
-    conanfile.conf.define("tools.cmake:install_strip", True)
+    conanfile.conf.define(config, True)
 
     conanfile.folders.generators = "."
     conanfile.folders.set_base_generators(temp_folder())
@@ -61,9 +67,18 @@ def test_run_install_strip():
 
     write_cmake_presets(conanfile, "toolchain", "Unix Makefiles", {})
     cmake = CMake(conanfile)
-    cmake.install()
-    assert "--strip" in conanfile.command
-
+    stdout = RedirectedTestOutput()  # Initialize each command
+    stderr = RedirectedTestOutput()
+    with redirect_output(stderr, stdout):
+        cmake.install(stdout=stdout, stderr=stderr)
+
+    if deprecated:
+        assert "--strip" not in conanfile.command
+        assert "WARN: The 'tools.cmake:install_strip' configuration is deprecated, "\
+                "use 'tools.install:strip' instead." in stderr
+    else:
+        assert "--strip" in conanfile.command
+        assert "tools.cmake:install_strip" not in stderr
 
 def test_run_install_cli_args():
     """
diff --git a/test/unittests/tools/meson/test_meson.py b/test/unittests/tools/meson/test_meson.py
index 8954d2bf326..1ff8e77b447 100644
--- a/test/unittests/tools/meson/test_meson.py
+++ b/test/unittests/tools/meson/test_meson.py
@@ -5,6 +5,7 @@
 from conan.tools.meson import Meson
 from conan.internal.model.conf import ConfDefinition
 from conan.test.utils.mocks import ConanFileMock, MockSettings
+from conan.test.utils.test_files import temp_folder
 from conan.tools.meson.helpers import get_apple_subsystem, to_cstd_flag, to_cppstd_flag
 
 
@@ -64,3 +65,28 @@ def test_meson_to_cstd_flag(cstd, expected):
 ])
 def test_meson_to_cppstd_flag(compiler, compiler_version, cppstd, expected):
     assert to_cppstd_flag(compiler, compiler_version, cppstd) == expected
+
+
+def test_meson_install_strip():
+    """When the configuration `tools.install:strip` is set to True,
+        the Meson install command should include the `--strip` option.
+    """
+    c = ConfDefinition()
+    c.loads("tools.install:strip=True")
+
+    settings = MockSettings({"build_type": "Release",
+                             "compiler": "gcc",
+                             "compiler.version": "7",
+                             "os": "Linux",
+                             "arch": "x86_64"})
+    conanfile = ConanFileMock()
+    conanfile.settings = settings
+    conanfile.conf = c.get_conanfile_conf(None)
+    conanfile.folders.generators = "."
+    conanfile.folders.set_base_generators(temp_folder())
+    conanfile.folders.set_base_package(temp_folder())
+
+    meson = Meson(conanfile)
+    meson.install()
+
+    assert '--strip' in str(conanfile.command)


Code review comments:
diff_hunk: @@ -209,7 +209,12 @@ def install(self, build_type=None, component=None, cli_args=None, stdout=None, s
             arg_list.extend(["--component", component])
         arg_list.extend(self._compilation_verbosity_arg)
 
-        do_strip = self._conanfile.conf.get("tools.cmake:install_strip", check_type=bool)
+        deprecated_install_strip = self._conanfile.conf.get("tools.cmake:install_strip", check_type=bool)
+        if deprecated_install_strip:
+            self._conanfile.output.warning("The 'tools.cmake:install_strip' configuration is deprecated, "
+                                           "use 'tools.install:strip' instead.")
+
+        do_strip = self._conanfile.conf.get("tools.install:strip", check_type=bool)
path: conan/tools/cmake/cmake.py
text: @user1:
We should still listen to the deprecated strip conf, and fall back to the new one otherwise

@author:
Done [013fd85](https://github.com/conan-io/conan/pull/18429/commits/013fd85671688745f0bcf2c3b1a1f26856155efe)