# CMAKE\_STRIP arguments?

**URL:** https://discourse.cmake.org/t/cmake-strip-arguments/6930
**Category:** Code
**Created:** [November 22, 2022, 8:38pm UTC](https://discourse.cmake.org/t/cmake-strip-arguments/6930 "2022-11-22T20:38:11Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![cmak](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/c/eb8c5e/32.png) [@cmak](https://discourse.cmake.org/u/cmak)
#### Post date: [November 22, 2022, 8:38pm UTC](https://discourse.cmake.org/t/cmake-strip-arguments/6930/1 "2022-11-22T20:38:11Z")

</div>

Is there a way to pass arguments to cmake strip (invoked via ninja install/strip)? Is appending them to `CMAKE_STRIP` the correct approach? Can’t really find the docs to cmake stripping.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 23, 2022, 11:50pm UTC](https://discourse.cmake.org/t/cmake-strip-arguments/6930/2 "2022-11-23T23:50:54Z")

</div>

I suspect this is not documented since it is mostly internal. A feature request to document the semantics and whether appending works might be the way to go.

---

<div class="post-metadata">

### Author: ![cmak](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/c/eb8c5e/32.png) [@cmak](https://discourse.cmake.org/u/cmak)
#### Post date: [November 24, 2022, 10:08am UTC](https://discourse.cmake.org/t/cmake-strip-arguments/6930/3 "2022-11-24T10:08:53Z")

</div>

Thanks!

When I set `CMAKE_STRIP` with arguments it appears as the binary no longer gets stripped at all. The cmake\_install.cmake file in the build folder looks correct, but the actual stripping does not take place. Can I see verbose output of cmake strip? I’m invoking it via `ninja install/strip`.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 26, 2022, 4:34pm UTC](https://discourse.cmake.org/t/cmake-strip-arguments/6930/4 "2022-11-26T16:34:31Z")

</div>

You can run the install script yourself:

```nohighlight
$ cmake --trace-expand -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake

```

---

<div class="post-metadata">

### Author: ![cmak](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/c/eb8c5e/32.png) [@cmak](https://discourse.cmake.org/u/cmak)
#### Post date: [December 15, 2022, 8:05pm UTC](https://discourse.cmake.org/t/cmake-strip-arguments/6930/5 "2022-12-15T20:05:50Z")

</div>

Thanks, for tip. But I still don’t understand why the file doesn’t become stripped when I add arguments to the strip command. Anything obvious wrong here? If I remove the trailing ` --strip-all` from my `CMAKE_STRIP` then the file gets stripped.

```bash
-- Installing: /data/src/build/install/usr/bin/my_binary
/data/src/build/cmake_install.cmake(48): if(EXISTS /data/src/build/install/usr/bin/my_binary AND NOT IS_SYMLINK /data/src/build/install/usr/bin/my_binary )
-- Set runtime path of "/data/src/build/install/usr/bin/my_binary" to ""
/data/src/build/cmake_install.cmake(54): if(CMAKE_INSTALL_DO_STRIP )
/data/src/build/cmake_install.cmake(55): execute_process(COMMAND strip --strip-all /data/src/build/install/usr/bin/my_binary )

```

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [December 16, 2022, 1:19am UTC](https://discourse.cmake.org/t/cmake-strip-arguments/6930/6 "2022-12-16T01:19:44Z")

</div>

How did you add `--strip-all`? If you set it to `strip --strip-all`, it is failing because that is not a valid command. You need to use `strip;--strip-all` to have CMake treat it as two items.

---

<div class="post-metadata">

### Author: ![cmak](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/c/eb8c5e/32.png) [@cmak](https://discourse.cmake.org/u/cmak)
#### Post date: [December 16, 2022, 7:28am UTC](https://discourse.cmake.org/t/cmake-strip-arguments/6930/7 "2022-12-16T07:28:10Z")

</div>

> [@ben.boeckel](#):
>
> `cmake --trace-expand -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake`

In toolchain file I set it like this

```cmake
set(CMAKE_STRIP "strip; --strip-all")

```

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [December 16, 2022, 12:59pm UTC](https://discourse.cmake.org/t/cmake-strip-arguments/6930/8 "2022-12-16T12:59:11Z")

</div>

That space means you’re passing a `<space>--strip-all` option and is probably treated as a filename, not a flag.

---

<div class="post-metadata">

### Author: ![cmak](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/c/eb8c5e/32.png) [@cmak](https://discourse.cmake.org/u/cmak)
#### Post date: [December 16, 2022, 2:08pm UTC](https://discourse.cmake.org/t/cmake-strip-arguments/6930/9 "2022-12-16T14:08:01Z")

</div>

> [@cmak](#):
>
> `set(CMAKE_STRIP "strip; --strip-all")`

No that does not help. As soon as I pass an argument to `CMAKE_STRIP` that breaks stripping. I don’t see an error message, but the file does not get stripped. I’m invoking this via the `install/strip` target.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [December 16, 2022, 2:39pm UTC](https://discourse.cmake.org/t/cmake-strip-arguments/6930/10 "2022-12-16T14:39:49Z")

</div>

At this point, I would use `strace` to see what is _actually_ happening and where things might be going wrong.

---

<div class="post-metadata">

### Author: ![cmak](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/c/eb8c5e/32.png) [@cmak](https://discourse.cmake.org/u/cmak)
#### Post date: [December 16, 2022, 7:10pm UTC](https://discourse.cmake.org/t/cmake-strip-arguments/6930/11 "2022-12-16T19:10:32Z")

</div>

I think I can see the problem. Looks like cmake is passing the strip command also on the argument list to `execve`.

```auto
[pid 32262] execve("/usr/bin/strip;--strip-all", ["/usr/bin/strip;--strip-all", "/data/src/build/my_binary"], 0x7ffc6199e120 /* 62 vars */) = -1 ENOENT (No such file or directory)

```

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [December 16, 2022, 7:39pm UTC](https://discourse.cmake.org/t/cmake-strip-arguments/6930/12 "2022-12-16T19:39:16Z")

</div>

That means that `${CMAKE_STRIP}` is quoted somewhere and doesn’t support expanding to arguments. Finding and fixing that would let it work in newer CMake versions that contain the fix at least.

---

<div class="post-metadata">

### Author: ![cmak](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/c/eb8c5e/32.png) [@cmak](https://discourse.cmake.org/u/cmak)
#### Post date: [December 16, 2022, 7:46pm UTC](https://discourse.cmake.org/t/cmake-strip-arguments/6930/13 "2022-12-16T19:46:55Z")

</div>

Which cmake has this fix? I’m running cmake version 3.16.5.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [December 16, 2022, 8:05pm UTC](https://discourse.cmake.org/t/cmake-strip-arguments/6930/14 "2022-12-16T20:05:27Z")

</div>

I don’t know that any CMake version has the fix yet.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [December 16, 2022, 8:09pm UTC](https://discourse.cmake.org/t/cmake-strip-arguments/6930/15 "2022-12-16T20:09:01Z")

</div>

Looking, the value is quoted in the written script in both usages:

- `cmInstallRuntimeDependencySetGenerator::GenerateStripFixup`
- `cmInstallTargetGenerator::AddStripRule`

So no arguments are supported even as of 3.25.

---

<div class="post-metadata">

### Author: ![cmak](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/c/eb8c5e/32.png) [@cmak](https://discourse.cmake.org/u/cmak)
#### Post date: [December 16, 2022, 8:21pm UTC](https://discourse.cmake.org/t/cmake-strip-arguments/6930/16 "2022-12-16T20:21:50Z")

</div>

I see, thanks for checking. Can I instead use `objcopy` to circumvent the bug? E.g. `objcopy --strip-debug` via custom target on all files that are installed? Is there an easy way to traverse all install targets?

I also would like cmake to add gnu debug links, `objcopy --add-gnu-debuglink`, on the files installed and the link point to where the unstripped file with symbols resides.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [December 16, 2022, 9:23pm UTC](https://discourse.cmake.org/t/cmake-strip-arguments/6930/17 "2022-12-16T21:23:52Z")

</div>

I don’t know of an easy way to know where all targets will be installed at configure time to be able to set something like that up, sorry.

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [December 18, 2022, 10:04am UTC](https://discourse.cmake.org/t/cmake-strip-arguments/6930/18 "2022-12-18T10:04:10Z")

</div>

You can add install(CODE) commands to do that.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [December 18, 2022, 1:05pm UTC](https://discourse.cmake.org/t/cmake-strip-arguments/6930/19 "2022-12-18T13:05:31Z")

</div>

You can do it, but it needs to be done per-target with knowledge of the install destination manually transferred.

---

<div class="post-metadata">

### Author: ![jobor](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jobor/32/1230_2.png) [@jobor](https://discourse.cmake.org/u/jobor)
#### Post date: [June 2, 2023, 7:32am UTC](https://discourse.cmake.org/t/cmake-strip-arguments/6930/20 "2023-06-02T07:32:27Z")

</div>

In an older mailing list thread was the suggestion to generate a shell script that calls strip with the desired arguments and assigning it to `CMAKE_STRIP`.

See [https://cmake.org/pipermail/cmake/2011-April/043705.html](https://cmake.org/pipermail/cmake/2011-April/043705.html)
