<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - CMake configure fails with multiple duplicate target clashes"
   href="https://bugs.llvm.org/show_bug.cgi?id=49156">49156</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>CMake configure fails with multiple duplicate target clashes
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>Build scripts
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>release blocker
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>cmake
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>kkm@pobox.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=24520" name="attach_24520" title="CMakeError.log and CMakeOutput.log">attachment 24520</a> <a href="attachment.cgi?id=24520&action=edit" title="CMakeError.log and CMakeOutput.log">[details]</a></span>
CMakeError.log and CMakeOutput.log

Debian 10 X64, Cmake 3.19.2, tip of the release12.x branch from the repo.

This is my first attempt to build the Clang toolchain from scratch. When I
attempted to generate build files for Ninja, I got 16 nearly identical
failures:

CMake Error at cmake/modules/LLVMExternalProjectUtils.cmake:330
(add_custom_target):
  add_custom_target cannot create target "cxxabi" because another target with
  the same name already exists.  The existing target is a custom target
  created in source directory "/home/kkm/work/llvm-project/libcxxabi/src".
  See documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
  runtimes/CMakeLists.txt:230 (llvm_ExternalProject_Add)
  runtimes/CMakeLists.txt:365 (runtime_default_target)

All of them mention the same files and line numbers, and differ only in the
target name and the source directory. Here's what I'm grepping out of the whole
list of these errors:

$ printf "%s\t%s\n" $(grep -Po '".+?"' errs)
"builtins"      "/home/kkm/work/llvm-project/compiler-rt/lib/builtins"
"compiler-rt"   "/home/kkm/work/llvm-project/compiler-rt"
"install-compiler-rt"   "/home/kkm/work/llvm-project/compiler-rt"
"install-compiler-rt-stripped"  "/home/kkm/work/llvm-project/compiler-rt"
"cxx"   "/home/kkm/work/llvm-project/libcxx/src"
"install-cxx"   "/home/kkm/work/llvm-project/libcxx/src"
"install-cxx-stripped"  "/home/kkm/work/llvm-project/libcxx/src"
"cxxabi"        "/home/kkm/work/llvm-project/libcxxabi/src"
"install-cxxabi"        "/home/kkm/work/llvm-project/libcxxabi/src"
"install-cxxabi-stripped"       "/home/kkm/work/llvm-project/libcxxabi/src"
"unwind"        "/home/kkm/work/llvm-project/libunwind/src"
"install-unwind"        "/home/kkm/work/llvm-project/libunwind/src"
"install-unwind-stripped"       "/home/kkm/work/llvm-project/libunwind/src"
"check-cxx"     "/home/kkm/work/llvm-project/libcxx/test"
"check-cxxabi"  "/home/kkm/work/llvm-project/libcxxabi/test"
"check-unwind"  "/home/kkm/work/llvm-project/libunwind/test"

This is a chunk of my build script:

projects="clang;clang-tools-extra;compiler-rt;libcxxabi;libcxx;libunwind;lld;lldb;polly"
runtimes="compiler-rt;libcxx;libcxxabi;libunwind"
vendor="kkm[210212]"

set -ex

[[ -d .git && -d llvm ]] || exit 1

cmake -S llvm -B Build -G Ninja                 \
      -DCMAKE_POLICY_DEFAULT_CMP0002=NEW        \
      -DCMAKE_POLICY_DEFAULT_CMP0114=NEW        \
      -DCMAKE_CXX_STANDARD=17                   \
      -DCMAKE_BUILD_TYPE=Release                \
      -DCMAKE_C_COMPILER=clang-11               \
      -DCMAKE_CXX_COMPILER=clang++-11           \
      -DLLVM_ENABLE_PROJECTS="$projects"        \
      -DLLVM_ENABLE_RUNTIMES="$runtimes"        \
      -DCLANG_DEFAULT_CXX_STDLIB=libc++         \
      -DCLANG_DEFAULT_RTLIB=compiler-rt         \
      -DCLANG_VENDOR="$vendor"                  \
      -DLLD_VENDOR="$vendor"                    \
      -DLLVM_BUILD_32_BITS=OFF                  \
      -DLLVM_CCACHE_BUILD=ON                    \
      -DLLVM_TARGETS_TO_BUILD=X86               \
      -DLLVM_ENABLE_LLD=ON                      \
      -DLLVM_ENABLE_DOXYGEN=ON                  \
      -DLLVM_ENABLE_OCAMLDOC=OFF                \
      -DLLVM_OPTIMIZED_TABLEGEN=ON              \
      -DLLVM_LIBDIR_SUFFIX=64                   \
      -DENABLE_EXPERIMENTAL_NEW_PASS_MANAGER=ON \
      -DLIBCXXABI_USE_LLVM_UNWINDER=ON          \
      -DLIBCXXABI_USE_COMPILER_RT=ON            \
      -DLIBCXX_CXX_ABI=libcxxabi                \
      -DLIBUNWIND_USE_COMPILER_RT=ON


The policies CMP0002 and CMP0114 were mentioned in these messages, and I tried
all 4 combinations of OLD/NEW, to no avail. Am I doing it wrong, or is this a
genuine bug?

My goal is to build the toolchain to be as self-contained as possible, using
only the system's own libc6, because my final target must be Amazon Linux 2
Docker image, based on the very aged RHEL7, although they so luckily threw in a
newer GCC 7.x, which is, fingers crossed, probably recent enough to bootstrap
the whole kaboodle. The SLES pre-built rpms from GitHub releases almost did it,
but not quite (lib directories did not match), unfortunately, so building from
source seems the cleanest option. If only it weren't failing... :)

I'm attaching CMake output logs, just in case, from my final run with exactly
these arguments. Let me know please if any other generated files will be
helpful. Thanks!</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>