Files
clang-p2996/mlir/examples/standalone/python/CMakeLists.txt
Stella Laurenzo 132bc6e2d4 Re-apply "[mlir] Allow out-of-tree python building from installed MLIR."
Re-applies D111513:
* Adds a full-fledged Python example dialect and tests to the Standalone example (need to do a bit of tweaking in the top level CMake and lit tests to adapt better to if not building with Python enabled).
* Rips out remnants of custom extension building in favor of pybind11_add_module which does the right thing.
* Makes python and extension sources installable (outputs to src/python/${name} in the install tree): Both Python and C++ extension sources get installed as downstreams need all of this in order to build a derived version of the API.
* Exports sources targets (with our properties that make everything work) by converting them to INTERFACE libraries (which have export support), as recommended for the forseeable future by CMake devs. Renames custom properties to start with lower-case letter, as also recommended/required (groan).
* Adds a ROOT_DIR argument to declare_mlir_python_extension since now all C++ sources for an extension must be under the same directory (to line up at install time).
* Downstreams will need to adapt by:

  * Remove absolute paths from any SOURCES for declare_mlir_python_extension (I believe all downstreams are just using ${CMAKE_CURRENT_SOURCE_DIR} here, which can just be ommitted). May need to set ROOT_DIR if not relative to the current source directory.
  * To allow further downstreams to install/build, will need to make sure that all C++ extension headers are also listed under SOURCES for declare_mlir_python_extension.

This reverts commit 1a6c26d1f5.

Reviewed By: stephenneuendorffer

Differential Revision: https://reviews.llvm.org/D113732
2021-11-14 20:31:34 -08:00

59 lines
2.0 KiB
CMake

include(AddMLIRPython)
# Specifies that all MLIR packages are co-located under the `mlir_standalone`
# top level package (the API has been embedded in a relocatable way).
# TODO: Add an upstream cmake param for this vs having a global here.
add_compile_definitions("MLIR_PYTHON_PACKAGE_PREFIX=mlir_standalone.")
################################################################################
# Sources
################################################################################
declare_mlir_python_sources(StandalonePythonSources)
declare_mlir_dialect_python_bindings(
ADD_TO_PARENT StandalonePythonSources
ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir_standalone"
TD_FILE dialects/StandaloneOps.td
SOURCES
dialects/standalone.py
DIALECT_NAME standalone)
declare_mlir_python_extension(StandalonePythonSources.Extension
MODULE_NAME _standaloneDialects
ADD_TO_PARENT StandalonePythonSources
SOURCES
StandaloneExtension.cpp
EMBED_CAPI_LINK_LIBS
StandaloneCAPI
)
################################################################################
# Common CAPI
################################################################################
add_mlir_python_common_capi_library(StandalonePythonCAPI
INSTALL_COMPONENT StandalonePythonModules
INSTALL_DESTINATION python_packages/standalone/mlir_standalone/_mlir_libs
OUTPUT_DIRECTORY "${MLIR_BINARY_DIR}/python_packages/standalone/mlir_standalone/_mlir_libs"
RELATIVE_INSTALL_ROOT "../../../.."
DECLARED_SOURCES
StandalonePythonSources
MLIRPythonSources.Core
)
################################################################################
# Instantiation of all Python modules
################################################################################
add_mlir_python_modules(StandalonePythonModules
ROOT_PREFIX "${MLIR_BINARY_DIR}/python_packages/standalone/mlir_standalone"
INSTALL_PREFIX "python_packages/standalone/mlir_standalone"
DECLARED_SOURCES
StandalonePythonSources
MLIRPythonSources
COMMON_CAPI_LINK_LIBS
StandalonePythonCAPI
)