221
|
1 include(LLVMDistributionSupport)
|
|
2
|
150
|
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.
|
173
|
6 set(MLIR_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/mlir)
|
150
|
7 set(mlir_cmake_builddir "${CMAKE_BINARY_DIR}/${MLIR_INSTALL_PACKAGE_DIR}")
|
|
8
|
|
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}")
|
|
12
|
|
13 get_property(MLIR_EXPORTS GLOBAL PROPERTY MLIR_EXPORTS)
|
173
|
14 export(TARGETS ${MLIR_EXPORTS} FILE ${mlir_cmake_builddir}/MLIRTargets.cmake)
|
|
15
|
|
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)
|
221
|
19 get_property(MLIR_TRANSLATION_LIBS GLOBAL PROPERTY MLIR_TRANSLATION_LIBS)
|
150
|
20
|
|
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}")
|
221
|
24 set(MLIR_CONFIG_INCLUDE_EXPORTS "include(\"\${MLIR_CMAKE_DIR}/MLIRTargets.cmake\")")
|
150
|
25 set(MLIR_CONFIG_INCLUDE_DIRS
|
|
26 "${MLIR_SOURCE_DIR}/include"
|
|
27 "${MLIR_BINARY_DIR}/include"
|
|
28 )
|
173
|
29 configure_file(
|
|
30 ${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfig.cmake.in
|
|
31 ${mlir_cmake_builddir}/MLIRConfig.cmake
|
|
32 @ONLY)
|
150
|
33 set(MLIR_CONFIG_CMAKE_DIR)
|
|
34 set(MLIR_CONFIG_LLVM_CMAKE_DIR)
|
173
|
35 set(MLIR_CONFIG_INCLUDE_DIRS)
|
150
|
36
|
173
|
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.
|
|
40 file(COPY .
|
|
41 DESTINATION ${mlir_cmake_builddir}
|
|
42 FILES_MATCHING PATTERN *.cmake
|
|
43 PATTERN CMakeFiles EXCLUDE
|
|
44 )
|
|
45
|
|
46 # Generate MLIRConfig.cmake for the install tree.
|
150
|
47 set(MLIR_CONFIG_CODE "
|
173
|
48 # Compute the installation prefix from this MLIRConfig.cmake file location.
|
150
|
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}")
|
|
53 foreach(p ${_count})
|
|
54 set(MLIR_CONFIG_CODE "${MLIR_CONFIG_CODE}
|
|
55 get_filename_component(MLIR_INSTALL_PREFIX \"\${MLIR_INSTALL_PREFIX}\" PATH)")
|
|
56 endforeach(p)
|
|
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}")
|
221
|
59 get_config_exports_includes(MLIR MLIR_CONFIG_INCLUDE_EXPORTS)
|
150
|
60 set(MLIR_CONFIG_INCLUDE_DIRS
|
|
61 "\${MLIR_INSTALL_PREFIX}/include"
|
|
62 )
|
173
|
63 configure_file(
|
|
64 ${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfig.cmake.in
|
|
65 ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfig.cmake
|
|
66 @ONLY)
|
150
|
67 set(MLIR_CONFIG_CODE)
|
|
68 set(MLIR_CONFIG_CMAKE_DIR)
|
173
|
69 set(MLIR_CONFIG_LLVM_CMAKE_DIR)
|
|
70 set(MLIR_CONFIG_INCLUDE_DIRS)
|
150
|
71
|
|
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.
|
221
|
75 install_distribution_exports(MLIR)
|
150
|
76
|
173
|
77 install(FILES
|
|
78 ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfig.cmake
|
150
|
79 ${CMAKE_CURRENT_SOURCE_DIR}/AddMLIR.cmake
|
221
|
80 ${CMAKE_CURRENT_SOURCE_DIR}/AddMLIRPython.cmake
|
|
81 ${CMAKE_CURRENT_SOURCE_DIR}/MLIRDetectPythonEnv.cmake
|
150
|
82 DESTINATION ${MLIR_INSTALL_PACKAGE_DIR}
|
|
83 COMPONENT mlir-cmake-exports)
|
|
84
|
|
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)
|
|
90 endif()
|
|
91 endif()
|