Skip to content

Commit 9202984

Browse files
authored
[flang][build] Fixed paths discrovery for the out-of-tree build. (#87822)
When building flang out-of-tree with relative paths in LLVM_DIR, CLANG_DIR and MLIR_DIR, we need to compute the absolute paths based on the CMake build directory (i.e. where the cmake is invoked from).
1 parent af34a5d commit 9202984

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

flang/CMakeLists.txt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,13 @@ if (FLANG_STANDALONE_BUILD)
8181
mark_as_advanced(LLVM_ENABLE_ASSERTIONS)
8282
endif()
8383

84-
# We need a pre-built/installed version of LLVM.
85-
find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
8684
# If the user specifies a relative path to LLVM_DIR, the calls to include
8785
# LLVM modules fail. Append the absolute path to LLVM_DIR instead.
88-
get_filename_component(LLVM_DIR_ABSOLUTE ${LLVM_DIR} REALPATH)
86+
get_filename_component(LLVM_DIR_ABSOLUTE ${LLVM_DIR}
87+
REALPATH BASE_DIR ${CMAKE_CURRENT_BINARY_DIR})
8988
list(APPEND CMAKE_MODULE_PATH ${LLVM_DIR_ABSOLUTE})
89+
# We need a pre-built/installed version of LLVM.
90+
find_package(LLVM REQUIRED HINTS "${LLVM_DIR_ABSOLUTE}")
9091

9192
# Users might specify a path to CLANG_DIR that's:
9293
# * a full path, or
@@ -97,7 +98,7 @@ if (FLANG_STANDALONE_BUILD)
9798
CLANG_DIR_ABSOLUTE
9899
${CLANG_DIR}
99100
REALPATH
100-
${CMAKE_CURRENT_SOURCE_DIR})
101+
BASE_DIR ${CMAKE_CURRENT_BINARY_DIR})
101102
list(APPEND CMAKE_MODULE_PATH ${CLANG_DIR_ABSOLUTE})
102103

103104
# TODO: Remove when libclangDriver is lifted out of Clang
@@ -124,13 +125,14 @@ if (FLANG_STANDALONE_BUILD)
124125
include(AddClang)
125126

126127
include(TableGen)
127-
find_package(MLIR REQUIRED CONFIG)
128-
# Use SYSTEM for the same reasons as for LLVM includes
129-
include_directories(SYSTEM ${MLIR_INCLUDE_DIRS})
130128
# If the user specifies a relative path to MLIR_DIR, the calls to include
131129
# MLIR modules fail. Append the absolute path to MLIR_DIR instead.
132-
get_filename_component(MLIR_DIR_ABSOLUTE ${MLIR_DIR} REALPATH)
130+
get_filename_component(MLIR_DIR_ABSOLUTE ${MLIR_DIR}
131+
REALPATH BASE_DIR ${CMAKE_CURRENT_BINARY_DIR})
133132
list(APPEND CMAKE_MODULE_PATH ${MLIR_DIR_ABSOLUTE})
133+
find_package(MLIR REQUIRED CONFIG HINTS ${MLIR_DIR_ABSOLUTE})
134+
# Use SYSTEM for the same reasons as for LLVM includes
135+
include_directories(SYSTEM ${MLIR_INCLUDE_DIRS})
134136
include(AddMLIR)
135137
find_program(MLIR_TABLEGEN_EXE "mlir-tblgen" ${LLVM_TOOLS_BINARY_DIR}
136138
NO_DEFAULT_PATH)

0 commit comments

Comments
 (0)