I am trying to compile llvm using a toolchain file where I have specified the target system and compilers as suggested at https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compilation-tool chain: set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_PROCESSOR arm) set(CMAKE_C_COMPILER arm-unknown-linux-gnueabi-gcc) set(CMAKE_CXX_COMPILER arm-unknown-linux-gnueabi-g++) But the problem is that native tools like llvm-config, llvm-tblgen and clang-tblgen, which must be built by the native compiler, are also created by the target compiler. What cmake / "toolchain file" options should I use to use the native (host) compiler for these native tools (which are placed in the NATIVE subdirectory), and target compilers for other binaries and libraries?
Hello, There might be a smarter way - but I just build the tree twice: mkdir native ; cd native ; cmake -GNinja .. ; ninja mkdir target ; cd target ; cmake -GNinja -DCMAKE_TOOLCHAIN_FILE=cross.cmake -DLLVM_TABLEGEN_PATH=../native/bin/llvm-tblgen .. I know there are runtime builds as well - but I am not familiar with it. -- Tobias On Thu, Sep 17, 2020 at 3:28 PM Денис Онищенко via llvm-dev <llvm-dev at lists.llvm.org> wrote:> > I am trying to compile llvm using a toolchain file where I have > specified the target system and compilers as suggested at > https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compilation-tool > chain: > > set(CMAKE_SYSTEM_NAME Linux) > set(CMAKE_SYSTEM_PROCESSOR arm) > > set(CMAKE_C_COMPILER arm-unknown-linux-gnueabi-gcc) > set(CMAKE_CXX_COMPILER arm-unknown-linux-gnueabi-g++) > > But the problem is that native tools like llvm-config, llvm-tblgen and > clang-tblgen, which must be built by the native compiler, are also > created by the target compiler. > > What cmake / "toolchain file" options should I use to use the native > (host) compiler for these native tools (which are placed in the NATIVE > subdirectory), and target compilers for other binaries and libraries? > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
But besides the fact that building llvm is very time-consuming, there is another serious problem with this method: llvm-config built in this way will return incorrect results that are related to the host, not the target. 2020-09-17 16:47 GMT+03:00, Tobias Hieta <tobias at plexapp.com>:> Hello, > > There might be a smarter way - but I just build the tree twice: > > mkdir native ; cd native ; cmake -GNinja .. ; ninja > mkdir target ; cd target ; cmake -GNinja > -DCMAKE_TOOLCHAIN_FILE=cross.cmake > -DLLVM_TABLEGEN_PATH=../native/bin/llvm-tblgen .. > > I know there are runtime builds as well - but I am not familiar with it. > > -- Tobias > > On Thu, Sep 17, 2020 at 3:28 PM Денис Онищенко via llvm-dev > <llvm-dev at lists.llvm.org> wrote: >> >> I am trying to compile llvm using a toolchain file where I have >> specified the target system and compilers as suggested at >> https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compilation-tool >> chain: >> >> set(CMAKE_SYSTEM_NAME Linux) >> set(CMAKE_SYSTEM_PROCESSOR arm) >> >> set(CMAKE_C_COMPILER arm-unknown-linux-gnueabi-gcc) >> set(CMAKE_CXX_COMPILER arm-unknown-linux-gnueabi-g++) >> >> But the problem is that native tools like llvm-config, llvm-tblgen and >> clang-tblgen, which must be built by the native compiler, are also >> created by the target compiler. >> >> What cmake / "toolchain file" options should I use to use the native >> (host) compiler for these native tools (which are placed in the NATIVE >> subdirectory), and target compilers for other binaries and libraries? >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >
On Thu, 17 Sep 2020, Денис Онищенко via llvm-dev wrote:> I am trying to compile llvm using a toolchain file where I have > specified the target system and compilers as suggested at > https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compilation-tool > chain: > > set(CMAKE_SYSTEM_NAME Linux) > set(CMAKE_SYSTEM_PROCESSOR arm) > > set(CMAKE_C_COMPILER arm-unknown-linux-gnueabi-gcc) > set(CMAKE_CXX_COMPILER arm-unknown-linux-gnueabi-g++) > > But the problem is that native tools like llvm-config, llvm-tblgen and > clang-tblgen, which must be built by the native compiler, are also > created by the target compiler. > > What cmake / "toolchain file" options should I use to use the native > (host) compiler for these native tools (which are placed in the NATIVE > subdirectory), and target compilers for other binaries and libraries?You need to pass -DCROSS_TOOLCHAIN_FLAGS_NATIVE="" during the cross build, to fix your build of the llvm-config/llvm-tblgen/clang-tblgen native tools. The reason for this is that if CROSS_TOOLCHAIN_FLAGS_NATIVE isn't set, it's default initialized to pass on your CMAKE_CXX_COMPILER to the native build process as well, which won't do the right thing in this kind of cross setup. // Martin