brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.8 KiB · 8469bff Raw
162 lines · plain
1include(AddMLIRPython)2 3# Specifies that all MLIR packages are co-located under the `mlir_standalone`4# top level package (the API has been embedded in a relocatable way).5add_compile_definitions("MLIR_PYTHON_PACKAGE_PREFIX=${MLIR_PYTHON_PACKAGE_PREFIX}.")6 7 8################################################################################9# Sources10################################################################################11 12declare_mlir_python_sources(StandalonePythonSources)13 14declare_mlir_dialect_python_bindings(15  ADD_TO_PARENT StandalonePythonSources16  ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir_standalone"17  TD_FILE dialects/StandaloneOps.td18  SOURCES19    dialects/standalone_pybind11.py20    dialects/standalone_nanobind.py21    _mlir_libs/_standaloneDialectsNanobind/py.typed22  DIALECT_NAME standalone)23 24 25declare_mlir_python_extension(StandalonePythonSources.Pybind11Extension26  MODULE_NAME _standaloneDialectsPybind1127  ADD_TO_PARENT StandalonePythonSources28  SOURCES29    StandaloneExtensionPybind11.cpp30  PRIVATE_LINK_LIBS31    LLVMSupport32  EMBED_CAPI_LINK_LIBS33    MLIRCAPIIR34    MLIRCAPIArith35    MLIRCAPITransforms36    StandaloneCAPI37  PYTHON_BINDINGS_LIBRARY pybind1138)39 40declare_mlir_python_extension(StandalonePythonSources.NanobindExtension41  MODULE_NAME _standaloneDialectsNanobind42  ADD_TO_PARENT StandalonePythonSources43  SOURCES44    StandaloneExtensionNanobind.cpp45  PRIVATE_LINK_LIBS46    LLVMSupport47  EMBED_CAPI_LINK_LIBS48    MLIRCAPIIR49    MLIRCAPIArith50    MLIRCAPITransforms51    StandaloneCAPI52  PYTHON_BINDINGS_LIBRARY nanobind53)54 55 56################################################################################57# Common CAPI58################################################################################59 60add_mlir_python_common_capi_library(StandalonePythonCAPI61  INSTALL_COMPONENT StandalonePythonModules62  INSTALL_DESTINATION "${MLIR_BINDINGS_PYTHON_INSTALL_PREFIX}/_mlir_libs"63  OUTPUT_DIRECTORY "${MLIR_BINARY_DIR}/${MLIR_BINDINGS_PYTHON_INSTALL_PREFIX}/_mlir_libs"64  RELATIVE_INSTALL_ROOT "../../../.."65  DECLARED_SOURCES66    StandalonePythonSources67    MLIRPythonSources.Core68    MLIRPythonSources.Dialects.builtin69)70 71################################################################################72# Instantiation of all Python modules73################################################################################74 75set(StandalonePythonModules_ROOT_PREFIX "${MLIR_BINARY_DIR}/${MLIR_BINDINGS_PYTHON_INSTALL_PREFIX}")76 77if(MLIR_PYTHON_STUBGEN_ENABLED)78  # Everything here is very tightly coupled. See the ample descriptions at the bottom of79  # mlir/python/CMakeLists.txt.80 81  # For a non-external projects build (e.g., installed distro) the type gen targets for the core _mlir module82  # need to be re-declared. On the contrary, for an external projects build, the MLIRPythonExtension.Core.type_stub_gen83  # target already exists and can just be added to DECLARED_SOURCES (see below).84  if(NOT EXTERNAL_PROJECT_BUILD)85    set(_core_type_stub_sources86      _mlir/__init__.pyi87      _mlir/ir.pyi88      _mlir/passmanager.pyi89      _mlir/rewrite.pyi90    )91    get_target_property(_core_extension_srcs MLIRPythonExtension.Core INTERFACE_SOURCES)92    mlir_generate_type_stubs(93      MODULE_NAME _mlir94      DEPENDS_TARGETS StandalonePythonModules.extension._mlir.dso95      OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/type_stubs/_mlir_libs"96      OUTPUTS "${_core_type_stub_sources}"97      DEPENDS_TARGET_SRC_DEPS "${_core_extension_srcs}"98      IMPORT_PATHS "${StandalonePythonModules_ROOT_PREFIX}/_mlir_libs"99      VERBOSE100    )101    set(_mlir_typestub_gen_target "${NB_STUBGEN_CUSTOM_TARGET}")102 103    list(TRANSFORM _core_type_stub_sources PREPEND "_mlir_libs/")104    declare_mlir_python_sources(105      StandalonePythonExtension.Core.type_stub_gen106      ROOT_DIR "${CMAKE_CURRENT_BINARY_DIR}/type_stubs"107      ADD_TO_PARENT StandalonePythonSources108      SOURCES "${_core_type_stub_sources}"109    )110  endif()111 112  get_target_property(_standalone_extension_srcs StandalonePythonSources.NanobindExtension INTERFACE_SOURCES)113  mlir_generate_type_stubs(114    MODULE_NAME mlir_standalone._mlir_libs._standaloneDialectsNanobind115    DEPENDS_TARGETS116      StandalonePythonModules.extension._mlir.dso117      StandalonePythonModules.extension._standaloneDialectsNanobind.dso118    OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/type_stubs/_mlir_libs"119    OUTPUTS120      _standaloneDialectsNanobind/__init__.pyi121      _standaloneDialectsNanobind/standalone.pyi122    DEPENDS_TARGET_SRC_DEPS "${_standalone_extension_srcs}"123    IMPORT_PATHS "${StandalonePythonModules_ROOT_PREFIX}/.."124  )125  set(_standaloneDialectsNanobind_typestub_gen_target "${NB_STUBGEN_CUSTOM_TARGET}")126 127  declare_mlir_python_sources(128    StandalonePythonSources.type_stub_gen129    ROOT_DIR "${CMAKE_CURRENT_BINARY_DIR}/type_stubs"130    ADD_TO_PARENT StandalonePythonSources131    SOURCES132      _mlir_libs/_standaloneDialectsNanobind/__init__.pyi133      _mlir_libs/_standaloneDialectsNanobind/standalone.pyi134  )135endif()136 137set(_declared_sources138  StandalonePythonSources139  MLIRPythonSources.Core140  MLIRPythonSources.Dialects.builtin141)142# For an external projects build, the MLIRPythonExtension.Core.type_stub_gen143# target already exists and can just be added to DECLARED_SOURCES.144if(EXTERNAL_PROJECT_BUILD AND MLIR_PYTHON_STUBGEN_ENABLED)145  list(APPEND _declared_sources MLIRPythonExtension.Core.type_stub_gen)146endif()147 148add_mlir_python_modules(StandalonePythonModules149  ROOT_PREFIX "${StandalonePythonModules_ROOT_PREFIX}"150  INSTALL_PREFIX "${MLIR_BINDINGS_PYTHON_INSTALL_PREFIX}"151  DECLARED_SOURCES "${_declared_sources}"152  COMMON_CAPI_LINK_LIBS153    StandalonePythonCAPI154)155 156if(MLIR_PYTHON_STUBGEN_ENABLED)157  if(NOT EXTERNAL_PROJECT_BUILD)158    add_dependencies(StandalonePythonModules "${_mlir_typestub_gen_target}")159  endif()160  add_dependencies(StandalonePythonModules "${_standaloneDialectsNanobind_typestub_gen_target}")161endif()162