jacobly0 / llvm-project

This fork of the canonical git mirror of the LLVM subversion repository adds (e)Z80 targets. Please refer to the wiki for important build instructions.
https://github.com/jacobly0/llvm-project/wiki
123 stars 15 forks source link

CMake: Fix build time problem with Z80 backend. #9

Closed pawosm-arm closed 4 years ago

pawosm-arm commented 4 years ago

Without this patch, CMake fails with following message:

CMake Error at cmake/config-ix.cmake:423 (message):
  Unknown architecture z80
Call Stack (most recent call first):
  CMakeLists.txt:629 (include)

I'm starting cmake command with following flags:

-DCMAKE_CXX_STANDARD=17 \
-DBUILD_SHARED_LIBS=True \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=$HOME/llvm-z80 \
-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="Z80" \
-DLLVM_TARGETS_TO_BUILD="" \
-DLLVM_TARGET_ARCH="Z80" \
-DLLVM_DEFAULT_TARGET_TRIPLE="z80-none-unknown" \
-DLLVM_ENABLE_PROJECTS="clang;lld;compiler-rt;lldb" \
-DLLVM_ENABLE_FFI=False \
-DOCAMLFIND="" \
-DLLVM_ENABLE_OCAMLDOC=OFF \
-DLLVM_INSTALL_UTILS=ON \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DLLDB_ENABLE_PYTHON=OFF
adriweb commented 4 years ago

Hmm, why are you trying to build it that way?

Building it following these instructions doesn't generate any error: https://github.com/jacobly0/llvm-project/wiki

pawosm-arm commented 4 years ago

Carried on script used for other LLVM projects I used to work on. Still those critical options are the same, the most significant difference I can see is that I'm explicitly setting target architecture and default triple. It could be anticipated someone may find it useful to do so one day.

jacobly0 commented 4 years ago

-DLLVM_TARGET_ARCH=Z80 would mean that you are cross compiling and targeting z80, which I highly doubt.

pawosm-arm commented 4 years ago

Maybe I got it wrong, but I was expecting LLVM with Z80 backend to be able to (also) act as an SDCC replacement. I do have system-wide installed LLVM targeting all of the architectures and I have couple of $HOME-installed LLVM's targeting just single architecture (e.g. AArch64), hence being just that: the crosscompilers. I guess such use case scenario isn't that uncommon.

pawosm-arm commented 4 years ago

So I looked into CMake settings, apparently, this option affects LLVM JIT only, which is not of our concern. Still, another 8-bit arch, avr, is allowed to be set there as it's listed in config-ix.cmake.

jacobly0 commented 4 years ago

No, it means you are cross compiling LLVM itself to Z80, in the sense that the clang executable you build would contain Z80 machine code, and the lli executable you build would be able to dynamically generate and execute Z80 code.

pawosm-arm commented 4 years ago

No, it means you are cross compiling LLVM itself to Z80, in the sense that the clang executable you build would contain Z80 machine code, and the lli executable you build would be able to dynamically generate and execute Z80 code.

I'm pretty sure CMake options to cross-compile are different and are more generic than anything LLVM_-prefixed.

pawosm-arm commented 4 years ago

Apparently, you're right. Although LLVM_TARGET_ARCH option itself does not cause cross-compilation (other CMake options are responsible for that), it is useful only when LLVM is cross-compiled. The fact that I was able to build avr-targeting LLVM cross-compiler with this option set misled me completely.