1 include(LLVMDistributionSupport)
3 # Generate a list of CMake library targets so that other CMake projects can
4 # link against them. LLVM calls its version of this file LLVMExports.cmake, but
5 # the usual CMake convention seems to be ${Project}Targets.cmake.
6 set(MLIR_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/mlir)
7 set(mlir_cmake_builddir "${CMAKE_BINARY_DIR}/${MLIR_INSTALL_PACKAGE_DIR}")
9 # Keep this in sync with llvm/cmake/CMakeLists.txt!
10 set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm)
11 set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}")
13 get_property(MLIR_EXPORTS GLOBAL PROPERTY MLIR_EXPORTS)
14 export(TARGETS ${MLIR_EXPORTS} FILE ${mlir_cmake_builddir}/MLIRTargets.cmake)
16 get_property(MLIR_ALL_LIBS GLOBAL PROPERTY MLIR_ALL_LIBS)
17 get_property(MLIR_DIALECT_LIBS GLOBAL PROPERTY MLIR_DIALECT_LIBS)
18 get_property(MLIR_CONVERSION_LIBS GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
19 get_property(MLIR_TRANSLATION_LIBS GLOBAL PROPERTY MLIR_TRANSLATION_LIBS)
21 # Generate MlirConfig.cmake for the build tree.
22 set(MLIR_CONFIG_CMAKE_DIR "${mlir_cmake_builddir}")
23 set(MLIR_CONFIG_LLVM_CMAKE_DIR "${llvm_cmake_builddir}")
24 set(MLIR_CONFIG_INCLUDE_EXPORTS "include(\"\${MLIR_CMAKE_DIR}/MLIRTargets.cmake\")")
25 set(MLIR_CONFIG_INCLUDE_DIRS
26 "${MLIR_SOURCE_DIR}/include"
27 "${MLIR_BINARY_DIR}/include"
30 ${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfig.cmake.in
31 ${mlir_cmake_builddir}/MLIRConfig.cmake
33 set(MLIR_CONFIG_CMAKE_DIR)
34 set(MLIR_CONFIG_LLVM_CMAKE_DIR)
35 set(MLIR_CONFIG_INCLUDE_DIRS)
37 # For compatibility with projects that include(MLIRConfig)
38 # via CMAKE_MODULE_PATH, place API modules next to it.
39 # This should be removed in the future.
41 DESTINATION ${mlir_cmake_builddir}
42 FILES_MATCHING PATTERN *.cmake
43 PATTERN CMakeFiles EXCLUDE
46 # Generate MLIRConfig.cmake for the install tree.
47 set(MLIR_CONFIG_CODE "
48 # Compute the installation prefix from this MLIRConfig.cmake file location.
49 get_filename_component(MLIR_INSTALL_PREFIX \"\${CMAKE_CURRENT_LIST_FILE}\" PATH)")
50 # Construct the proper number of get_filename_component(... PATH)
51 # calls to compute the installation prefix.
52 string(REGEX REPLACE "/" ";" _count "${MLIR_INSTALL_PACKAGE_DIR}")
54 set(MLIR_CONFIG_CODE "${MLIR_CONFIG_CODE}
55 get_filename_component(MLIR_INSTALL_PREFIX \"\${MLIR_INSTALL_PREFIX}\" PATH)")
57 set(MLIR_CONFIG_CMAKE_DIR "\${MLIR_INSTALL_PREFIX}/${MLIR_INSTALL_PACKAGE_DIR}")
58 set(MLIR_CONFIG_LLVM_CMAKE_DIR "\${MLIR_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}")
59 get_config_exports_includes(MLIR MLIR_CONFIG_INCLUDE_EXPORTS)
60 set(MLIR_CONFIG_INCLUDE_DIRS
61 "\${MLIR_INSTALL_PREFIX}/include"
64 ${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfig.cmake.in
65 ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfig.cmake
68 set(MLIR_CONFIG_CMAKE_DIR)
69 set(MLIR_CONFIG_LLVM_CMAKE_DIR)
70 set(MLIR_CONFIG_INCLUDE_DIRS)
72 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
73 # Not TOOLCHAIN ONLY, so install the MLIR parts as well
74 # Include the cmake files so other tools can use mlir-tblgen, etc.
75 install_distribution_exports(MLIR)
78 ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfig.cmake
79 ${CMAKE_CURRENT_SOURCE_DIR}/AddMLIR.cmake
80 ${CMAKE_CURRENT_SOURCE_DIR}/AddMLIRPython.cmake
81 ${CMAKE_CURRENT_SOURCE_DIR}/MLIRDetectPythonEnv.cmake
82 DESTINATION ${MLIR_INSTALL_PACKAGE_DIR}
83 COMPONENT mlir-cmake-exports)
85 if(NOT LLVM_ENABLE_IDE)
86 # Add a dummy target so this can be used with LLVM_DISTRIBUTION_COMPONENTS
87 add_custom_target(mlir-cmake-exports)
88 add_llvm_install_targets(install-mlir-cmake-exports
89 COMPONENT mlir-cmake-exports)