Skip to content

Commit 8e12037

Browse files
authored
[flang] Fix finding system install of LLVM/Clang/MLIR in standalone builds (#120914)
The changes in #87822 introduced a regression where Flang could no longer be built standalone without explicitly specifying all of LLVM_DIR, CLANG_DIR and MLIR_DIR. Restore the earlier logic that used these paths as hints, and supported finding system-wide LLVM install via default paths. Instead, make paths absolute after locating the packages, using the paths CMake determined. ----- @vzakhari, could you confirm that this doesn't break your use case?
1 parent d514571 commit 8e12037

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

flang/CMakeLists.txt

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,16 @@ if (FLANG_STANDALONE_BUILD)
8989
mark_as_advanced(LLVM_ENABLE_ASSERTIONS)
9090
endif()
9191

92+
# We need a pre-built/installed version of LLVM.
93+
find_package(LLVM REQUIRED HINTS "${LLVM_DIR}")
9294
# If the user specifies a relative path to LLVM_DIR, the calls to include
9395
# LLVM modules fail. Append the absolute path to LLVM_DIR instead.
9496
get_filename_component(LLVM_DIR_ABSOLUTE ${LLVM_DIR}
9597
REALPATH BASE_DIR ${CMAKE_CURRENT_BINARY_DIR})
9698
list(APPEND CMAKE_MODULE_PATH ${LLVM_DIR_ABSOLUTE})
97-
# We need a pre-built/installed version of LLVM.
98-
find_package(LLVM REQUIRED HINTS "${LLVM_DIR_ABSOLUTE}")
99+
100+
# TODO: Remove when libclangDriver is lifted out of Clang
101+
find_package(Clang REQUIRED PATHS "${CLANG_DIR}")
99102

100103
# Users might specify a path to CLANG_DIR that's:
101104
# * a full path, or
@@ -104,17 +107,11 @@ if (FLANG_STANDALONE_BUILD)
104107
# cases.
105108
get_filename_component(
106109
CLANG_DIR_ABSOLUTE
107-
${CLANG_DIR}
110+
${Clang_DIR}
108111
REALPATH
109112
BASE_DIR ${CMAKE_CURRENT_BINARY_DIR})
110113
list(APPEND CMAKE_MODULE_PATH ${CLANG_DIR_ABSOLUTE})
111114

112-
# TODO: Remove when libclangDriver is lifted out of Clang
113-
find_package(Clang REQUIRED PATHS "${CLANG_DIR_ABSOLUTE}" NO_DEFAULT_PATH)
114-
if (NOT Clang_FOUND)
115-
message(FATAL_ERROR "Failed to find Clang")
116-
endif()
117-
118115
# If LLVM links to zlib we need the imported targets so we can too.
119116
if(LLVM_ENABLE_ZLIB)
120117
find_package(ZLIB REQUIRED)
@@ -132,12 +129,12 @@ if (FLANG_STANDALONE_BUILD)
132129
include(AddClang)
133130

134131
include(TableGen)
132+
find_package(MLIR REQUIRED CONFIG HINTS ${MLIR_DIR})
135133
# If the user specifies a relative path to MLIR_DIR, the calls to include
136134
# MLIR modules fail. Append the absolute path to MLIR_DIR instead.
137135
get_filename_component(MLIR_DIR_ABSOLUTE ${MLIR_DIR}
138136
REALPATH BASE_DIR ${CMAKE_CURRENT_BINARY_DIR})
139137
list(APPEND CMAKE_MODULE_PATH ${MLIR_DIR_ABSOLUTE})
140-
find_package(MLIR REQUIRED CONFIG HINTS ${MLIR_DIR_ABSOLUTE})
141138
# Use SYSTEM for the same reasons as for LLVM includes
142139
include_directories(SYSTEM ${MLIR_INCLUDE_DIRS})
143140
include(AddMLIR)

0 commit comments

Comments
 (0)