1# Generate a list of CMake library targets so that other CMake projects can 2# link against them. LLVM calls its version of this file LLVMExports.cmake, but 3# the usual CMake convention seems to be ${Project}Targets.cmake. 4set(MLIR_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/mlir) 5set(mlir_cmake_builddir "${CMAKE_BINARY_DIR}/${MLIR_INSTALL_PACKAGE_DIR}") 6 7# Keep this in sync with llvm/cmake/CMakeLists.txt! 8set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm) 9set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}") 10 11get_property(MLIR_EXPORTS GLOBAL PROPERTY MLIR_EXPORTS) 12export(TARGETS ${MLIR_EXPORTS} FILE ${mlir_cmake_builddir}/MLIRTargets.cmake) 13 14get_property(MLIR_ALL_LIBS GLOBAL PROPERTY MLIR_ALL_LIBS) 15get_property(MLIR_DIALECT_LIBS GLOBAL PROPERTY MLIR_DIALECT_LIBS) 16get_property(MLIR_CONVERSION_LIBS GLOBAL PROPERTY MLIR_CONVERSION_LIBS) 17get_property(MLIR_TRANSLATION_LIBS GLOBAL PROPERTY MLIR_TRANSLATION_LIBS) 18 19# Generate MlirConfig.cmake for the build tree. 20set(MLIR_CONFIG_CMAKE_DIR "${mlir_cmake_builddir}") 21set(MLIR_CONFIG_LLVM_CMAKE_DIR "${llvm_cmake_builddir}") 22set(MLIR_CONFIG_EXPORTS_FILE "\${MLIR_CMAKE_DIR}/MLIRTargets.cmake") 23set(MLIR_CONFIG_INCLUDE_DIRS 24 "${MLIR_SOURCE_DIR}/include" 25 "${MLIR_BINARY_DIR}/include" 26 ) 27configure_file( 28 ${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfig.cmake.in 29 ${mlir_cmake_builddir}/MLIRConfig.cmake 30 @ONLY) 31set(MLIR_CONFIG_CMAKE_DIR) 32set(MLIR_CONFIG_LLVM_CMAKE_DIR) 33set(MLIR_CONFIG_EXPORTS_FILE) 34set(MLIR_CONFIG_INCLUDE_DIRS) 35 36# For compatibility with projects that include(MLIRConfig) 37# via CMAKE_MODULE_PATH, place API modules next to it. 38# This should be removed in the future. 39file(COPY . 40 DESTINATION ${mlir_cmake_builddir} 41 FILES_MATCHING PATTERN *.cmake 42 PATTERN CMakeFiles EXCLUDE 43 ) 44 45# Generate MLIRConfig.cmake for the install tree. 46set(MLIR_CONFIG_CODE " 47# Compute the installation prefix from this MLIRConfig.cmake file location. 48get_filename_component(MLIR_INSTALL_PREFIX \"\${CMAKE_CURRENT_LIST_FILE}\" PATH)") 49# Construct the proper number of get_filename_component(... PATH) 50# calls to compute the installation prefix. 51string(REGEX REPLACE "/" ";" _count "${MLIR_INSTALL_PACKAGE_DIR}") 52foreach(p ${_count}) 53 set(MLIR_CONFIG_CODE "${MLIR_CONFIG_CODE} 54get_filename_component(MLIR_INSTALL_PREFIX \"\${MLIR_INSTALL_PREFIX}\" PATH)") 55endforeach(p) 56set(MLIR_CONFIG_CMAKE_DIR "\${MLIR_INSTALL_PREFIX}/${MLIR_INSTALL_PACKAGE_DIR}") 57set(MLIR_CONFIG_LLVM_CMAKE_DIR "\${MLIR_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}") 58set(MLIR_CONFIG_EXPORTS_FILE "\${MLIR_CMAKE_DIR}/MLIRTargets.cmake") 59set(MLIR_CONFIG_INCLUDE_DIRS 60 "\${MLIR_INSTALL_PREFIX}/include" 61 ) 62configure_file( 63 ${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfig.cmake.in 64 ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfig.cmake 65 @ONLY) 66set(MLIR_CONFIG_CODE) 67set(MLIR_CONFIG_CMAKE_DIR) 68set(MLIR_CONFIG_LLVM_CMAKE_DIR) 69set(MLIR_CONFIG_EXPORTS_FILE) 70set(MLIR_CONFIG_INCLUDE_DIRS) 71 72if (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 get_property(mlir_has_exports GLOBAL PROPERTY MLIR_HAS_EXPORTS) 76 if(mlir_has_exports) 77 install(EXPORT MLIRTargets DESTINATION ${MLIR_INSTALL_PACKAGE_DIR} 78 COMPONENT mlir-cmake-exports) 79 endif() 80 81 install(FILES 82 ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfig.cmake 83 ${CMAKE_CURRENT_SOURCE_DIR}/AddMLIR.cmake 84 DESTINATION ${MLIR_INSTALL_PACKAGE_DIR} 85 COMPONENT mlir-cmake-exports) 86 87 if(NOT LLVM_ENABLE_IDE) 88 # Add a dummy target so this can be used with LLVM_DISTRIBUTION_COMPONENTS 89 add_custom_target(mlir-cmake-exports) 90 add_llvm_install_targets(install-mlir-cmake-exports 91 COMPONENT mlir-cmake-exports) 92 endif() 93endif() 94