[PATCH] D96433: llvm cmake: Fix NATIVE build when a toolchain file is already defined

Tim Renouf via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 10 10:08:06 PST 2021


tpr created this revision.
Herald added a subscriber: mgorny.
tpr requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96433

Files:
  llvm/cmake/modules/CrossCompile.cmake


Index: llvm/cmake/modules/CrossCompile.cmake
===================================================================
--- llvm/cmake/modules/CrossCompile.cmake
+++ llvm/cmake/modules/CrossCompile.cmake
@@ -12,10 +12,16 @@
     message(STATUS "Setting native build dir to " ${${project_name}_${target_name}_BUILD})
   endif(NOT DEFINED ${project_name}_${target_name}_BUILD)
 
-  if (EXISTS ${LLVM_MAIN_SRC_DIR}/cmake/platforms/${toolchain}.cmake)
+  if (DEFINED CMAKE_TOOLCHAIN_FILE)
+    # A toolchain file has already been defined, so use it.
+    # Useful for projects consuming LLVM that define a toolchain.
+    set(CROSS_TOOLCHAIN_FLAGS_INIT "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}")
+  elseif (EXISTS ${LLVM_MAIN_SRC_DIR}/cmake/platforms/${toolchain}.cmake)
+    # User wants a specific toolchain file.
     set(CROSS_TOOLCHAIN_FLAGS_INIT
       -DCMAKE_TOOLCHAIN_FILE=\"${LLVM_MAIN_SRC_DIR}/cmake/platforms/${toolchain}.cmake\")
   else()
+    # Else make a best guess. This should work fine for most cases.
     set(CROSS_TOOLCHAIN_FLAGS_INIT
       -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
       -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96433.322730.patch
Type: text/x-patch
Size: 1150 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210210/d7b702e8/attachment.bin>


More information about the llvm-commits mailing list