diff --git a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake --- a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake +++ b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake @@ -240,6 +240,21 @@ 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") + # `--src-root` might report a path does not exist (e.g. built on another machine). + # In this case we fallback on the LLVM sources living next to `compiler-rt` which + # is true in the compiler-rt is checked out as part of the monorepo. + if (NOT EXISTS "${LLVM_MAIN_SRC_DIR}") + # TODO(dliew): We should make this behavior the only behavior rather than + # a fallback once we know nobody relies on the old behavior. + message(WARNING "LLVM source directory (${LLVM_MAIN_SRC_DIR}) reported by llvm-config does not exist") + get_filename_component(LLVM_MAIN_SRC_DIR_REL "${CMAKE_CURRENT_SOURCE_DIR}/../llvm" ABSOLUTE) + if (NOT EXISTS "${LLVM_MAIN_SRC_DIR_REL}") + message(FATAL_ERROR "LLVM source directory (${LLVM_MAIN_SRC_DIR_REL}) does not exist") + endif() + set(LLVM_MAIN_SRC_DIR "${LLVM_MAIN_SRC_DIR_REL}") + endif() + message(STATUS "LLVM source directory: \"${LLVM_MAIN_SRC_DIR}\"") + # Detect if we have the LLVMXRay and TestingSupport library installed and # available from llvm-config. execute_process(