# cmake add\_custom\_command + Xcode: multi output = multi command invocation

**URL:** https://discourse.cmake.org/t/cmake-add-custom-command-xcode-multi-output-multi-command-invocation/1303
**Category:** Usage
**Created:** [June 1, 2020, 5:36pm UTC](https://discourse.cmake.org/t/cmake-add-custom-command-xcode-multi-output-multi-command-invocation/1303 "2020-06-01T17:36:30Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![davemilter](https://discourse.cmake.org/user_avatar/discourse.cmake.org/davemilter/32/541_2.png) [@davemilter](https://discourse.cmake.org/u/davemilter)
#### Post date: [June 1, 2020, 5:36pm UTC](https://discourse.cmake.org/t/cmake-add-custom-command-xcode-multi-output-multi-command-invocation/1303/1 "2020-06-01T17:36:30Z")

</div>

[cross posting](https://stackoverflow.com/questions/62137725/cmake-add-custom-command-xcode-multi-output-multi-command-invocation)

I have custom command that generate several headers at once.  
All works fine with make/ninja files generated by cmake.  
But if I generate Xcode project via `cmake -GXCode`,  
then instead of once `gen.sh` was invoked 10 times  
and not only that, it also will be invoked every build,  
even if timestamps of generated file are younger then gen\_in.txt.

How can I fix this?

```cmake
project(multi_output)
cmake_minimum_required(VERSION 3.17)

set(MANY_HEADERS test0.h test1.h test2.h test3.h test4.h test5.h test6.h test7.h test8.h test9.h)

add_custom_command(
  OUTPUT ${MANY_HEADERS}
  COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/gen.sh
  DEPENDS gen_in.txt
  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  )

add_executable(foo main.cpp ${MANY_HEADERS})

```

where gen.sh is

```auto
#!/bin/sh

echo "gen.sh: start"
sleep 1
echo "gen.sh: hard work done"
for i in `seq 0 9`; do
    cat gen_in.txt > test$i.h
    sed -i bak s/placeholder/$i/g test$i.h
done

```

---

<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 10, 2020, 2:33pm UTC](https://discourse.cmake.org/t/cmake-add-custom-command-xcode-multi-output-multi-command-invocation/1303/2 "2020-11-10T14:33:26Z")

</div>

You have a working directory of the source directory, but I believe relative paths in `OUTPUT` are computed to be relative to the binary directory. I recommend using absolute paths for `MANY_HEADERS` items.
