This is an archive of the discontinued LLVM Phabricator instance.

llvm cmake: Fix NATIVE build when a toolchain file is already defined
AbandonedPublic

Authored by tpr on Feb 10 2021, 10:08 AM.

Details

Summary

Building on Windows with a cmake toolchain with LLVM called from an
outer cmake project ran into problems when LLVM does its inner "NATIVE"
cmake to build tablegen etc, in that some toolchain settings failed to
be conveyed into the NATIVE cmake, and it could not even run the initial
test for a working C compiler.

Fixed by passing the outer toolchain file if one was specified.

Fix from Juan Ramos, also from AMD.

Change-Id: I72d0c891d230393baaace79bfd14de953185ee21

Diff Detail

Event Timeline

tpr created this revision.Feb 10 2021, 10:08 AM
tpr requested review of this revision.Feb 10 2021, 10:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 10 2021, 10:08 AM
smeenai requested changes to this revision.Feb 10 2021, 11:15 AM

The NATIVE build is also used for cross-compilation scenarios (e.g. you're building on Windows but targeting Linux, but you still need tools like tablegen to be built targeting Windows), and for those cases, using the same CMAKE_TOOLCHAIN_FILE as the main build is completely incorrect.

What I've done to handle situations like this is set the CROSS_TOOLCHAIN_FLAGS_NATIVE cache variable to include the desired toolchain file for the NATIVE build (and any other desired CMake settings as well). Does that work for you? Something like -DCROSS_TOOLCHAIN_FLAGS_NATIVE="-DCMAKE_TOOLCHAIN_FILE=/path/to/your/toolchain/file" should do the trick.

This revision now requires changes to proceed.Feb 10 2021, 11:15 AM
tpr added a comment.Feb 10 2021, 12:04 PM

This fix is wrong. I have a test build that went into an infinitely recursive loop of doing NATIVE builds.

tpr added a comment.Feb 10 2021, 12:05 PM

The NATIVE build is also used for cross-compilation scenarios (e.g. you're building on Windows but targeting Linux, but you still need tools like tablegen to be built targeting Windows), and for those cases, using the same CMAKE_TOOLCHAIN_FILE as the main build is completely incorrect.

What I've done to handle situations like this is set the CROSS_TOOLCHAIN_FLAGS_NATIVE cache variable to include the desired toolchain file for the NATIVE build (and any other desired CMake settings as well). Does that work for you? Something like -DCROSS_TOOLCHAIN_FLAGS_NATIVE="-DCMAKE_TOOLCHAIN_FILE=/path/to/your/toolchain/file" should do the trick.

Thanks; I will try that.

tpr abandoned this revision.Feb 10 2021, 12:08 PM

Abandoning as it is the wrong fix.