forked from OSchip/llvm-project
lld/cmake: Drop use of llvm-config for LLVM install discovery
This has been deprecated since D116492 earlier in 2022. That seems recent, but with the recent cut of LLVM 15 that is still two releases (14 and 15). Meanwhile Clang has deprecated `llvm-config` for a lot longer, and since it is likely that LLD users are also Clang users, this serves as an extra "heads up" that `llvm-config` is on its way out. Remove it in favor of using CMake's find_package() function. Reviewed By: MaskRay, mgorny Differential Revision: https://reviews.llvm.org/D131144
This commit is contained in:
parent
d2b158e29e
commit
91f3f0bf31
|
@ -17,70 +17,13 @@ if(LLD_BUILT_STANDALONE)
|
|||
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
|
||||
# Rely on llvm-config.
|
||||
set(LLVM_CONFIG_OUTPUT)
|
||||
if(NOT LLVM_CONFIG)
|
||||
# back compat
|
||||
set(LLVM_CONFIG "${LLVM_CONFIG_PATH}")
|
||||
endif()
|
||||
if(LLVM_CONFIG)
|
||||
set (LLVM_CONFIG_FOUND 1)
|
||||
message(STATUS "Found LLVM_CONFIG as ${LLVM_CONFIG}")
|
||||
message(DEPRECATION "Using llvm-config to detect the LLVM installation is \
|
||||
deprecated. The installed cmake files should be used \
|
||||
instead. CMake should be able to detect your LLVM install \
|
||||
automatically, but you can also use LLVM_DIR to specify \
|
||||
the path containing LLVMConfig.cmake.")
|
||||
set(CONFIG_COMMAND ${LLVM_CONFIG}
|
||||
"--includedir"
|
||||
"--prefix"
|
||||
"--src-root"
|
||||
"--cmakedir"
|
||||
)
|
||||
execute_process(
|
||||
COMMAND ${CONFIG_COMMAND}
|
||||
RESULT_VARIABLE HAD_ERROR
|
||||
OUTPUT_VARIABLE LLVM_CONFIG_OUTPUT
|
||||
)
|
||||
if(NOT HAD_ERROR)
|
||||
string(REGEX REPLACE
|
||||
"[ \t]*[\r\n]+[ \t]*" ";"
|
||||
LLVM_CONFIG_OUTPUT ${LLVM_CONFIG_OUTPUT})
|
||||
else()
|
||||
string(REPLACE ";" " " CONFIG_COMMAND_STR "${CONFIG_COMMAND}")
|
||||
message(STATUS "${CONFIG_COMMAND_STR}")
|
||||
message(FATAL_ERROR "llvm-config failed with status ${HAD_ERROR}")
|
||||
endif()
|
||||
|
||||
list(GET LLVM_CONFIG_OUTPUT 0 MAIN_INCLUDE_DIR)
|
||||
list(GET LLVM_CONFIG_OUTPUT 1 LLVM_OBJ_ROOT)
|
||||
list(GET LLVM_CONFIG_OUTPUT 2 MAIN_SRC_DIR)
|
||||
list(GET LLVM_CONFIG_OUTPUT 3 LLVM_CONFIG_CMAKE_DIR)
|
||||
|
||||
# Normalize LLVM_CMAKE_DIR. --cmakedir might contain backslashes.
|
||||
# CMake assumes slashes as PATH.
|
||||
file(TO_CMAKE_PATH ${LLVM_CONFIG_CMAKE_DIR} LLVM_CMAKE_DIR)
|
||||
endif()
|
||||
|
||||
find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
|
||||
list(APPEND CMAKE_MODULE_PATH "${LLVM_DIR}")
|
||||
|
||||
# We can't check LLVM_CONFIG here, because find_package(LLVM ...) also sets
|
||||
# LLVM_CONFIG.
|
||||
if (NOT LLVM_CONFIG_FOUND)
|
||||
# Pull values from LLVMConfig.cmake. We can drop this once the llvm-config
|
||||
# path is removed.
|
||||
set(INCLUDE_DIRS ${LLVM_INCLUDE_DIRS})
|
||||
set(LLVM_OBJ_DIR "${LLVM_BINARY_DIR}")
|
||||
# N.B. this is just a default value, the CACHE PATHs below can be overridden.
|
||||
set(MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../llvm")
|
||||
else()
|
||||
set(INCLUDE_DIRS "${LLVM_BINARY_DIR}/include" "${MAIN_INCLUDE_DIR}")
|
||||
endif()
|
||||
|
||||
set(LLVM_INCLUDE_DIRS ${INCLUDE_DIRS} CACHE PATH "Path to llvm/include and any other header dirs needed")
|
||||
set(LLVM_BINARY_DIR "${LLVM_OBJ_ROOT}" CACHE PATH "Path to LLVM build tree")
|
||||
set(LLVM_MAIN_SRC_DIR "${MAIN_SRC_DIR}" CACHE PATH "Path to LLVM source tree")
|
||||
# Turn into CACHE PATHs for overwritting
|
||||
set(LLVM_INCLUDE_DIRS ${LLVM_INCLUDE_DIRS} CACHE PATH "Path to llvm/include and any other header dirs needed")
|
||||
set(LLVM_BINARY_DIR "${LLVM_BINARY_DIR}" CACHE PATH "Path to LLVM build tree")
|
||||
set(LLVM_MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../llvm" CACHE PATH "Path to LLVM source tree")
|
||||
|
||||
find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" ${LLVM_TOOLS_BINARY_DIR}
|
||||
NO_DEFAULT_PATH)
|
||||
|
|
Loading…
Reference in New Issue