# postinstall with cmake

**URL:** https://discourse.cmake.org/t/postinstall-with-cmake/3701
**Category:** Code
**Tags:** os:macos
**Created:** [July 6, 2021, 3:20pm UTC](https://discourse.cmake.org/t/postinstall-with-cmake/3701 "2021-07-06T15:20:18Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![alice](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alice/32/1615_2.png) [@alice](https://discourse.cmake.org/u/alice)
#### Post date: [July 6, 2021, 3:20pm UTC](https://discourse.cmake.org/t/postinstall-with-cmake/3701/1 "2021-07-06T15:20:18Z")

</div>

How to create a postinstall or preinstall with cmake (macOS

---

<div class="post-metadata">

### Author: ![alice](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alice/32/1615_2.png) [@alice](https://discourse.cmake.org/u/alice)
#### Post date: [July 9, 2021, 9:49am UTC](https://discourse.cmake.org/t/postinstall-with-cmake/3701/2 "2021-07-09T09:49:08Z")

</div>

How to create a postinstall or preinstall with cmake (macOS  
For example,  
I use the  
CPACK\_PREFLIGHT\_SCRIPT or CPACK\_POSTFLIGHT\_SCRIPT  
But it doesnt work .

cmakelist  
set(CPACK\_PREFLIGHT\_SCRIPT “${PROJECT\_BINARY\_DIR}/preinstall.sh”)  
set(CPACK\_POSTFLIGHT\_SCRIPT “${PROJECT\_SOURCE\_DIR}/scripts/postinstall.sh”)

preinstall.sh  
#!/bin/sh  
mkdir -p /User/user/Desktop/123  
echo “Here is do the post install”  
exit 0

[https://cmake.org/cmake/help/latest/command/add\_custom\_command.html#build-events](https://cmake.org/cmake/help/latest/command/add_custom_command.html#build-events)

[https://cmake.org/cmake/help/latest/module/CPack.html#variable:CPACK\_PRE\_BUILD\_SCRIPTS](https://cmake.org/cmake/help/latest/module/CPack.html#variable:CPACK_PRE_BUILD_SCRIPTS)

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [July 9, 2021, 11:08pm UTC](https://discourse.cmake.org/t/postinstall-with-cmake/3701/3 "2021-07-09T23:08:29Z")

</div>

Please post a complete, minimal example that demonstrates the problem. Include the commands you are running. The links you provided are for different variables to the ones you say are not working.

---

<div class="post-metadata">

### Author: ![alice](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alice/32/1615_2.png) [@alice](https://discourse.cmake.org/u/alice)
#### Post date: [July 11, 2021, 3:38am UTC](https://discourse.cmake.org/t/postinstall-with-cmake/3701/4 "2021-07-11T03:38:58Z")

</div>

The above message is just the sample that I find. In fact, I dont have any idea.  
I dont have the experience of preinstall and postistall. Could you give me a advance and sample for preinstall and post install?  
How to create a postinstall or preinstall with cmake (macOS  
Thanks.
