[flang][cmake] Improve how CLANG_DIR is handled

* Added a sanity check with `Clang_FOUND` to verify that find_package
succeeded
* Made sure that find_package won't use any of CMake's standard paths
to guarantee that only the path provided with CLANG_DIR is considered
(implemented through NO_DEFAULT_PATH)
* Made the call to get_filename_component more explicit (so that it is
clear what the base directory is)
* Updated comments to clarify what CLANG_DIR means

Differential Revision: https://reviews.llvm.org/D99088
This commit is contained in:
Andrzej Warzynski 2021-03-22 17:04:01 +00:00
parent 94ef248d7b
commit af8056889a

View file

@ -48,9 +48,23 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
list(APPEND CMAKE_MODULE_PATH ${LLVM_DIR_ABSOLUTE})
if(FLANG_BUILD_NEW_DRIVER)
# Users might specify a path to CLANG_DIR that's:
# * a full path, or
# * a path relative to the path of this script.
# Append the absolute path to CLANG_DIR so that find_package works in both
# cases.
get_filename_component(
CLANG_DIR_ABSOLUTE
${CLANG_DIR}
REALPATH
CMAKE_CURRENT_SOURCE_DIR)
list(APPEND CMAKE_MODULE_PATH ${CLANG_DIR_ABSOLUTE})
# TODO: Remove when libclangDriver is lifted out of Clang
list(APPEND CMAKE_MODULE_PATH ${CLANG_DIR})
find_package(Clang REQUIRED HINTS "${CLANG_DIR}")
find_package(Clang REQUIRED PATHS "${CLANG_DIR_ABSOLUTE}" NO_DEFAULT_PATH)
if (NOT Clang_FOUND)
message(FATAL_ERROR "Failed to find Clang")
endif()
endif()
# If LLVM links to zlib we need the imported targets so we can too.