brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.7 KiB · 47349f0 Raw
152 lines · plain
1# This file configures the CMake package configuration file "MLIRConfig.cmake"2# (see https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html).3# Two different versions of the package config file are generated and copied4# into different locations:5# 1. One in a canonical location in the build directory,6#   '<build>/lib/cmake/mlir/MLIRConfig.cmake'. This version may use absolute7#    paths referring to locations in the build tree.8# 2. One under '${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles', which is the version9#    *to be installed* when `cmake --install` command is run or when CPack10#    is invoked. This is the version that is distributed with LLVM packages.11#    The key difference between this and (1) is that all paths must be12#    relative the the installed "MLIRConfig.cmake" file.13 14include(GNUInstallPackageDir)15include(ExtendPath)16include(LLVMDistributionSupport)17include(FindPrefixFromConfig)18 19# This is a relative path to the location of MLIRConfig.cmake within the20# installation.21set(MLIR_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/mlir" CACHE STRING22  "Path for CMake subdirectory for MLIR (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/mlir')")23 24# Keep this in sync with llvm/cmake/CMakeLists.txt!25set(LLVM_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/llvm" CACHE STRING26  "Path for CMake subdirectory for LLVM (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/llvm')")27string(REPLACE "${CMAKE_CFG_INTDIR}" "." llvm_cmake_builddir "${LLVM_LIBRARY_DIR}")28 29# These two variables contain absolute paths, so only use them for the30# build directory 'MLIRConfig.cmake'.31set(mlir_cmake_builddir "${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/mlir")32set(llvm_cmake_builddir "${llvm_cmake_builddir}/cmake/llvm")33 34# -----------------------------------------------------------------------------35# Generate `<build>/lib/cmake/mlir/MLIRConfig.cmake'36# -----------------------------------------------------------------------------37 38# Generate the 'MLIRTarget.cmake' file.39get_property(MLIR_EXPORTS GLOBAL PROPERTY MLIR_EXPORTS)40export(TARGETS ${MLIR_EXPORTS} FILE ${mlir_cmake_builddir}/MLIRTargets.cmake)41 42# Declare all the variables required by the 'MLIRConfig.cmake.in' template.43get_property(MLIR_ALL_LIBS GLOBAL PROPERTY MLIR_ALL_LIBS)44get_property(MLIR_DIALECT_LIBS GLOBAL PROPERTY MLIR_DIALECT_LIBS)45get_property(MLIR_CONVERSION_LIBS GLOBAL PROPERTY MLIR_CONVERSION_LIBS)46get_property(MLIR_EXTENSION_LIBS GLOBAL PROPERTY MLIR_EXTENSION_LIBS)47get_property(MLIR_TRANSLATION_LIBS GLOBAL PROPERTY MLIR_TRANSLATION_LIBS)48get_property(MLIR_CAPI_LIBS GLOBAL PROPERTY MLIR_CAPI_LIBS)49 50# Generate MlirConfig.cmake for the build tree.51set(MLIR_CONFIG_CMAKE_DIR "${mlir_cmake_builddir}")52set(MLIR_CONFIG_LLVM_CMAKE_DIR "${llvm_cmake_builddir}")53set(MLIR_CONFIG_INCLUDE_EXPORTS "include(\"\${MLIR_CMAKE_DIR}/MLIRTargets.cmake\")")54set(MLIR_CONFIG_INCLUDE_DIRS55  "${MLIR_SOURCE_DIR}/include"56  "${MLIR_BINARY_DIR}/include"57  )58# Refer to the best host mlir-tblgen, which might be a host-optimized version59set(MLIR_CONFIG_TABLEGEN_EXE "${MLIR_TABLEGEN_EXE}")60set(MLIR_CONFIG_PDLL_TABLEGEN_EXE "${MLIR_PDLL_TABLEGEN_EXE}")61set(MLIR_CONFIG_SRC_SHARDER_TABLEGEN_EXE "${MLIR_SRC_SHARDER_TABLEGEN_EXE}")62 63configure_file(64  ${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfig.cmake.in65  ${mlir_cmake_builddir}/MLIRConfig.cmake66  @ONLY)67configure_file(68  ${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfigVersion.cmake.in69  ${mlir_cmake_builddir}/MLIRConfigVersion.cmake70  @ONLY)71 72# Reset the variables which are invalid for the installed version of73# MLIRConfig.cmake.74set(MLIR_CONFIG_CMAKE_DIR)75set(MLIR_CONFIG_LLVM_CMAKE_DIR)76set(MLIR_CONFIG_INCLUDE_DIRS)77 78# For compatibility with projects that add '<build>/lib/cmake/mlir' to79# their CMAKE_MODULE_PATH, place API modules next to it.80# Copy without source permissions because the source could be read-only,81# but we need to write into the copied folder.82file(COPY .83  DESTINATION ${mlir_cmake_builddir}84  NO_SOURCE_PERMISSIONS85  FILES_MATCHING PATTERN *.cmake86  PATTERN CMakeFiles EXCLUDE87  )88 89# -----------------------------------------------------------------------------90# Generate MLIRConfig.cmake for the install tree.91# All path variables used in the template must be relative!92# -----------------------------------------------------------------------------93 94# This is a helper that sets 'MLIR_CONFIG_CODE' to some CMake code for95# insertion at the top of the generated 'MLIRConfig.cmake'. The code calculates96# the install directory prefix relative to the installed MLIRConfig.cmake (whose97# prefix is MLIR_INSTALL_PACKAGE_DIR), avoiding any use of absolute paths.98find_prefix_from_config(MLIR_CONFIG_CODE MLIR_INSTALL_PREFIX "${MLIR_INSTALL_PACKAGE_DIR}")99 100# Generate the other required paths by setting them relative to the101# variable 'MLIR_INSTALL_PREFIX'.102extend_path(MLIR_CONFIG_CMAKE_DIR "\${MLIR_INSTALL_PREFIX}" "${MLIR_INSTALL_PACKAGE_DIR}")103extend_path(MLIR_CONFIG_LLVM_CMAKE_DIR "\${MLIR_INSTALL_PREFIX}" "${LLVM_INSTALL_PACKAGE_DIR}")104get_config_exports_includes(MLIR MLIR_CONFIG_INCLUDE_EXPORTS)105extend_path(base_includedir "\${MLIR_INSTALL_PREFIX}" "${CMAKE_INSTALL_INCLUDEDIR}")106set(MLIR_CONFIG_INCLUDE_DIRS107  "${base_includedir}"108  )109# Ensure that we are using the installed mlir-tblgen. This might not be MLIR_TABLEGEN_EXE110# if we're building with a host-optimized mlir-tblgen (with LLVM_OPTIMIZED_TABLEGEN).111set(MLIR_CONFIG_TABLEGEN_EXE mlir-tblgen)112set(MLIR_CONFIG_PDLL_TABLEGEN_EXE mlir-pdll)113set(MLIR_CONFIG_SRC_SHARDER_TABLEGEN_EXE mlir-src-sharder)114 115set(MLIR_CONFIG_IRDL_TO_CPP_EXE mlir-irdl-to-cpp)116 117configure_file(118  ${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfig.cmake.in119  ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfig.cmake120  @ONLY)121configure_file(122  ${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfigVersion.cmake.in123  ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfigVersion.cmake124  @ONLY)125set(MLIR_CONFIG_CODE)126set(MLIR_CONFIG_CMAKE_DIR)127set(MLIR_CONFIG_LLVM_CMAKE_DIR)128set(MLIR_CONFIG_INCLUDE_DIRS)129 130if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)131  # Not TOOLCHAIN ONLY, so install the MLIR parts as well132  # Include the cmake files so other tools can use mlir-tblgen, etc.133  install_distribution_exports(MLIR)134 135  install(FILES136    ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfig.cmake137    ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/MLIRConfigVersion.cmake138    ${CMAKE_CURRENT_SOURCE_DIR}/AddMLIR.cmake139    ${CMAKE_CURRENT_SOURCE_DIR}/AddMLIRPython.cmake140    ${CMAKE_CURRENT_SOURCE_DIR}/IRDLToCpp.cmake141    ${CMAKE_CURRENT_SOURCE_DIR}/MLIRDetectPythonEnv.cmake142    DESTINATION ${MLIR_INSTALL_PACKAGE_DIR}143    COMPONENT mlir-cmake-exports)144 145  if(NOT LLVM_ENABLE_IDE)146    # Add a dummy target so this can be used with LLVM_DISTRIBUTION_COMPONENTS147    add_custom_target(mlir-cmake-exports)148    add_llvm_install_targets(install-mlir-cmake-exports149                             COMPONENT mlir-cmake-exports)150  endif()151endif()152