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_TRANSLATION_LIBS GLOBAL PROPERTY MLIR_TRANSLATION_LIBS)
29 # Generate MlirConfig.cmake for the build tree.
30 set(MLIR_CONFIG_CMAKE_DIR "${mlir_cmake_builddir}")
31 set(MLIR_CONFIG_LLVM_CMAKE_DIR "${llvm_cmake_builddir}")
32 set(MLIR_CONFIG_INCLUDE_EXPORTS "include(\"\${MLIR_CMAKE_DIR}/MLIRTargets.cmake\")")
33 set(MLIR_CONFIG_INCLUDE_DIRS
34 "${MLIR_SOURCE_DIR}/include"
35 "${MLIR_BINARY_DIR}/include"
37 # Refer to the best host mlir-tbgen, which might be a host-optimized version
38 set(MLIR_CONFIG_TABLEGEN_EXE "${MLIR_TABLEGEN_EXE}")
39 set(MLIR_CONFIG_PDLL_TABLEGEN_EXE "${MLIR_PDLL_TABLEGEN_EXE}")
42 ${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfig.cmake.in
43 ${mlir_cmake_builddir}/MLIRConfig.cmake
46 ${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfigVersion.cmake.in
47 ${mlir_cmake_builddir}/MLIRConfigVersion.cmake
49 set(MLIR_CONFIG_CMAKE_DIR)
50 set(MLIR_CONFIG_LLVM_CMAKE_DIR)
51 set(MLIR_CONFIG_INCLUDE_DIRS)
53 # For compatibility with projects that include(MLIRConfig)
54 # via CMAKE_MODULE_PATH, place API modules next to it.
55 # Copy without source permissions because the source could be read-only,
56 # but we need to write into the copied folder.
57 # This should be removed in the future.
59 DESTINATION ${mlir_cmake_builddir}
61 FILES_MATCHING PATTERN *.cmake
62 PATTERN CMakeFiles EXCLUDE
65 # Generate MLIRConfig.cmake for the install tree.
66 find_prefix_from_config(MLIR_CONFIG_CODE MLIR_INSTALL_PREFIX "${MLIR_INSTALL_PACKAGE_DIR}")
67 extend_path(MLIR_CONFIG_CMAKE_DIR "\${MLIR_INSTALL_PREFIX}" "${MLIR_INSTALL_PACKAGE_DIR}")
68 extend_path(MLIR_CONFIG_LLVM_CMAKE_DIR "\${MLIR_INSTALL_PREFIX}" "${LLVM_INSTALL_PACKAGE_DIR}")
69 get_config_exports_includes(MLIR MLIR_CONFIG_INCLUDE_EXPORTS)
70 extend_path(base_includedir "\${MLIR_INSTALL_PREFIX}" "${CMAKE_INSTALL_INCLUDEDIR}")
71 set(MLIR_CONFIG_INCLUDE_DIRS
74 # Ensure that we are using the installed mlir-tblgen. This might not be MLIR_TABLEGEN_EXE
75 # if we're building with a host-optimized mlir-tblgen (with LLVM_OPTIMIZED_TABLEGEN).
76 set(MLIR_CONFIG_TABLEGEN_EXE mlir-tblgen)
77 set(MLIR_CONFIG_PDLL_TABLEGEN_EXE mlir-pdll)
80 ${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfig.cmake.in
81 ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfig.cmake
84 ${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfigVersion.cmake.in
85 ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfigVersion.cmake
88 set(MLIR_CONFIG_CMAKE_DIR)
89 set(MLIR_CONFIG_LLVM_CMAKE_DIR)
90 set(MLIR_CONFIG_INCLUDE_DIRS)
92 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
93 # Not TOOLCHAIN ONLY, so install the MLIR parts as well
94 # Include the cmake files so other tools can use mlir-tblgen, etc.
95 install_distribution_exports(MLIR)
98 ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfig.cmake
99 ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfigVersion.cmake
100 ${CMAKE_CURRENT_SOURCE_DIR}/AddMLIR.cmake
101 ${CMAKE_CURRENT_SOURCE_DIR}/AddMLIRPython.cmake
102 ${CMAKE_CURRENT_SOURCE_DIR}/MLIRDetectPythonEnv.cmake
103 DESTINATION ${MLIR_INSTALL_PACKAGE_DIR}
104 COMPONENT mlir-cmake-exports)
106 if(NOT LLVM_ENABLE_IDE)
107 # Add a dummy target so this can be used with LLVM_DISTRIBUTION_COMPONENTS
108 add_custom_target(mlir-cmake-exports)
109 add_llvm_install_targets(install-mlir-cmake-exports
110 COMPONENT mlir-cmake-exports)