[Mlir-commits] [mlir] 7c081a5 - [mlir][standalone] Enable to build as LLVM external project
Marius Brehler
llvmlistbot at llvm.org
Wed Mar 1 05:15:58 PST 2023
Author: Marius Brehler
Date: 2023-03-01T14:15:17+01:00
New Revision: 7c081a5675cae9f083e3c34ec27a89ad3fcc9d3b
URL: https://github.com/llvm/llvm-project/commit/7c081a5675cae9f083e3c34ec27a89ad3fcc9d3b
DIFF: https://github.com/llvm/llvm-project/commit/7c081a5675cae9f083e3c34ec27a89ad3fcc9d3b.diff
LOG: [mlir][standalone] Enable to build as LLVM external project
In addition to the component build, this enables the standalone example
to be build as part of a monolithic LLVM build by using the LLVM
external projects mechanism (`LLVM_EXTERNAL_PROJECTS`).
Reviewed By: stephenneuendorffer, stellaraccident
Differential Revision: https://reviews.llvm.org/D143718
Added:
Modified:
mlir/examples/standalone/CMakeLists.txt
mlir/examples/standalone/README.md
mlir/examples/standalone/test/lit.site.cfg.py.in
Removed:
################################################################################
diff --git a/mlir/examples/standalone/CMakeLists.txt b/mlir/examples/standalone/CMakeLists.txt
index 84bce58641896..d36a6badc16d6 100644
--- a/mlir/examples/standalone/CMakeLists.txt
+++ b/mlir/examples/standalone/CMakeLists.txt
@@ -5,31 +5,42 @@ set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
-find_package(MLIR REQUIRED CONFIG)
-
-message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}")
-message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
-
-set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/bin)
-set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/lib)
-set(MLIR_BINARY_DIR ${CMAKE_BINARY_DIR})
-
-list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}")
-list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
-include(TableGen)
-include(AddLLVM)
-include(AddMLIR)
-include(HandleLLVMOptions)
+if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
+ find_package(MLIR REQUIRED CONFIG)
+
+ message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}")
+ message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
+
+ set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/bin)
+ set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/lib)
+ set(MLIR_BINARY_DIR ${CMAKE_BINARY_DIR})
+
+ list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}")
+ list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
+
+ include(TableGen)
+ include(AddLLVM)
+ include(AddMLIR)
+ include(HandleLLVMOptions)
+else()
+ # Build via external projects mechanism
+ set(MLIR_MAIN_SRC_DIR ${LLVM_MAIN_SRC_DIR}/../mlir)
+ set(MLIR_INCLUDE_DIR ${MLIR_MAIN_SRC_DIR}/include)
+ set(MLIR_GENERATED_INCLUDE_DIR ${LLVM_BINARY_DIR}/tools/mlir/include)
+ set(MLIR_INCLUDE_DIRS "${MLIR_INCLUDE_DIR};${MLIR_GENERATED_INCLUDE_DIR}")
+endif()
if(MLIR_ENABLE_BINDINGS_PYTHON)
include(MLIRDetectPythonEnv)
mlir_configure_python_dev_packages()
endif()
+set(STANDALONE_SOURCE_DIR ${PROJECT_SOURCE_DIR})
+set(STANDALONE_BINARY_DIR ${PROJECT_BINARY_DIR})
include_directories(${LLVM_INCLUDE_DIRS})
include_directories(${MLIR_INCLUDE_DIRS})
-include_directories(${PROJECT_SOURCE_DIR}/include)
-include_directories(${PROJECT_BINARY_DIR}/include)
+include_directories(${STANDALONE_SOURCE_DIR}/include)
+include_directories(${STANDALONE_BINARY_DIR}/include)
link_directories(${LLVM_BUILD_LIBRARY_DIR})
add_definitions(${LLVM_DEFINITIONS})
diff --git a/mlir/examples/standalone/README.md b/mlir/examples/standalone/README.md
index b1ca6275e598f..03721f4546c1c 100644
--- a/mlir/examples/standalone/README.md
+++ b/mlir/examples/standalone/README.md
@@ -2,7 +2,7 @@
This is an example of an out-of-tree [MLIR](https://mlir.llvm.org/) dialect along with a standalone `opt`-like tool to operate on that dialect.
-## Building
+## Building - Component Build
This setup assumes that you have built LLVM and MLIR in `$BUILD_DIR` and installed them to `$PREFIX`. To build and launch the tests, run
```sh
@@ -16,3 +16,17 @@ cmake --build . --target mlir-doc
```
**Note**: Make sure to pass `-DLLVM_INSTALL_UTILS=ON` when building LLVM with CMake in order to install `FileCheck` to the chosen installation prefix.
+## Building - Monolithic Build
+
+This setup assumes that you build the project as part of a monolithic LLVM build via the `LLVM_EXTERNAL_PROJECTS` mechanism.
+To build LLVM, MLIR, the example and launch the tests run
+```sh
+mkdir build && cd build
+cmake -G Ninja `$LLVM_SRC_DIR/llvm` \
+ -DCMAKE_BUILD_TYPE=Release \
+ -DLLVM_TARGETS_TO_BUILD=host
+ -DLLVM_ENABLE_PROJECTS=mlir \
+ -DLLVM_EXTERNAL_PROJECTS=standalone-dialect -DLLVM_EXTERNAL_STANDALONE_DIALECT_SOURCE_DIR=../
+cmake --build . --target check-standalone
+```
+Here, `$LLVM_SRC_DIR` needs to point to the root of the monorepo.
diff --git a/mlir/examples/standalone/test/lit.site.cfg.py.in b/mlir/examples/standalone/test/lit.site.cfg.py.in
index 8f9e557907f1f..9a81c6b48343c 100644
--- a/mlir/examples/standalone/test/lit.site.cfg.py.in
+++ b/mlir/examples/standalone/test/lit.site.cfg.py.in
@@ -3,10 +3,10 @@
config.llvm_tools_dir = lit_config.substitute("@LLVM_TOOLS_DIR@")
config.mlir_obj_dir = "@MLIR_BINARY_DIR@"
config.enable_bindings_python = @MLIR_ENABLE_BINDINGS_PYTHON@
-config.standalone_obj_root = "@CMAKE_BINARY_DIR@"
+config.standalone_obj_root = "@STANDALONE_BINARY_DIR@"
import lit.llvm
lit.llvm.initialize(lit_config, config)
# Let the main config do the real work.
-lit_config.load_config(config, "@CMAKE_SOURCE_DIR@/test/lit.cfg.py")
+lit_config.load_config(config, "@STANDALONE_SOURCE_DIR@/test/lit.cfg.py")
More information about the Mlir-commits
mailing list