[flang-commits] [PATCH] D87083: [cmake] Use absolute paths for modules search

Diana Picus via Phabricator via flang-commits flang-commits at lists.llvm.org
Thu Sep 3 04:58:46 PDT 2020


rovka created this revision.
rovka added reviewers: PeteSteinfeld, isuruf.
rovka added a project: Flang.
Herald added subscribers: rriddle, mgorny.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: DavidTruby.
rovka requested review of this revision.
Herald added a subscriber: stephenneuendorffer.

For out of tree builds, the user generally needs to specify LLVM_DIR and
MLIR_DIR on the command line so that the correct LLVM and MLIR
installations are picked up.

If the provided paths are absolute, everything works fine, however for
buildbots it is customary to work with relative paths, and that makes it
difficult for CMake to find the right modules to include.

This patch changes CMakeLists.txt to convert LLVM_DIR and MLIR_DIR to
absolute paths before adding them to CMAKE_MODULE_PATH. The inputs are
assumed to be relative to the source directory (llvm-project/flang).


https://reviews.llvm.org/D87083

Files:
  flang/CMakeLists.txt


Index: flang/CMakeLists.txt
===================================================================
--- flang/CMakeLists.txt
+++ flang/CMakeLists.txt
@@ -56,7 +56,10 @@
 
   # We need a pre-built/installed version of LLVM.
   find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_PATH}")
-  list(APPEND CMAKE_MODULE_PATH ${LLVM_DIR})
+  # If the user specifies a relative path to LLVM_DIR, the calls to include
+  # LLVM modules fail. Append the absolute path to LLVM_DIR instead.
+  get_filename_component(LLVM_DIR_ABSOLUTE ${LLVM_DIR} REALPATH)
+  list(APPEND CMAKE_MODULE_PATH ${LLVM_DIR_ABSOLUTE})
 
   # If LLVM links to zlib we need the imported targets so we can too.
   if(LLVM_ENABLE_ZLIB)
@@ -78,7 +81,10 @@
     find_package(MLIR REQUIRED CONFIG)
     # Use SYSTEM for the same reasons as for LLVM includes
     include_directories(SYSTEM ${MLIR_INCLUDE_DIRS})
-    list(APPEND CMAKE_MODULE_PATH ${MLIR_DIR})
+    # If the user specifies a relative path to MLIR_DIR, the calls to include
+    # MLIR modules fail. Append the absolute path to MLIR_DIR instead.
+    get_filename_component(MLIR_DIR_ABSOLUTE ${MLIR_DIR} REALPATH)
+    list(APPEND CMAKE_MODULE_PATH ${MLIR_DIR_ABSOLUTE})
     include(AddMLIR)
     find_program(MLIR_TABLEGEN_EXE "mlir-tblgen" ${LLVM_TOOLS_BINARY_DIR}
       NO_DEFAULT_PATH)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87083.289683.patch
Type: text/x-patch
Size: 1306 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20200903/a343326c/attachment.bin>


More information about the flang-commits mailing list