# How to compile a storyboard file with dependency tracking

**URL:** <https://discourse.cmake.org/t/how-to-compile-a-storyboard-file-with-dependency-tracking/8020>\
**Category:** Code\
**Tags:** os:macos\
**Created:** [April 29, 2023, 9:39pm UTC](https://discourse.cmake.org/t/how-to-compile-a-storyboard-file-with-dependency-tracking/8020 "2023-04-29T21:39:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![TellowKrinkle](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/t/58f4c7/32.png) [@TellowKrinkle](https://discourse.cmake.org/u/TellowKrinkle)\
**Post date:** [April 29, 2023, 9:39pm UTC](https://discourse.cmake.org/t/how-to-compile-a-storyboard-file-with-dependency-tracking/8020/1 "2023-04-29T21:39:40Z")

</div>

I have a macOS bundle target, and would like to compile a `Main.storyboard` file and have it installed to `Target.app/Contents/Resources/Main.storyboardc`.

Normally for similar compile-and-copy actions, I’d do this:

```cmake
set(input ${CMAKE_CURRENT_SOURCE_DIR}/Main.storyboard)
set(output ${CMAKE_CURRENT_BINARY_DIR}/Main.storyboardc)
add_custom_command(OUTPUT ${output}
	COMMAND ${IBTOOL} --compile ${output} ${input}
	DEPENDS ${input})
target_sources(MyTarget PRIVATE ${output})
set_source_files_properties(${output} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)

```

This usually works fine, but it doesn’t work for `storyboardc` files, because they’re actually directories, and `MACOSX_PACKAGE_LOCATION` doesn’t recursively copy directories.  
Searching online for how to make `MACOSX_PACKAGE_LOCATION` copy directories only results in people saying to use `file(GLOB`, which won’t work here, since the directory doesn’t exist until the custom command has run.

Importantly, this does add a dependency from `MyTarget` to `Main.storyboard`, so if `Main.storyboard` is edited, it will be recompiled (and would be recopied if `MACOSX_PACKAGE_LOCATION` worked on directories)

Instead of using `MACOSX_PACKAGE_LOCATION`, I can attempt to generate the file in place with

```cmake
set(input ${CMAKE_CURRENT_SOURCE_DIR}/Main.storyboard)
set(output $<TARGET_BUNDLE_DIR:MyTarget>/Contents/Resources/Main.storyboardc)
add_custom_command(TARGET MyTarget POST_BUILD
	COMMAND ${IBTOOL} --compile ${output} ${input})

```

But this doesn’t properly put a dependency on `Main.storyboardc` (so if it’s edited, MyTarget won’t recompile)

Finally, I tried this

```cmake
set(input ${CMAKE_CURRENT_SOURCE_DIR}/Main.storyboard)
set(output ${CMAKE_CURRENT_BINARY_DIR}/Main.storyboardc)
set(install $<TARGET_BUNDLE_DIR:MyTarget>/Contents/Resources/Main.storyboardc)
add_custom_command(OUTPUT ${output}
	COMMAND ${IBTOOL} --compile ${output} ${input}
	DEPENDS ${input})
add_custom_target(copy_storyboard_main
	COMMAND ${CMAKE_COMMAND} -E remove_directory ${install}
	COMMAND ${CMAKE_COMMAND} -E copy_directory ${output} ${install}
	DEPENDS ${output})
add_dependencies(MyTarget copy_storyboard_main)

```

But it seems `TARGET_BUNDLE_DIR` adds a dependency on `MyTarget`, resulting in a mutual dependency.

Does anyone know a good way to make it so the `storyboardc` is properly installed, and `MyTarget` has a dependency on `Main.storyboard`?

---

<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:** [April 30, 2023, 1:46am UTC](https://discourse.cmake.org/t/how-to-compile-a-storyboard-file-with-dependency-tracking/8020/2 "2023-04-30T01:46:18Z")

</div>

If you are only using the Xcode generator, then you can leave most of the work up to Xcode itself.

```cmake
add_executable(MyApp MACOSX_BUNDLE
    Main.storyboard
    ....
)
set_source_files_properties(Main.storyboard PROPERTIES
    MACOSX_PACKAGE_LOCATION Resources
)

```

---

<div class="post-metadata">

**Author:** ![TellowKrinkle](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/t/58f4c7/32.png) [@TellowKrinkle](https://discourse.cmake.org/u/TellowKrinkle)\
**Post date:** [April 30, 2023, 3:42am UTC](https://discourse.cmake.org/t/how-to-compile-a-storyboard-file-with-dependency-tracking/8020/3 "2023-04-30T03:42:58Z")

</div>

We mainly compile with Ninja, though I use Xcode for development

(This is from [dolphin emulator](https://github.com/dolphin-emu/dolphin/blob/2e39c79984490e21a7428fd5f47ea99a0359cf64/Source/Core/MacUpdater/CMakeLists.txt#L49-L56), where I recently broke the updater thinking I could use `MACOSX_PACKAGE_LOCATION` for storyboards. It’s not super important, as no one actually edits the updater’s storyboard files, but it just feels kind of bad to know we have missing dependencies here.)
