Skip to content

Commit c37dd7c

Browse files
committed
[cmake] Enable accepting external stablehlo project
This MR enables `torch_mlir` project to accept path to external stablehlo and include those directories. This in turn enables `torch_mlir` to be part of bigger compiler project where `stablehlo` is already a dependency. One more change is added by changing the way set is created in `torch_mlir_target_includes`. Previous way of using `MLIR_INCLUDE_DIRS` variable was silently adding source directory into target include directories.
1 parent 4a2cbb9 commit c37dd7c

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

CMakeLists.txt

+10-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ option(TORCH_MLIR_ENABLE_STABLEHLO "Add stablehlo dialect" ON)
4343
if(TORCH_MLIR_ENABLE_STABLEHLO)
4444
add_definitions(-DTORCH_MLIR_ENABLE_STABLEHLO)
4545
endif()
46+
# It is possible that both stablehlo and torch_mlir projects are used in some compiler project.
47+
# In this case, we don't want to use stablehlo that is downloaded by torch_mlir (in external/stablehlo)
48+
# folder but instead want to use stablehlo that is part of top level compiler project.
49+
# With TORCH_MLIR_USE_EXTERNAL_STABLEHLO enables, it is assumed that top level compiler project makes
50+
# stablehlo targets AND includes available (for example with `add_subdirectory` and `include_directories`).
51+
option(TORCH_MLIR_USE_EXTERNAL_STABLEHLO "Use stablehlo from top level project" OFF)
4652

4753
option(TORCH_MLIR_OUT_OF_TREE_BUILD "Specifies an out of tree build" OFF)
4854

@@ -142,7 +148,8 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)
142148

143149
function(torch_mlir_target_includes target)
144150
set(_dirs
145-
$<BUILD_INTERFACE:${MLIR_INCLUDE_DIRS}>
151+
$<BUILD_INTERFACE:${MLIR_INCLUDE_DIR}>
152+
$<BUILD_INTERFACE:${MLIR_GENERATED_INCLUDE_DIR}>
146153
$<BUILD_INTERFACE:${TORCH_MLIR_SOURCE_DIR}/include>
147154
$<BUILD_INTERFACE:${TORCH_MLIR_BINARY_DIR}/include>
148155
)
@@ -232,7 +239,8 @@ endif()
232239
# Getting this wrong results in building large parts of the stablehlo
233240
# project that we don't actually depend on. Further some of those parts
234241
# do not even compile on all platforms.
235-
if (TORCH_MLIR_ENABLE_STABLEHLO)
242+
# Only configure StableHLO if it isn't provided from a top-level project
243+
if (TORCH_MLIR_ENABLE_STABLEHLO AND NOT TORCH_MLIR_USE_EXTERNAL_STABLEHLO)
236244
set(STABLEHLO_BUILD_EMBEDDED ON)
237245
set(STABLEHLO_ENABLE_BINDINGS_PYTHON ON)
238246
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/externals/stablehlo

0 commit comments

Comments
 (0)