The target `X86' is not a core tier target

I’m currently trying to build LLVM for android, it works fine until I get to i686-linux-android.

I really don’t understand why this is happening and what is happening there, I added some debug output to the llvm CMakeList.txt file:

# ...
foreach(t ${LLVM_TARGETS_TO_BUILD})
  set( td ${LLVM_MAIN_SRC_DIR}/lib/Target/${t} )
  message("t: \"${t}\"")
  message("LLVM_ALL_TARGETS: \"${LLVM_ALL_TARGETS}\"")
  list(GET LLVM_ALL_TARGETS 17 LLVM_ALL_TARGETS_17)
  message("LLVM_ALL_TARGETS_17: \"${LLVM_ALL_TARGETS_17}\"")

  string(HEX ${t} HEX_STRING1)
  message("HEX_STRING1: ${HEX_STRING1}")

  string(HEX ${LLVM_ALL_TARGETS_17} HEX_STRING2)
  message("HEX_STRING2: ${HEX_STRING2}")


  if (${t} IN_LIST LLVM_ALL_TARGETS)
      message("A CONTAINED IN LLVM TARGET")
  else()
      message("A NOT CONTAINED IN LLVM TARGET")
  endif()


  if (${LLVM_ALL_TARGETS_17} IN_LIST LLVM_ALL_TARGETS)
      message("B CONTAINED IN LLVM TARGET")
  else()
      message("B NOT CONTAINED IN LLVM TARGET")
  endif()

  # Make sure that any experimental targets were passed via
  # LLVM_EXPERIMENTAL_TARGETS_TO_BUILD, not LLVM_TARGETS_TO_BUILD.
  # We allow experimental targets that are not in LLVM_ALL_EXPERIMENTAL_TARGETS,
  # as long as they are passed via LLVM_EXPERIMENTAL_TARGETS_TO_BUILD.
  if ( NOT ${t} IN_LIST LLVM_ALL_TARGETS AND NOT ${t} IN_LIST LLVM_EXPERIMENTAL_TARGETS_TO_BUILD )
    if( ${t} IN_LIST LLVM_ALL_EXPERIMENTAL_TARGETS )
      message(FATAL_ERROR "The target `${t}' is experimental and must be passed "
        "via LLVM_EXPERIMENTAL_TARGETS_TO_BUILD.")
    else()
      message(FATAL_ERROR "The target `${t}' is not a core tier target. It may be "
        "experimental, if so it must be passed via "
        "LLVM_EXPERIMENTAL_TARGETS_TO_BUILD.\n"
        "Core tier targets: ${LLVM_ALL_TARGETS}\n"
        "Known experimental targets: ${LLVM_ALL_EXPERIMENTAL_TARGETS}")
    endif()
  else()
    set(LLVM_ENUM_TARGETS "${LLVM_ENUM_TARGETS}LLVM_TARGET(${t})\n")
  endif()

# ....

This is the output this gives me:

...
t: "X86"
LLVM_ALL_TARGETS: "AArch64;AMDGPU;ARM;AVR;BPF;Hexagon;Lanai;LoongArch;Mips;MSP430;NVPTX;PowerPC;RISCV;Sparc;SystemZ;VE;WebAssembly;X86;XCore"
LLVM_ALL_TARGETS_17: "X86"
HEX_STRING1: 583836
HEX_STRING2: 583836
A NOT CONTAINED IN LLVM TARGET
B NOT CONTAINED IN LLVM TARGET
CMake Error at CMakeLists.txt:955 (message):
  The target `X86' is not a core tier target.  It may be experimental, if so
  it must be passed via LLVM_EXPERIMENTAL_TARGETS_TO_BUILD.

  Core tier targets:
  AArch64;AMDGPU;ARM;AVR;BPF;Hexagon;Lanai;LoongArch;Mips;MSP430;NVPTX;PowerPC;RISCV;Sparc;SystemZ;VE;WebAssembly;X86;XCore


  Known experimental targets: ARC;CSKY;DirectX;M68k;SPIRV;Xtensa


-- Configuring incomplete, errors occurred!

How is this even possible? LLVM_ALL_TARGETS contains X86 I can access it with list(GET …). I’m even checking for the hex value, to make sure it’s not a weird ASCII character.

It works fine for ARM, AArch64, even for X86_64, how is this possible? :frowning:

EDIT:
It appears to be related to using the android ndk (r25c), as soon as the CMAKE_TOOLCHAIN_FILE is set the error happens.

Also the following change in llvm\CMakeLists.txt would make it work:

# Changing this:
if ( NOT ${t} IN_LIST LLVM_ALL_TARGETS AND NOT ${t} IN_LIST LLVM_EXPERIMENTAL_TARGETS_TO_BUILD )

# To that
if ( NOT "${t}" IN_LIST LLVM_ALL_TARGETS AND NOT "${t}" IN_LIST LLVM_EXPERIMENTAL_TARGETS_TO_BUILD )

Any ideas why this could happend? Also it doesn’t feel right to change the llvm CMakeLists.txt file for that, feels like there is another underlying issue here?

I suspect that you’re running into a “fun” CMake feature if — CMake 3.27.6 Documentation, where the NDK CMake toolchain is defining a variable named X86, which affects our if conditionals. Either adding the quotes or removing the ${} would fix this, and I’d encourage you to put up a pull request to do so :slight_smile:

Oh wow, thanks for the info! Sure I’ll try to get on that pull request in the next couple days! :slight_smile:

1 Like

There now is a pull request addressing this issue.