1include(AddMLIRPythonExtension) 2add_custom_target(MLIRBindingsPythonExtension) 3 4################################################################################ 5# Generate dialect-specific bindings. 6################################################################################ 7 8add_mlir_dialect_python_bindings(MLIRBindingsPythonStandardOps 9 StandardOps.td 10 std) 11add_dependencies(MLIRBindingsPythonExtension MLIRBindingsPythonStandardOps) 12 13################################################################################ 14# Copy python source tree. 15################################################################################ 16 17set(PY_SRC_FILES 18 mlir/__init__.py 19 mlir/_dlloader.py 20 mlir/ir.py 21 mlir/dialects/__init__.py 22 mlir/ir.py 23 mlir/passmanager.py 24 mlir/transforms/__init__.py 25) 26 27add_custom_target(MLIRBindingsPythonSources ALL 28 DEPENDS ${PY_SRC_FILES} 29) 30add_dependencies(MLIRBindingsPythonExtension MLIRBindingsPythonSources) 31 32foreach(PY_SRC_FILE ${PY_SRC_FILES}) 33 set(PY_DEST_FILE "${PROJECT_BINARY_DIR}/python/${PY_SRC_FILE}") 34 add_custom_command( 35 TARGET MLIRBindingsPythonSources PRE_BUILD 36 COMMENT "Copying python source ${PY_SRC_FILE} -> ${PY_DEST_FILE}" 37 DEPENDS "${PY_SRC_FILE}" 38 COMMAND "${CMAKE_COMMAND}" -E copy_if_different 39 "${CMAKE_CURRENT_SOURCE_DIR}/${PY_SRC_FILE}" "${PY_DEST_FILE}" 40 ) 41endforeach() 42 43################################################################################ 44# Build core python extension 45################################################################################ 46add_mlir_python_extension(MLIRCoreBindingsPythonExtension _mlir 47 INSTALL_DIR 48 python 49 SOURCES 50 MainModule.cpp 51 IRModules.cpp 52 PybindUtils.cpp 53 Pass.cpp 54) 55add_dependencies(MLIRBindingsPythonExtension MLIRCoreBindingsPythonExtension) 56 57# Note that we copy from the source tree just like for headers because 58# it will not be polluted with py_cache runtime artifacts (from testing and 59# such). 60install( 61 DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/mlir 62 DESTINATION python 63 COMPONENT MLIRBindingsPythonSources 64 FILES_MATCHING PATTERN "*.py" 65) 66 67if (NOT LLVM_ENABLE_IDE) 68 add_llvm_install_targets( 69 install-MLIRBindingsPythonSources 70 DEPENDS MLIRBindingsPythonSources 71 COMPONENT MLIRBindingsPythonSources) 72endif() 73 74add_subdirectory(Transforms) 75