# How to properly use bracket arguments in install(code)?

**URL:** https://discourse.cmake.org/t/how-to-properly-use-bracket-arguments-in-install-code/6889
**Category:** Code
**Created:** [November 17, 2022, 6:59am UTC](https://discourse.cmake.org/t/how-to-properly-use-bracket-arguments-in-install-code/6889 "2022-11-17T06:59:10Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![shakfu](https://discourse.cmake.org/user_avatar/discourse.cmake.org/shakfu/32/2929_2.png) [@shakfu](https://discourse.cmake.org/u/shakfu)
#### Post date: [November 17, 2022, 6:59am UTC](https://discourse.cmake.org/t/how-to-properly-use-bracket-arguments-in-install-code/6889/1 "2022-11-17T06:59:10Z")

</div>

I have been studying an [example](https://github.com/ionyshch/cmake-bundle-macos), by Ivan Onyshenko, which demonstrates how to use `fixup_bundle` and how cmake and cpack can create, for macOS, a bundle and also copy `.dylib` dependencies into that bundle.

That’s all fine. Now, in that `CMakeLists.tx` file there’s some code like the following:

```cmake

set(APPS "\${CMAKE_INSTALL_PREFIX}/${APP_NAME}.app")

# Directories to look for dependencies
set(DIRS "${CMAKE_BINARY_DIR}")

install(CODE "include(BundleUtilities)
    fixup_bundle(\"${APPS}\" \"\" \"${DIRS}\")")

```

This works fine.

My question is: is it possible, in this case, to use **bracket arguments** in `fixup_bundle`. I can’t seem to get it right.

I’ve tried to convert to the following without success:

```cmake
install(CODE [[
    include(BundleUtilities)
    fixup_bundle("${APPS}" "" "${DIRS}")
]])

```

And then I read somewhere that only `${CMAKE_INSTALL_PREFIX}` and generator expressions work in bracketted code. But even in this case, it doesn’t work:

```cmake
install(CODE [[
    include(BundleUtilities)
    fixup_bundle(
    "${CMAKE_INSTALL_PREFIX}/PortableApp.app"
    "" 
    "${CMAKE_INSTALL_PREFIX}")
]])

```

So are bracket arguments usable in this context? If not, how to avoid all this escaping which I personally find tedious and error-prone?

---

<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 17, 2022, 2:29pm UTC](https://discourse.cmake.org/t/how-to-properly-use-bracket-arguments-in-install-code/6889/2 "2022-11-17T14:29:34Z")

</div>

`install(SCRIPT)` would be the way to go I think. Note that the “what variables work” part is about what variables are present in the install script environment. If you want configure-time variables to be used, `@var@` expansion and `configure_file` can be used to create the path given to `install(SCRIPT)`.

---

<div class="post-metadata">

### Author: ![shakfu](https://discourse.cmake.org/user_avatar/discourse.cmake.org/shakfu/32/2929_2.png) [@shakfu](https://discourse.cmake.org/u/shakfu)
#### Post date: [November 18, 2022, 6:30am UTC](https://discourse.cmake.org/t/how-to-properly-use-bracket-arguments-in-install-code/6889/3 "2022-11-18T06:30:42Z")

</div>

Thanks @ben.boeckel for your reply.

Just to flesh out your answer. Would it mean that I have something like a `fixup_osx.cmake.in` file which contains the `@var@` variables which are defined somewhere in the `CMakeList.txt` file, and then use `configure_file` to take `fixup_osx.cmake.in` and output `fixup_osx.cmake` with the vars now expanded and then use `install(SCRIPT fixup_osx.cmake)` to execute the installation commands in that file.

Does that sequence sound about right?

---

<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 18, 2022, 12:31pm UTC](https://discourse.cmake.org/t/how-to-properly-use-bracket-arguments-in-install-code/6889/4 "2022-11-18T12:31:22Z")

</div>

Sounds like the right direction to me.

---

<div class="post-metadata">

### Author: ![shakfu](https://discourse.cmake.org/user_avatar/discourse.cmake.org/shakfu/32/2929_2.png) [@shakfu](https://discourse.cmake.org/u/shakfu)
#### Post date: [November 18, 2022, 2:18pm UTC](https://discourse.cmake.org/t/how-to-properly-use-bracket-arguments-in-install-code/6889/5 "2022-11-18T14:18:40Z")

</div>

Thanks @ben.boeckel, that was very helpful.
