From f09db1fea09211e800103ca612d327e435718858 Mon Sep 17 00:00:00 2001 From: Marius Brehler Date: Fri, 6 Nov 2020 07:37:05 -0800 Subject: [PATCH] PR #44589: Introduce MHLO_BUILD_EMBEDDED build option Imported from GitHub PR https://github.com/tensorflow/tensorflow/pull/44589 This option allows to skip calling `find_package(MLIR)`, enabling to embed MHLO into other project, e.g. IREE. Copybara import of the project: -- 715299e594c95ce9d4f45dc154ba8a4acb196289 by Marius Brehler : Introduce MHLO_BUILD_EMBEDDED build option This option allows to skip calling `find_package(MLIR)`, enabling to embed MHLO into other project, e.g. IREE. -- 6a9cd1adb69dfd27e4306566085c2edcb9e266bf by Marius Brehler : Update tensorflow/compiler/mlir/hlo/CMakeLists.txt Co-authored-by: Geoffrey Martin-Noble PiperOrigin-RevId: 341046504 --- CMakeLists.txt | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c4e2ea1..e35c3ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,8 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") # Options and settings #------------------------------------------------------------------------------- +option(MHLO_BUILD_EMBEDDED "Build MHLO as part of another project" OFF) + #------------------------------------------------------------------------------- # MSVC defaults #------------------------------------------------------------------------------- @@ -57,11 +59,16 @@ endif() # MLIR/LLVM Configuration #------------------------------------------------------------------------------- -find_package(MLIR REQUIRED CONFIG) -message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}") -message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") -list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}") -list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}") +# Find MLIR to install if we are building standalone. If building as part of +# another project, let it handle the MLIR dependency. The dependent project +# might use a bundled version of MLIR instead of installing, for instance. +if(NOT MHLO_BUILD_EMBEDDED) + find_package(MLIR REQUIRED CONFIG) + message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}") + message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") + list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}") + list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}") +endif() if(LLVM_ENABLE_ZLIB) find_package(ZLIB)