cmake add_custom_command + Xcode: multi output = multi command invocation

cross posting

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 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_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)

  DEPENDS gen_in.txt

add_executable(foo main.cpp ${MANY_HEADERS})

where is


echo " start"
sleep 1
echo " 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

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.