# Install static library while preserving extended attributes on macOS

**URL:** <https://discourse.cmake.org/t/install-static-library-while-preserving-extended-attributes-on-macos/7694>\
**Category:** Code\
**Tags:** os:macos\
**Created:** [March 16, 2023, 8:54pm UTC](https://discourse.cmake.org/t/install-static-library-while-preserving-extended-attributes-on-macos/7694 "2023-03-16T20:54:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jviotti](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jviotti/32/3030_2.png) [@jviotti](https://discourse.cmake.org/u/jviotti)\
**Post date:** [March 16, 2023, 8:54pm UTC](https://discourse.cmake.org/t/install-static-library-while-preserving-extended-attributes-on-macos/7694/1 "2023-03-16T20:54:30Z")

</div>

I have a project that generates static libraries, which need to be code-signed, as the package including them needs to get notarized.

I have a set of custom targets that correctly sign the static libraries, and that works fine. Static libraries are not Mach-O binaries, so macOS will sign them using extended attributes. However, `install(TARGETS)` on the static library seems to wipe out extended attributes of every file it installs, including the signatures.

Is there any way to instruct `install(TARGETS)` to NOT wipe the extended attributes of the static library it is installing?

---

<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:** [March 16, 2023, 8:55pm UTC](https://discourse.cmake.org/t/install-static-library-while-preserving-extended-attributes-on-macos/7694/2 "2023-03-16T20:55:56Z")

</div>

@brad.king

---

<div class="post-metadata">

**Author:** ![jviotti](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jviotti/32/3030_2.png) [@jviotti](https://discourse.cmake.org/u/jviotti)\
**Post date:** [March 17, 2023, 4:28pm UTC](https://discourse.cmake.org/t/install-static-library-while-preserving-extended-attributes-on-macos/7694/3 "2023-03-17T16:28:39Z")

</div>

I just found out that CPack’s ZIP generator also wipes out extended attributes, as it likely uses plain `zip(1)` on macOS rather than `ditto(1)`, which implements ZIP with extended attributes support for macOS ZIP deployments.

---

<div class="post-metadata">

**Author:** ![jviotti](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jviotti/32/3030_2.png) [@jviotti](https://discourse.cmake.org/u/jviotti)\
**Post date:** [March 17, 2023, 5:00pm UTC](https://discourse.cmake.org/t/install-static-library-while-preserving-extended-attributes-on-macos/7694/4 "2023-03-17T17:00:06Z")

</div>

Actually, after some more experimentation, CPack will clear the extended attributes while staging the files into `_CPack_Packages`. So probably the staging logic needs to be updated to at least preserve the extended attributes that corresponds to code-signing (which start with `com.apple.cs.*` as far as I can see), and then the zipping logic might need to be tweaked too.
