@@ -43,6 +43,14 @@ 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 might not want to use stablehlo that is downloaded by torch_mlir (in external/stablehlo folder)
48
+ # but instead stablehlo that is part of the top level compiler project.
49
+ # TORCH_MLIR_EXTERNAL_STABLEHLO_DIR represents stablehlo directory (<some_path>/stablehlo)
50
+ # in top level compiler project that will be included in torch_mlir. It is assumed that top level
51
+ # compiler project makes stablehlo targets available (for example with `add_subdirectory`) and
52
+ # thus they are not added.
53
+ set (TORCH_MLIR_EXTERNAL_STABLEHLO_DIR "" CACHE STRING "Path to stablehlo dir from super project" )
46
54
47
55
option (TORCH_MLIR_OUT_OF_TREE_BUILD "Specifies an out of tree build" OFF )
48
56
@@ -233,12 +241,17 @@ endif()
233
241
# project that we don't actually depend on. Further some of those parts
234
242
# do not even compile on all platforms.
235
243
if (TORCH_MLIR_ENABLE_STABLEHLO)
236
- set (STABLEHLO_BUILD_EMBEDDED ON )
237
- set (STABLEHLO_ENABLE_BINDINGS_PYTHON ON )
238
- add_subdirectory (${CMAKE_CURRENT_SOURCE_DIR} /externals/stablehlo
239
- ${CMAKE_CURRENT_BINARY_DIR} /stablehlo
240
- EXCLUDE_FROM_ALL )
241
- include_directories (${CMAKE_CURRENT_SOURCE_DIR} /externals/stablehlo)
244
+ if (NOT "${TORCH_MLIR_EXTERNAL_STABLEHLO_DIR} " STREQUAL "" )
245
+ # Only include directories. It is assumed that stablehlo targets are made available by external project.
246
+ include_directories (${TORCH_MLIR_EXTERNAL_STABLEHLO_DIR} )
247
+ else ()
248
+ set (STABLEHLO_BUILD_EMBEDDED ON )
249
+ set (STABLEHLO_ENABLE_BINDINGS_PYTHON ON )
250
+ add_subdirectory (${CMAKE_CURRENT_SOURCE_DIR} /externals/stablehlo
251
+ ${CMAKE_CURRENT_BINARY_DIR} /stablehlo
252
+ EXCLUDE_FROM_ALL )
253
+ include_directories (${CMAKE_CURRENT_SOURCE_DIR} /externals/stablehlo)
254
+ endif ()
242
255
endif ()
243
256
244
257
#-------------------------------------------------------------------------------
0 commit comments