<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 - llvm-exegesis build on x86 doesn't set LLVM_EXEGESIS_INITIALIZE_NATIVE_TARGET"
   href="https://bugs.llvm.org/show_bug.cgi?id=39021">39021</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>llvm-exegesis build on x86 doesn't set LLVM_EXEGESIS_INITIALIZE_NATIVE_TARGET
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>7.0
          </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>normal
          </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>steven@uplinklabs.net
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Something's up with the llvm-exegesis build process on 7.0.0 release. On my x86
machines they always complain "no exegesis target for x86_64-pc-linux-gnu,
using default", and this seems to be because
LLVM_EXEGESIS_INITIALIZE_NATIVE_TARGET never gets set by CMake.

The CMake scripts try to set LLVM_EXEGESIS_TARGETS in the lib subdirectory, but
this doesn't seem to work properly. I made this change to figure out what's
happening:

---

diff --git a/tools/llvm-exegesis/CMakeLists.txt
b/tools/llvm-exegesis/CMakeLists.txt
index 65b1ada8529..94842519ca7 100644
--- a/tools/llvm-exegesis/CMakeLists.txt
+++ b/tools/llvm-exegesis/CMakeLists.txt
@@ -8,7 +8,9 @@ add_llvm_tool(llvm-exegesis
   llvm-exegesis.cpp
   )

+message(WARNING "LLVM_EXEGESIS_TARGETS at parent scope before:
${LLVM_EXEGESIS_TARGETS}")
 add_subdirectory(lib)
+message(FATAL_ERROR "LLVM_EXEGESIS_TARGETS at parent scope after:
${LLVM_EXEGESIS_TARGETS}")

 # Link the native exegesis target if compiled and on the right host.
 if ((LLVM_TARGETS_TO_BUILD MATCHES "${LLVM_NATIVE_ARCH}") AND
(LLVM_EXEGESIS_TARGETS MATCHES "${LLVM_NATIVE_ARCH}"))
diff --git a/tools/llvm-exegesis/lib/CMakeLists.txt
b/tools/llvm-exegesis/lib/CMakeLists.txt
index 175c2adf9de..4dc91ef125c 100644
--- a/tools/llvm-exegesis/lib/CMakeLists.txt
+++ b/tools/llvm-exegesis/lib/CMakeLists.txt
@@ -1,12 +1,18 @@
+message( WARNING "LLVM_EXEGESIS_TARGETS before: ${LLVM_EXEGESIS_TARGETS}" )
+
 if (LLVM_TARGETS_TO_BUILD MATCHES "X86")
   add_subdirectory(X86)
+  message( WARNING "Appending X86" )
   set(LLVM_EXEGESIS_TARGETS "${LLVM_EXEGESIS_TARGETS} X86" PARENT_SCOPE)
 endif()
 if (LLVM_TARGETS_TO_BUILD MATCHES "AArch64")
   add_subdirectory(AArch64)
+  message( WARNING "Appending AArch64" )
   set(LLVM_EXEGESIS_TARGETS "${LLVM_EXEGESIS_TARGETS} AArch64" PARENT_SCOPE)
 endif()

+message( WARNING "LLVM_EXEGESIS_TARGETS after: ${LLVM_EXEGESIS_TARGETS}" )
+
 add_library(LLVMExegesis
   STATIC
   Analysis.cpp

---

This results in this behavior (extraneous newlines removed for readability):

CMake Warning at tools/llvm-exegesis/CMakeLists.txt:11 (message):
  LLVM_EXEGESIS_TARGETS at parent scope before:
CMake Warning at tools/llvm-exegesis/lib/CMakeLists.txt:1 (message):
  LLVM_EXEGESIS_TARGETS before:
CMake Warning at tools/llvm-exegesis/lib/CMakeLists.txt:5 (message):
  Appending X86
CMake Warning at tools/llvm-exegesis/lib/CMakeLists.txt:10 (message):
  Appending AArch64
CMake Warning at tools/llvm-exegesis/lib/CMakeLists.txt:14 (message):
  LLVM_EXEGESIS_TARGETS after:
CMake Error at tools/llvm-exegesis/CMakeLists.txt:13 (message):
  LLVM_EXEGESIS_TARGETS at parent scope after: AArch64

So reading the LLVM_EXEGESIS_TARGETS variable in lib/CMakeLists.txt doesn't
work properly, and the second set(... PARENT_SCOPE) just sees the empty
LLVM_EXEGESIS_TARGETS value, overwriting the previously appended X86 value.

Any ideas on how to fix this? I'm doing this locally but it seems sloppy:

diff --git a/tools/llvm-exegesis/lib/CMakeLists.txt
b/tools/llvm-exegesis/lib/CMakeLists.txt
index 175c2adf9de..194304adf98 100644
--- a/tools/llvm-exegesis/lib/CMakeLists.txt
+++ b/tools/llvm-exegesis/lib/CMakeLists.txt
@@ -1,12 +1,16 @@
+set(TARGETS_TO_APPEND "")
+
 if (LLVM_TARGETS_TO_BUILD MATCHES "X86")
   add_subdirectory(X86)
-  set(LLVM_EXEGESIS_TARGETS "${LLVM_EXEGESIS_TARGETS} X86" PARENT_SCOPE)
+  set(TARGETS_TO_APPEND "${TARGETS_TO_APPEND} X86")
 endif()
 if (LLVM_TARGETS_TO_BUILD MATCHES "AArch64")
   add_subdirectory(AArch64)
-  set(LLVM_EXEGESIS_TARGETS "${LLVM_EXEGESIS_TARGETS} AArch64" PARENT_SCOPE)
+  set(TARGETS_TO_APPEND "${TARGETS_TO_APPEND} AArch64")
 endif()

+set(LLVM_EXEGESIS_TARGETS "${LLVM_EXEGESIS_TARGETS} ${TARGETS_TO_APPEND}"
PARENT_SCOPE)
+
 add_library(LLVMExegesis
   STATIC
   Analysis.cpp</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>