[flang-commits] [flang] [flang] Fix finding system install of LLVM/Clang/MLIR in standalone builds (PR #120914)
Michał Górny via flang-commits
flang-commits at lists.llvm.org
Sun Dec 22 11:15:19 PST 2024
https://github.com/mgorny created https://github.com/llvm/llvm-project/pull/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?
>From 705879eb4a638c767a95680480be87ad44518106 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny at gentoo.org>
Date: Sun, 22 Dec 2024 20:10:57 +0100
Subject: [PATCH] [flang] Fix finding system install of LLVM/Clang/MLIR in
standalone builds
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.
---
flang/CMakeLists.txt | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index 68947eaa9c9bd7..34b3fedc884941 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -89,13 +89,16 @@ if (FLANG_STANDALONE_BUILD)
mark_as_advanced(LLVM_ENABLE_ASSERTIONS)
endif()
+ # We need a pre-built/installed version of LLVM.
+ find_package(LLVM REQUIRED HINTS "${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 BASE_DIR ${CMAKE_CURRENT_BINARY_DIR})
list(APPEND CMAKE_MODULE_PATH ${LLVM_DIR_ABSOLUTE})
- # We need a pre-built/installed version of LLVM.
- find_package(LLVM REQUIRED HINTS "${LLVM_DIR_ABSOLUTE}")
+
+ # TODO: Remove when libclangDriver is lifted out of Clang
+ find_package(Clang REQUIRED PATHS "${CLANG_DIR}")
# Users might specify a path to CLANG_DIR that's:
# * a full path, or
@@ -104,17 +107,11 @@ if (FLANG_STANDALONE_BUILD)
# cases.
get_filename_component(
CLANG_DIR_ABSOLUTE
- ${CLANG_DIR}
+ ${Clang_DIR}
REALPATH
BASE_DIR ${CMAKE_CURRENT_BINARY_DIR})
list(APPEND CMAKE_MODULE_PATH ${CLANG_DIR_ABSOLUTE})
- # TODO: Remove when libclangDriver is lifted out of Clang
- find_package(Clang REQUIRED PATHS "${CLANG_DIR_ABSOLUTE}" NO_DEFAULT_PATH)
- if (NOT Clang_FOUND)
- message(FATAL_ERROR "Failed to find Clang")
- endif()
-
# If LLVM links to zlib we need the imported targets so we can too.
if(LLVM_ENABLE_ZLIB)
find_package(ZLIB REQUIRED)
@@ -132,12 +129,12 @@ if (FLANG_STANDALONE_BUILD)
include(AddClang)
include(TableGen)
+ find_package(MLIR REQUIRED CONFIG HINTS ${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 BASE_DIR ${CMAKE_CURRENT_BINARY_DIR})
list(APPEND CMAKE_MODULE_PATH ${MLIR_DIR_ABSOLUTE})
- find_package(MLIR REQUIRED CONFIG HINTS ${MLIR_DIR_ABSOLUTE})
# Use SYSTEM for the same reasons as for LLVM includes
include_directories(SYSTEM ${MLIR_INCLUDE_DIRS})
include(AddMLIR)
More information about the flang-commits
mailing list