compiler-rt suspect race condition in add_custom_command

On MacPorts we are seeing intermittent error reports from some users when building compiler-rt from clang-12 using parallel builds on faster machines.


CMake Error: failed to create symbolic link ‘/opt/local/var/macports/build/_Users_blairzajac_Code_MacPorts_macports-ports.git_lang_llvm-12/clang-12/work/build/projects/compiler-rt/lib/builtins/outline_atomic_helpers.dir/outline_atomic_ldset1_2.S’: file already exists

I believe this is due to this add_custom_command invocation:


I am not a cmake expert, but I believe this issue is covered by cmake here:

“Do not list the output in more than one independent target that may build in parallel or the two instances of the rule may conflict (instead use the add_custom_target() command to drive the command and make the other targets depend on that one).”


If so, it seems that the proper solution to this would be to add_custom_target a dependency on “${helper_asm}”, perhaps something like this?

add_custom_target(compiler-rt-asm ALL DEPENDS ${helper_asm})

I defer now to the cmake experts.