-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir] NFC: fix typos and improve commentary regarding generation of MLIRConfig.cmake #127712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-mlir Author: Christopher Bate (christopherbate) ChangesFull diff: https://github.com/llvm/llvm-project/pull/127712.diff 1 Files Affected:
diff --git a/mlir/cmake/modules/CMakeLists.txt b/mlir/cmake/modules/CMakeLists.txt
index 3ac1c79b090ed..e3fdab6748f46 100644
--- a/mlir/cmake/modules/CMakeLists.txt
+++ b/mlir/cmake/modules/CMakeLists.txt
@@ -1,26 +1,45 @@
+# This file configures the CMake package configuration file "MLIRConfig.cmake"
+# (see https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html).
+# Two different versions of the package config file are generated and copied
+# into different locations:
+# 1. One in a canonical location in the build directory,
+# '<build>/lib/cmake/mlir/MLIRConfig.cmake'. This version may use absolute
+# paths referring to locations in the build tree.
+# 2. One under '${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles', which is the version
+# *to be installed* when `cmake --install` command is run or when CPack
+# is invoked. This is the version that is distributed with LLVM packages.
+# The key difference between this and (1) is that all paths must be
+# relative the the instlaled "MLIRConfig.cmake" file.
+
include(GNUInstallPackageDir)
include(ExtendPath)
include(LLVMDistributionSupport)
include(FindPrefixFromConfig)
-# 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.
+# This is a relative path to the location of MLIConfig.cmake within the
+# installation.
set(MLIR_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/mlir" CACHE STRING
- "Path for CMake subdirectory for Polly (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/polly')")
-# CMAKE_INSTALL_PACKAGEDIR might be absolute, so don't reuse below.
-set(mlir_cmake_builddir "${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/mlir")
+ "Path for CMake subdirectory for MLIR (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/mlir')")
# Keep this in sync with llvm/cmake/CMakeLists.txt!
set(LLVM_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/llvm" CACHE STRING
"Path for CMake subdirectory for LLVM (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/llvm')")
-# CMAKE_INSTALL_PACKAGEDIR might be absolute, so don't reuse below.
string(REPLACE "${CMAKE_CFG_INTDIR}" "." llvm_cmake_builddir "${LLVM_LIBRARY_DIR}")
+
+# These two variables contain absolute paths, so only use them for the
+# build directory 'MLIRConfig.cmake'.
+set(mlir_cmake_builddir "${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/mlir")
set(llvm_cmake_builddir "${llvm_cmake_builddir}/cmake/llvm")
+# -----------------------------------------------------------------------------
+# Generate `<build>/lib/cmake/mlir/MLIRConfig.cmake'
+# -----------------------------------------------------------------------------
+
+# Generate the 'MLIRTarget.cmake' file.
get_property(MLIR_EXPORTS GLOBAL PROPERTY MLIR_EXPORTS)
export(TARGETS ${MLIR_EXPORTS} FILE ${mlir_cmake_builddir}/MLIRTargets.cmake)
+# Declare all the variables required by the 'MLIRConfig.cmake.in' template.
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)
@@ -49,15 +68,17 @@ configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/MLIRConfigVersion.cmake.in
${mlir_cmake_builddir}/MLIRConfigVersion.cmake
@ONLY)
+
+# Reset the variables which are invalid for the installed version of
+# MLIRConfig.cmake.
set(MLIR_CONFIG_CMAKE_DIR)
set(MLIR_CONFIG_LLVM_CMAKE_DIR)
set(MLIR_CONFIG_INCLUDE_DIRS)
-# For compatibility with projects that include(MLIRConfig)
-# via CMAKE_MODULE_PATH, place API modules next to it.
+# For compatibility with projects that add '<build>/lib/cmake/mlir' to
+# their CMAKE_MODULE_PATH, place API modules next to it.
# Copy without source permissions because the source could be read-only,
# but we need to write into the copied folder.
-# This should be removed in the future.
file(COPY .
DESTINATION ${mlir_cmake_builddir}
NO_SOURCE_PERMISSIONS
@@ -65,8 +86,19 @@ file(COPY .
PATTERN CMakeFiles EXCLUDE
)
+# -----------------------------------------------------------------------------
# Generate MLIRConfig.cmake for the install tree.
+# All path variables used in the template must be relative!
+# -----------------------------------------------------------------------------
+
+# This is a helper that sets 'MLIR_CONFIG_CODE' to some CMake code for
+# insertion at the top of the generated 'MLIRConfig.cmake'. The code calculates
+# the install directory prefix relative to the installed MLIRConfig.cmake (whose
+# prefix is MLIR_INSTALL_PACKAGE_DIR), avoiding any use of absolute paths.
find_prefix_from_config(MLIR_CONFIG_CODE MLIR_INSTALL_PREFIX "${MLIR_INSTALL_PACKAGE_DIR}")
+
+# Generate the other required paths by setting them relative to the
+# variable 'MLIR_INSTALL_PREFIX'.
extend_path(MLIR_CONFIG_CMAKE_DIR "\${MLIR_INSTALL_PREFIX}" "${MLIR_INSTALL_PACKAGE_DIR}")
extend_path(MLIR_CONFIG_LLVM_CMAKE_DIR "\${MLIR_INSTALL_PREFIX}" "${LLVM_INSTALL_PACKAGE_DIR}")
get_config_exports_includes(MLIR MLIR_CONFIG_INCLUDE_EXPORTS)
|
joker-eph
approved these changes
Feb 19, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.