[flang-commits] [flang] af80568 - [flang][cmake] Improve how CLANG_DIR is handled
Andrzej Warzynski via flang-commits
flang-commits at lists.llvm.org
Tue Mar 23 08:16:15 PDT 2021
Author: Andrzej Warzynski
Date: 2021-03-23T15:14:51Z
New Revision: af8056889ac9913c587293fd68503b4883dab558
URL: https://github.com/llvm/llvm-project/commit/af8056889ac9913c587293fd68503b4883dab558
DIFF: https://github.com/llvm/llvm-project/commit/af8056889ac9913c587293fd68503b4883dab558.diff
LOG: [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
Added:
Modified:
flang/CMakeLists.txt
Removed:
################################################################################
diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index 33e5521f6d5b..1318eafec7c3 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -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.
More information about the flang-commits
mailing list