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