# How to add\_executable(targetB MACOSX\_BUNDLE targetB.cc targetA) ?

**URL:** https://discourse.cmake.org/t/how-to-add-executable-targetb-macosx-bundle-targetb-cc-targeta/2482
**Category:** Code
**Created:** [January 5, 2021, 7:34pm UTC](https://discourse.cmake.org/t/how-to-add-executable-targetb-macosx-bundle-targetb-cc-targeta/2482 "2021-01-05T19:34:04Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![paulrichards321](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/c4cdca/32.png) [@paulrichards321](https://discourse.cmake.org/u/paulrichards321)
#### Post date: [January 5, 2021, 7:34pm UTC](https://discourse.cmake.org/t/how-to-add-executable-targetb-macosx-bundle-targetb-cc-targeta/2482/1 "2021-01-05T19:34:04Z")

</div>

include(CPack)  
…  
set(MACOSX\_BUNDLE TRUE)  
set(MACOSX\_BUNDLE\_BUNDLE\_NAME targetB)  
set(MACOSX\_BUNDLE\_ICON\_FILE iconfile.icns)  
set(MACOSX\_BUNDLE\_STARTUP\_COMMAND targetB)  
add\_executable(targetA targetA.cc)  
add\_executable(targetB MACOSX\_BUNDLE targetB.cc)  
add\_dependency(targetB targetA)  
…

I have a C++ exe targetB on Mac OS X, and I am trying to get a previous dependent targetA (not a library, another executable) into it’s sources so that it will be put into the same bundle. If I leave out targetA from the sources in the add\_executable command it doesn’t get in the bundle. However, if I leave it in it won’t build because cmake says the targetA doesn’t exist.

Any ideas?

---

<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: [January 5, 2021, 8:04pm UTC](https://discourse.cmake.org/t/how-to-add-executable-targetb-macosx-bundle-targetb-cc-targeta/2482/2 "2021-01-05T20:04:44Z")

</div>

You shouldn’t need the `add_dependencies`, but it probably doesn’t hurt too much either. You probably need a `install(TARGETS targetA)` with the appropriate destination. You’ll want it to come _after_ the install for `targetB` though so that the directory structure exists.

---

<div class="post-metadata">

### Author: ![mrmsdbdl](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mrmsdbdl/32/2686_2.png) [@mrmsdbdl](https://discourse.cmake.org/u/mrmsdbdl)
#### Post date: [October 29, 2021, 9:18am UTC](https://discourse.cmake.org/t/how-to-add-executable-targetb-macosx-bundle-targetb-cc-targeta/2482/3 "2021-10-29T09:18:26Z")

</div>

If I may jump in here for a sec. This is very similar to my question [here](https://discourse.cmake.org/t/creating-a-macos-app-bundle-from-several-executable-and-framework/4356). So, what you are suggesting is to build one of the executables as MACOSX\_BUNDLE and install the second on in the `Contents/MacOS` folder next to it, 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: [October 29, 2021, 12:26pm UTC](https://discourse.cmake.org/t/how-to-add-executable-targetb-macosx-bundle-targetb-cc-targeta/2482/4 "2021-10-29T12:26:03Z")

</div>

Yes, I think that works. It may not be the best solution though, but I don’t know of one right now.
