1 include(GNUInstallPackageDir)
3 include(LLVMDistributionSupport)
4 include(FindPrefixFromConfig)
6 # Generate a list of CMake library targets so that other CMake projects can
7 # link against them. LLVM calls its version of this file LLVMExports.cmake, but
8 # the usual CMake convention seems to be ${Project}Targets.cmake.
9 set(MLIR_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/mlir" CACHE STRING
10 "Path for CMake subdirectory for Polly (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/polly')")
11 # CMAKE_INSTALL_PACKAGEDIR might be absolute, so don't reuse below.
12 set(mlir_cmake_builddir "${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/mlir")
14 # Keep this in sync with llvm/cmake/CMakeLists.txt!
15 set(LLVM_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/llvm" CACHE STRING
16 "Path for CMake subdirectory for LLVM (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/llvm')")
17 # CMAKE_INSTALL_PACKAGEDIR might be absolute, so don't reuse below.
18 string(REPLACE "${CMAKE_CFG_INTDIR}" "." llvm_cmake_builddir "${LLVM_LIBRARY_DIR}")
19 set(llvm_cmake_builddir "${llvm_cmake_builddir}/cmake/llvm")
21 get_property(MLIR_EXPORTS GLOBAL PROPERTY MLIR_EXPORTS)
22 export(TARGETS ${MLIR_EXPORTS} FILE ${mlir_cmake_builddir}/MLIRTargets.cmake)
24 get_property(MLIR_ALL_LIBS GLOBAL PROPERTY MLIR_ALL_LIBS)
25 get_property(MLIR_DIALECT_LIBS GLOBAL PROPERTY MLIR_DIALECT_LIBS)
26 get_property(MLIR_CONVERSION_LIBS GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
27 get_property(MLIR_EXTENSION_LIBS GLOBAL PROPERTY MLIR_EXTENSION_LIBS)
28 get_property(MLIR_TRANSLATION_LIBS GLOBAL PROPERTY MLIR_TRANSLATION_LIBS)
29 get_property(MLIR_CAPI_LIBS GLOBAL PROPERTY MLIR_CAPI_LIBS)
31 # Generate MlirConfig.cmake for the build tree.
32 set(MLIR_CONFIG_CMAKE_DIR "${mlir_cmake_builddir}")
33 set(MLIR_CONFIG_LLVM_CMAKE_DIR "${llvm_cmake_builddir}")
34 set(MLIR_CONFIG_INCLUDE_EXPORTS "include(\"\${MLIR_CMAKE_DIR}/MLIRTargets.cmake\")")
35 set(MLIR_CONFIG_INCLUDE_DIRS
36 "${MLIR_SOURCE_DIR}/include"
37 "${MLIR_BINARY_DIR}/include"
39 # Refer to the best host mlir-tbgen, which might be a host-optimized version
40 set(MLIR_CONFIG_TABLEGEN_EXE "${MLIR_TABLEGEN_EXE}")
41 set(MLIR_CONFIG_PDLL_TABLEGEN_EXE "${MLIR_PDLL_TABLEGEN_EXE}")
42 set(MLIR_CONFIG_SRC_SHARDER_TABLEGEN_EXE "${MLIR_SRC_SHARDER_TABLEGEN_EXE}")
45 ${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfig.cmake.in
46 ${mlir_cmake_builddir}/MLIRConfig.cmake
49 ${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfigVersion.cmake.in
50 ${mlir_cmake_builddir}/MLIRConfigVersion.cmake
52 set(MLIR_CONFIG_CMAKE_DIR)
53 set(MLIR_CONFIG_LLVM_CMAKE_DIR)
54 set(MLIR_CONFIG_INCLUDE_DIRS)
56 # For compatibility with projects that include(MLIRConfig)
57 # via CMAKE_MODULE_PATH, place API modules next to it.
58 # Copy without source permissions because the source could be read-only,
59 # but we need to write into the copied folder.
60 # This should be removed in the future.
62 DESTINATION ${mlir_cmake_builddir}
64 FILES_MATCHING PATTERN *.cmake
65 PATTERN CMakeFiles EXCLUDE
68 # Generate MLIRConfig.cmake for the install tree.
69 find_prefix_from_config(MLIR_CONFIG_CODE MLIR_INSTALL_PREFIX "${MLIR_INSTALL_PACKAGE_DIR}")
70 extend_path(MLIR_CONFIG_CMAKE_DIR "\${MLIR_INSTALL_PREFIX}" "${MLIR_INSTALL_PACKAGE_DIR}")
71 extend_path(MLIR_CONFIG_LLVM_CMAKE_DIR "\${MLIR_INSTALL_PREFIX}" "${LLVM_INSTALL_PACKAGE_DIR}")
72 get_config_exports_includes(MLIR MLIR_CONFIG_INCLUDE_EXPORTS)
73 extend_path(base_includedir "\${MLIR_INSTALL_PREFIX}" "${CMAKE_INSTALL_INCLUDEDIR}")
74 set(MLIR_CONFIG_INCLUDE_DIRS
77 # Ensure that we are using the installed mlir-tblgen. This might not be MLIR_TABLEGEN_EXE
78 # if we're building with a host-optimized mlir-tblgen (with LLVM_OPTIMIZED_TABLEGEN).
79 set(MLIR_CONFIG_TABLEGEN_EXE mlir-tblgen)
80 set(MLIR_CONFIG_PDLL_TABLEGEN_EXE mlir-pdll)
81 set(MLIR_CONFIG_SRC_SHARDER_TABLEGEN_EXE mlir-src-sharder)
84 ${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfig.cmake.in
85 ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfig.cmake
88 ${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfigVersion.cmake.in
89 ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfigVersion.cmake
92 set(MLIR_CONFIG_CMAKE_DIR)
93 set(MLIR_CONFIG_LLVM_CMAKE_DIR)
94 set(MLIR_CONFIG_INCLUDE_DIRS)
96 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
97 # Not TOOLCHAIN ONLY, so install the MLIR parts as well
98 # Include the cmake files so other tools can use mlir-tblgen, etc.
99 install_distribution_exports(MLIR)
102 ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfig.cmake
103 ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfigVersion.cmake
104 ${CMAKE_CURRENT_SOURCE_DIR}/AddMLIR.cmake
105 ${CMAKE_CURRENT_SOURCE_DIR}/AddMLIRPython.cmake
106 ${CMAKE_CURRENT_SOURCE_DIR}/MLIRDetectPythonEnv.cmake
107 DESTINATION ${MLIR_INSTALL_PACKAGE_DIR}
108 COMPONENT mlir-cmake-exports)
110 if(NOT LLVM_ENABLE_IDE)
111 # Add a dummy target so this can be used with LLVM_DISTRIBUTION_COMPONENTS
112 add_custom_target(mlir-cmake-exports)
113 add_llvm_install_targets(install-mlir-cmake-exports
114 COMPONENT mlir-cmake-exports)