# Add a PRE\_INSTALL option to add\_custom\_command

**URL:** <https://discourse.cmake.org/t/add-a-pre-install-option-to-add-custom-command/14319>\
**Category:** Code\
**Created:** [July 5, 2025, 8:37am UTC](https://discourse.cmake.org/t/add-a-pre-install-option-to-add-custom-command/14319 "2025-07-05T08:37:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![perdrix](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/a8b319/32.png) [@perdrix](https://discourse.cmake.org/u/perdrix)\
**Post date:** [July 5, 2025, 8:37am UTC](https://discourse.cmake.org/t/add-a-pre-install-option-to-add-custom-command/14319/1 "2025-07-05T08:37:10Z")

</div>

Running on macOS (particularly in this case), I need to do some things prior to running the install such as unlocking the keychain (for example), so that the app files I generate can be signed.

Now I do this in the POST\_BUILD but that doesn’t get run if I have just done a full build and then run an install as a separate step. Which means I need to do a clean and then install (which forces a build to run first).

Is this likely to materialise (please)?

David

---

<div class="post-metadata">

**Author:** ![perdrix](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/a8b319/32.png) [@perdrix](https://discourse.cmake.org/u/perdrix)\
**Post date:** [July 7, 2025, 7:42am UTC](https://discourse.cmake.org/t/add-a-pre-install-option-to-add-custom-command/14319/2 "2025-07-07T07:42:04Z")

</div>

A better alternative may be the add the ability to use:

```auto
install(COMMAND command1 [ARGS] [args1...]
        [COMMAND command2 [ARGS] [args2...] ...])

```

when the COMMAND part has the same syntax as add\_custom\_command.

David

---

<div class="post-metadata">

**Author:** ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)\
**Post date:** [July 7, 2025, 9:04am UTC](https://discourse.cmake.org/t/add-a-pre-install-option-to-add-custom-command/14319/3 "2025-07-07T09:04:12Z")

</div>

The [`install(CODE|SCRIPT)` command](https://cmake.org/cmake/help/latest/command/install.html#script) might be what you’re looking for. You can put `execute_process()` in the code, for example.

---

<div class="post-metadata">

**Author:** ![perdrix](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/a8b319/32.png) [@perdrix](https://discourse.cmake.org/u/perdrix)\
**Post date:** [July 7, 2025, 12:06pm UTC](https://discourse.cmake.org/t/add-a-pre-install-option-to-add-custom-command/14319/4 "2025-07-07T12:06:01Z")

</div>

Woohoo!!! (As the saying goes).

Adding:

if(APPLE)  
install (CODE “execute\_process(COMMAND "$ENV{HOME}/.unlock\_keychain")”)  
endif()

Did exactly what I needed!

Thank you so much  
David
