@@ -43,6 +43,12 @@ option(TORCH_MLIR_ENABLE_STABLEHLO "Add stablehlo dialect" ON)
43
43
if (TORCH_MLIR_ENABLE_STABLEHLO)
44
44
add_definitions (-DTORCH_MLIR_ENABLE_STABLEHLO)
45
45
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 )
46
52
47
53
option (TORCH_MLIR_OUT_OF_TREE_BUILD "Specifies an out of tree build" OFF )
48
54
@@ -142,7 +148,8 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)
142
148
143
149
function (torch_mlir_target_includes target )
144
150
set (_dirs
145
- $<BUILD_INTERFACE:${MLIR_INCLUDE_DIRS} >
151
+ $<BUILD_INTERFACE:${MLIR_INCLUDE_DIR} >
152
+ $<BUILD_INTERFACE:${MLIR_GENERATED_INCLUDE_DIR} >
146
153
$<BUILD_INTERFACE:${TORCH_MLIR_SOURCE_DIR} /include >
147
154
$<BUILD_INTERFACE:${TORCH_MLIR_BINARY_DIR} /include >
148
155
)
@@ -232,7 +239,8 @@ endif()
232
239
# Getting this wrong results in building large parts of the stablehlo
233
240
# project that we don't actually depend on. Further some of those parts
234
241
# 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)
236
244
set (STABLEHLO_BUILD_EMBEDDED ON )
237
245
set (STABLEHLO_ENABLE_BINDINGS_PYTHON ON )
238
246
add_subdirectory (${CMAKE_CURRENT_SOURCE_DIR} /externals/stablehlo
0 commit comments