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}")
44 ${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfig.cmake.in
45 ${mlir_cmake_builddir}/MLIRConfig.cmake
48 ${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfigVersion.cmake.in
49 ${mlir_cmake_builddir}/MLIRConfigVersion.cmake
51 set(MLIR_CONFIG_CMAKE_DIR)
52 set(MLIR_CONFIG_LLVM_CMAKE_DIR)
53 set(MLIR_CONFIG_INCLUDE_DIRS)
55 # For compatibility with projects that include(MLIRConfig)
56 # via CMAKE_MODULE_PATH, place API modules next to it.
57 # Copy without source permissions because the source could be read-only,
58 # but we need to write into the copied folder.
59 # This should be removed in the future.
61 DESTINATION ${mlir_cmake_builddir}
63 FILES_MATCHING PATTERN *.cmake
64 PATTERN CMakeFiles EXCLUDE
67 # Generate MLIRConfig.cmake for the install tree.
68 find_prefix_from_config(MLIR_CONFIG_CODE MLIR_INSTALL_PREFIX "${MLIR_INSTALL_PACKAGE_DIR}")
69 extend_path(MLIR_CONFIG_CMAKE_DIR "\${MLIR_INSTALL_PREFIX}" "${MLIR_INSTALL_PACKAGE_DIR}")
70 extend_path(MLIR_CONFIG_LLVM_CMAKE_DIR "\${MLIR_INSTALL_PREFIX}" "${LLVM_INSTALL_PACKAGE_DIR}")
71 get_config_exports_includes(MLIR MLIR_CONFIG_INCLUDE_EXPORTS)
72 extend_path(base_includedir "\${MLIR_INSTALL_PREFIX}" "${CMAKE_INSTALL_INCLUDEDIR}")
73 set(MLIR_CONFIG_INCLUDE_DIRS
76 # Ensure that we are using the installed mlir-tblgen. This might not be MLIR_TABLEGEN_EXE
77 # if we're building with a host-optimized mlir-tblgen (with LLVM_OPTIMIZED_TABLEGEN).
78 set(MLIR_CONFIG_TABLEGEN_EXE mlir-tblgen)
79 set(MLIR_CONFIG_PDLL_TABLEGEN_EXE mlir-pdll)
82 ${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfig.cmake.in
83 ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfig.cmake
86 ${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfigVersion.cmake.in
87 ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfigVersion.cmake
90 set(MLIR_CONFIG_CMAKE_DIR)
91 set(MLIR_CONFIG_LLVM_CMAKE_DIR)
92 set(MLIR_CONFIG_INCLUDE_DIRS)
94 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
95 # Not TOOLCHAIN ONLY, so install the MLIR parts as well
96 # Include the cmake files so other tools can use mlir-tblgen, etc.
97 install_distribution_exports(MLIR)
100 ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfig.cmake
101 ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfigVersion.cmake
102 ${CMAKE_CURRENT_SOURCE_DIR}/AddMLIR.cmake
103 ${CMAKE_CURRENT_SOURCE_DIR}/AddMLIRPython.cmake
104 ${CMAKE_CURRENT_SOURCE_DIR}/MLIRDetectPythonEnv.cmake
105 DESTINATION ${MLIR_INSTALL_PACKAGE_DIR}
106 COMPONENT mlir-cmake-exports)
108 if(NOT LLVM_ENABLE_IDE)
109 # Add a dummy target so this can be used with LLVM_DISTRIBUTION_COMPONENTS
110 add_custom_target(mlir-cmake-exports)
111 add_llvm_install_targets(install-mlir-cmake-exports
112 COMPONENT mlir-cmake-exports)