[PATCH] D99620: [CMake][Compiler-rt] Fix `LLVM_MAIN_SRC_DIR` to be correct when `llvm-config` reports a path that doesn't exist.

Dan Liew via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 30 15:28:21 PDT 2021


delcypher updated this revision to Diff 334286.
delcypher added a comment.

Make relying on the monorepo layout the default and using `llvm-config` a deprecated fallback.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99620/new/

https://reviews.llvm.org/D99620

Files:
  compiler-rt/cmake/Modules/CompilerRTUtils.cmake


Index: compiler-rt/cmake/Modules/CompilerRTUtils.cmake
===================================================================
--- compiler-rt/cmake/Modules/CompilerRTUtils.cmake
+++ compiler-rt/cmake/Modules/CompilerRTUtils.cmake
@@ -221,7 +221,7 @@
   endif()
   if (LLVM_CONFIG_PATH)
     execute_process(
-      COMMAND ${LLVM_CONFIG_PATH} "--obj-root" "--bindir" "--libdir" "--src-root" "--includedir"
+      COMMAND ${LLVM_CONFIG_PATH} "--obj-root" "--bindir" "--libdir" "--includedir"
       RESULT_VARIABLE HAD_ERROR
       OUTPUT_VARIABLE CONFIG_OUTPUT)
     if (HAD_ERROR)
@@ -231,15 +231,40 @@
     list(GET CONFIG_OUTPUT 0 BINARY_DIR)
     list(GET CONFIG_OUTPUT 1 TOOLS_BINARY_DIR)
     list(GET CONFIG_OUTPUT 2 LIBRARY_DIR)
-    list(GET CONFIG_OUTPUT 3 MAIN_SRC_DIR)
-    list(GET CONFIG_OUTPUT 4 INCLUDE_DIR)
+    list(GET CONFIG_OUTPUT 3 INCLUDE_DIR)
 
     set(LLVM_BINARY_DIR ${BINARY_DIR} CACHE PATH "Path to LLVM build tree")
     set(LLVM_LIBRARY_DIR ${LIBRARY_DIR} CACHE PATH "Path to llvm/lib")
-    set(LLVM_MAIN_SRC_DIR ${MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree")
     set(LLVM_TOOLS_BINARY_DIR ${TOOLS_BINARY_DIR} CACHE PATH "Path to llvm/bin")
     set(LLVM_INCLUDE_DIR ${INCLUDE_DIR} CACHE PATH "Paths to LLVM headers")
 
+    # Compute path to LLVM sources assuming the monorepo layout.
+    get_filename_component(LLVM_MAIN_SRC_DIR_DEFAULT "${CMAKE_CURRENT_SOURCE_DIR}/../llvm" ABSOLUTE)
+    if (NOT EXISTS "${LLVM_MAIN_SRC_DIR_DEFAULT}")
+      # If that fails consult llvm-config for the path.
+      # TODO(dliew): Remove this legacy fallback path.
+      message(WARNING
+        "LLVM source tree not found at \"${LLVM_MAIN_SRC_DIR_DEFAULT}\". "
+        "You are not using the monorepo layout. "
+        "This configuration is DEPRECATED. Consulting llvm-config for the LLVM source path"
+        "as a fallback. This behavior will be removed in the future."
+      )
+      execute_process(
+        COMMAND ${LLVM_CONFIG_PATH} --src-root
+        RESULT_VARIABLE HAD_ERROR
+        OUTPUT_VARIABLE CONFIG_OUTPUT
+        OUTPUT_STRIP_TRAILING_WHITESPACE)
+      if(NOT HAD_ERROR)
+        set(LLVM_MAIN_SRC_DIR_DEFAULT "${CONFIG_OUTPUT}")
+      else()
+        message(FATAL_ERROR "FAILED to run llvm-config to determine LLVM source path")
+      endif()
+    endif()
+    set(LLVM_MAIN_SRC_DIR "${LLVM_MAIN_SRC_DIR_DEFAULT}" CACHE PATH "Path to LLVM source tree")
+    if (NOT EXISTS "${LLVM_MAIN_SRC_DIR}")
+      message(FATAL_ERROR "LLVM_MAIN_SRC_DIR (${LLVM_MAIN_SRC_DIR}) does not exist")
+    endif()
+
     # Detect if we have the LLVMXRay and TestingSupport library installed and
     # available from llvm-config.
     execute_process(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99620.334286.patch
Type: text/x-patch
Size: 2695 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210330/17762d91/attachment.bin>


More information about the llvm-commits mailing list