1################################################################################
2# Copy python source tree.
3################################################################################
4
5file(GLOB_RECURSE PY_SRC_FILES
6  RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
7  "${CMAKE_CURRENT_SOURCE_DIR}/mlir/*.py")
8
9add_custom_target(MLIRBindingsPythonSources ALL
10  DEPENDS
11    ${PY_SRC_FILES}
12)
13
14foreach(PY_SRC_FILE ${PY_SRC_FILES})
15  set(PY_DEST_FILE "${PROJECT_BINARY_DIR}/python/${PY_SRC_FILE}")
16  get_filename_component(PY_DEST_DIR "${PY_DEST_FILE}" DIRECTORY)
17  file(MAKE_DIRECTORY "${PY_DEST_DIR}")
18  add_custom_command(
19    TARGET MLIRBindingsPythonSources PRE_BUILD
20    COMMENT "Copying python source ${PY_SRC_FILE} -> ${PY_DEST_FILE}"
21    DEPENDS "${PY_SRC_FILE}"
22    BYPRODUCTS "${PY_DEST_FILE}"
23    COMMAND "${CMAKE_COMMAND}" -E create_symlink
24        "${CMAKE_CURRENT_SOURCE_DIR}/${PY_SRC_FILE}" "${PY_DEST_FILE}"
25  )
26endforeach()
27
28# Note that we copy from the source tree just like for headers because
29# it will not be polluted with py_cache runtime artifacts (from testing and
30# such).
31install(
32  DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/mlir
33  DESTINATION python
34  COMPONENT MLIRBindingsPythonSources
35  FILES_MATCHING PATTERN "*.py"
36)
37
38if (NOT LLVM_ENABLE_IDE)
39  add_llvm_install_targets(
40    install-MLIRBindingsPythonSources
41    DEPENDS MLIRBindingsPythonSources
42    COMPONENT MLIRBindingsPythonSources)
43endif()
44
45################################################################################
46# Generated sources.
47################################################################################
48
49add_subdirectory(mlir/dialects)
50