[flang-commits] [flang] d4b88ac - [cmake] Use absolute paths for modules search

Diana Picus via flang-commits flang-commits at lists.llvm.org
Wed Sep 9 04:59:51 PDT 2020


Author: Diana Picus
Date: 2020-09-09T13:56:19+02:00
New Revision: d4b88ac1658d681e143482336cac27c6a74b8b24

URL: https://github.com/llvm/llvm-project/commit/d4b88ac1658d681e143482336cac27c6a74b8b24
DIFF: https://github.com/llvm/llvm-project/commit/d4b88ac1658d681e143482336cac27c6a74b8b24.diff

LOG: [cmake] Use absolute paths for modules search

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).

Differential Revision: https://reviews.llvm.org/D87083

Added: 
    

Modified: 
    flang/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index 03440b72ec8c..707c7235a272 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -56,7 +56,10 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
 
   # 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 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
     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)


        


More information about the flang-commits mailing list