2022-01-18 15:03:10 +08:00
|
|
|
include(ExtendPath)
|
2020-10-02 05:35:28 +08:00
|
|
|
include(LLVMDistributionSupport)
|
2022-01-03 10:25:06 +08:00
|
|
|
include(FindPrefixFromConfig)
|
2020-10-02 05:35:28 +08:00
|
|
|
|
2020-01-22 08:44:17 +08:00
|
|
|
# Generate a list of CMake library targets so that other CMake projects can
|
|
|
|
# link against them. LLVM calls its version of this file LLVMExports.cmake, but
|
|
|
|
# the usual CMake convention seems to be ${Project}Targets.cmake.
|
2020-03-12 13:35:58 +08:00
|
|
|
set(MLIR_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/mlir)
|
2020-01-22 08:44:17 +08:00
|
|
|
set(mlir_cmake_builddir "${CMAKE_BINARY_DIR}/${MLIR_INSTALL_PACKAGE_DIR}")
|
|
|
|
|
|
|
|
# Keep this in sync with llvm/cmake/CMakeLists.txt!
|
|
|
|
set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm)
|
|
|
|
set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}")
|
|
|
|
|
|
|
|
get_property(MLIR_EXPORTS GLOBAL PROPERTY MLIR_EXPORTS)
|
2020-03-12 13:35:58 +08:00
|
|
|
export(TARGETS ${MLIR_EXPORTS} FILE ${mlir_cmake_builddir}/MLIRTargets.cmake)
|
|
|
|
|
|
|
|
get_property(MLIR_ALL_LIBS GLOBAL PROPERTY MLIR_ALL_LIBS)
|
|
|
|
get_property(MLIR_DIALECT_LIBS GLOBAL PROPERTY MLIR_DIALECT_LIBS)
|
|
|
|
get_property(MLIR_CONVERSION_LIBS GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
|
2020-05-28 23:38:00 +08:00
|
|
|
get_property(MLIR_TRANSLATION_LIBS GLOBAL PROPERTY MLIR_TRANSLATION_LIBS)
|
2020-01-22 08:44:17 +08:00
|
|
|
|
|
|
|
# Generate MlirConfig.cmake for the build tree.
|
|
|
|
set(MLIR_CONFIG_CMAKE_DIR "${mlir_cmake_builddir}")
|
|
|
|
set(MLIR_CONFIG_LLVM_CMAKE_DIR "${llvm_cmake_builddir}")
|
2020-10-02 05:35:28 +08:00
|
|
|
set(MLIR_CONFIG_INCLUDE_EXPORTS "include(\"\${MLIR_CMAKE_DIR}/MLIRTargets.cmake\")")
|
2020-01-22 08:44:17 +08:00
|
|
|
set(MLIR_CONFIG_INCLUDE_DIRS
|
|
|
|
"${MLIR_SOURCE_DIR}/include"
|
|
|
|
"${MLIR_BINARY_DIR}/include"
|
|
|
|
)
|
2022-01-10 14:16:58 +08:00
|
|
|
# Refer to the best host mlir-tbgen, which might be a host-optimized version
|
|
|
|
set(MLIR_CONFIG_TABLEGEN_EXE "${MLIR_TABLEGEN_EXE}")
|
|
|
|
|
2020-03-12 13:35:58 +08:00
|
|
|
configure_file(
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfig.cmake.in
|
|
|
|
${mlir_cmake_builddir}/MLIRConfig.cmake
|
|
|
|
@ONLY)
|
2020-01-22 08:44:17 +08:00
|
|
|
set(MLIR_CONFIG_CMAKE_DIR)
|
|
|
|
set(MLIR_CONFIG_LLVM_CMAKE_DIR)
|
2020-03-12 13:35:58 +08:00
|
|
|
set(MLIR_CONFIG_INCLUDE_DIRS)
|
|
|
|
|
|
|
|
# For compatibility with projects that include(MLIRConfig)
|
|
|
|
# via CMAKE_MODULE_PATH, place API modules next to it.
|
|
|
|
# This should be removed in the future.
|
|
|
|
file(COPY .
|
|
|
|
DESTINATION ${mlir_cmake_builddir}
|
|
|
|
FILES_MATCHING PATTERN *.cmake
|
|
|
|
PATTERN CMakeFiles EXCLUDE
|
|
|
|
)
|
2020-01-22 08:44:17 +08:00
|
|
|
|
2020-03-12 13:35:58 +08:00
|
|
|
# Generate MLIRConfig.cmake for the install tree.
|
2022-01-03 10:25:06 +08:00
|
|
|
find_prefix_from_config(MLIR_CONFIG_CODE MLIR_INSTALL_PREFIX "${MLIR_INSTALL_PACKAGE_DIR}")
|
2020-01-22 08:44:17 +08:00
|
|
|
set(MLIR_CONFIG_CMAKE_DIR "\${MLIR_INSTALL_PREFIX}/${MLIR_INSTALL_PACKAGE_DIR}")
|
|
|
|
set(MLIR_CONFIG_LLVM_CMAKE_DIR "\${MLIR_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}")
|
2020-10-02 05:35:28 +08:00
|
|
|
get_config_exports_includes(MLIR MLIR_CONFIG_INCLUDE_EXPORTS)
|
2022-01-18 15:03:10 +08:00
|
|
|
extend_path(base_includedir "\${MLIR_INSTALL_PREFIX}" "${CMAKE_INSTALL_INCLUDEDIR}")
|
2020-01-22 08:44:17 +08:00
|
|
|
set(MLIR_CONFIG_INCLUDE_DIRS
|
2022-01-18 15:03:10 +08:00
|
|
|
"${base_includedir}"
|
2020-01-22 08:44:17 +08:00
|
|
|
)
|
2022-01-10 14:16:58 +08:00
|
|
|
# Ensure that we are using the installed mlir-tblgen. This might not be MLIR_TABLEGEN_EXE
|
|
|
|
# if we're building with a host-optimized mlir-tblgen (with LLVM_OPTIMIZED_TABLEGEN).
|
|
|
|
set(MLIR_CONFIG_TABLEGEN_EXE mlir-tblgen)
|
|
|
|
|
2020-03-12 13:35:58 +08:00
|
|
|
configure_file(
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfig.cmake.in
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfig.cmake
|
|
|
|
@ONLY)
|
2020-01-22 08:44:17 +08:00
|
|
|
set(MLIR_CONFIG_CODE)
|
|
|
|
set(MLIR_CONFIG_CMAKE_DIR)
|
2020-03-12 13:35:58 +08:00
|
|
|
set(MLIR_CONFIG_LLVM_CMAKE_DIR)
|
|
|
|
set(MLIR_CONFIG_INCLUDE_DIRS)
|
2020-01-22 08:44:17 +08:00
|
|
|
|
|
|
|
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
|
|
|
|
# Not TOOLCHAIN ONLY, so install the MLIR parts as well
|
|
|
|
# Include the cmake files so other tools can use mlir-tblgen, etc.
|
2020-10-02 05:35:28 +08:00
|
|
|
install_distribution_exports(MLIR)
|
2020-01-22 08:44:17 +08:00
|
|
|
|
2020-03-12 13:35:58 +08:00
|
|
|
install(FILES
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfig.cmake
|
2020-01-22 08:44:17 +08:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/AddMLIR.cmake
|
2021-04-29 04:04:17 +08:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/AddMLIRPython.cmake
|
2021-04-07 23:21:40 +08:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/MLIRDetectPythonEnv.cmake
|
2020-01-22 08:44:17 +08:00
|
|
|
DESTINATION ${MLIR_INSTALL_PACKAGE_DIR}
|
|
|
|
COMPONENT mlir-cmake-exports)
|
|
|
|
|
|
|
|
if(NOT LLVM_ENABLE_IDE)
|
|
|
|
# Add a dummy target so this can be used with LLVM_DISTRIBUTION_COMPONENTS
|
|
|
|
add_custom_target(mlir-cmake-exports)
|
|
|
|
add_llvm_install_targets(install-mlir-cmake-exports
|
|
|
|
COMPONENT mlir-cmake-exports)
|
|
|
|
endif()
|
|
|
|
endif()
|