[PATCH] D99621: [CMake][Compiler-rt] Make it possible to configure standalone compiler-rt without `LLVMConfig.cmake`.

Dan Liew via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 30 16:10:54 PDT 2021


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

- Add comment clarifying the intended use case of the configuration that doesn't depend on `LLVMConfig.cmake`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99621

Files:
  compiler-rt/cmake/Modules/CompilerRTMockLLVMCMakeConfig.cmake
  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
@@ -323,9 +323,18 @@
       set(LLVM_CMAKE_PATH "${LLVM_BINARY_DIR_CMAKE_STYLE}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm")
     endif()
 
-    list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}")
-    # Get some LLVM variables from LLVMConfig.
-    include("${LLVM_CMAKE_PATH}/LLVMConfig.cmake")
+    if (EXISTS "${LLVM_CMAKE_PATH}")
+      list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}")
+      # Get some LLVM variables from LLVMConfig.
+      include("${LLVM_CMAKE_PATH}/LLVMConfig.cmake")
+    else()
+      # This configuration tries to configure without the prescence of `LLVMConfig.cmake`. It is
+      # intended for testing purposes (generating the lit test suites) and will likely not support
+      # a build of the runtimes in compiler-rt.
+      message(WARNING "LLVM CMake path (${LLVM_CMAKE_PATH}) reported by llvm-config does not exist")
+      include(CompilerRTMockLLVMCMakeConfig)
+      compiler_rt_mock_llvm_cmake_config()
+    endif()
 
     set(LLVM_LIBRARY_OUTPUT_INTDIR
       ${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
Index: compiler-rt/cmake/Modules/CompilerRTMockLLVMCMakeConfig.cmake
===================================================================
--- /dev/null
+++ compiler-rt/cmake/Modules/CompilerRTMockLLVMCMakeConfig.cmake
@@ -0,0 +1,43 @@
+# This macro mocks enough of the changes `LLVMConfig.cmake` makes so that
+# compiler-rt can successfully configure itself when a LLVM toolchain is
+# available but the corresponding CMake build files are not.
+#
+# The motivation for this is to be able to generate the compiler-rt
+# lit tests suites and run them against an arbitrary LLVM toolchain
+# which doesn't ship the LLVM CMake build files.
+macro(compiler_rt_mock_llvm_cmake_config)
+  message(STATUS "Attempting to mock the changes made by LLVMConfig.cmake")
+  compiler_rt_mock_llvm_cmake_config_set_cmake_path()
+  compiler_rt_mock_llvm_cmake_config_set_target_triple()
+  compiler_rt_mock_llvm_cmake_config_include_cmake_files()
+endmacro()
+
+macro(compiler_rt_mock_llvm_cmake_config_set_cmake_path)
+  # Point `LLVM_CMAKE_PATH` at the source tree in the monorepo.
+  set(LLVM_CMAKE_PATH "${LLVM_MAIN_SRC_DIR}/cmake/modules")
+  if (NOT EXISTS "${LLVM_CMAKE_PATH}")
+    message(FATAL_ERROR "LLVM_CMAKE_PATH (${LLVM_CMAKE_PATH}) does not exist")
+  endif()
+  list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}")
+  message(STATUS "LLVM_CMAKE_PATH: \"${LLVM_CMAKE_PATH}\"")
+endmacro()
+
+macro(compiler_rt_mock_llvm_cmake_config_set_target_triple)
+  # Various bits of compiler-rt depend on this variable being defined.
+  execute_process(
+    COMMAND ${LLVM_CONFIG_PATH} --host-target
+    RESULT_VARIABLE HAD_ERROR
+    OUTPUT_VARIABLE CONFIG_OUTPUT
+    OUTPUT_STRIP_TRAILING_WHITESPACE)
+  if(NOT HAD_ERROR)
+    set(TARGET_TRIPLE "${CONFIG_OUTPUT}")
+  else()
+    message(FATAL_ERROR "FAILED to run llvm-config to determine host target")
+  endif()
+  message(STATUS "TARGET_TRIPLE: \"${TARGET_TRIPLE}\"")
+endmacro()
+
+macro(compiler_rt_mock_llvm_cmake_config_include_cmake_files)
+  # Some compiler-rt CMake code needs to call code in this file.
+  include("${LLVM_CMAKE_PATH}/AddLLVM.cmake")
+endmacro()


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99621.334298.patch
Type: text/x-patch
Size: 3408 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210330/a5165b9f/attachment.bin>


More information about the llvm-commits mailing list