@@ -43,6 +43,12 @@ option(TORCH_MLIR_ENABLE_STABLEHLO "Add stablehlo dialect" ON)
4343if (TORCH_MLIR_ENABLE_STABLEHLO)
4444 add_definitions (-DTORCH_MLIR_ENABLE_STABLEHLO)
4545endif ()
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
4753option (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
143149function (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