Build same lib with identical names in subninjas

I am trying to create a build containing several cmake projects. Splitting the “whole” project into multiple cmake projects is necessary to support different C++ toolchains in one build.
We use the ninja generator and have a main cmake file which runs “cmake” with CMAKE_NINJA_OUTPUT_PATH_PREFIX=toolchainX in multiple subdirectories of the main build. In general, this works fine and we can reference the files from the sub-builds as “toolchainX/fileX” from the main build.
However, in some cases, cmake generates cmake_object_order_depends_target_{target} targets. From I read that these targets are generated basically if a custom_command does not properly list all OUTPUTs (please correct me if I’m wrong).
The problem in this case is, that the cmake_object_order_depends_target_{target} are now defined multiple times, if the same target (e.g. a common shared library) is built in multiple subninjas. The “builds involving this target will not be correct” warning proves to be right in this case, and the build fails.

I see the following solutions:

  1. List all outputs in add_custom_command/target. In our case, this is a problem, because the output is generated dynamically by a third-party tool which does not generate depfiles. This would be hell to maintain.
  2. Add a new variable for a prefix/suffix for cmake_object_order_depends_target_ analogous to CMAKE_NINJA_OUTPUT_PATH_PREFIX. This would probably need to be added for all target (as in non-file) names somehow.

Is there a solution for this problem with already-implemented tools? I searched for a prefix/suffix which is applied to all target names, but I found nothing.

I also tried using the “Ninja Multi-Config” generator and just use a different config for each sub-build. However, the Multi-Config generator does not seem to acknowledge CMAKE_NINJA_OUTPUT_PATH_PREFIX.

Hrm. I suppose the prefix needs to be incorporated here. Do you mind filing an issue about this?