[Mlir-commits] [mlir] d8cb5d3 - [mlir][sparse] Refining the IR/CMakeLists.txt (followup to D136477)

wren romano llvmlistbot at llvm.org
Fri Oct 21 15:23:58 PDT 2022


Author: wren romano
Date: 2022-10-21T15:23:50-07:00
New Revision: d8cb5d3c6e1883166d8d2a8dbb4b497a8fd37f4a

URL: https://github.com/llvm/llvm-project/commit/d8cb5d3c6e1883166d8d2a8dbb4b497a8fd37f4a
DIFF: https://github.com/llvm/llvm-project/commit/d8cb5d3c6e1883166d8d2a8dbb4b497a8fd37f4a.diff

LOG: [mlir][sparse] Refining the IR/CMakeLists.txt (followup to D136477)

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D136506

Added: 
    

Modified: 
    mlir/lib/Dialect/SparseTensor/IR/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/SparseTensor/IR/CMakeLists.txt b/mlir/lib/Dialect/SparseTensor/IR/CMakeLists.txt
index feb227390a9d..fb1bc6e1561c 100644
--- a/mlir/lib/Dialect/SparseTensor/IR/CMakeLists.txt
+++ b/mlir/lib/Dialect/SparseTensor/IR/CMakeLists.txt
@@ -7,19 +7,31 @@
 # relevant portions below.  If doing so becomes too complicated, then
 # we should adjust the `add_mlir_library` function to also work for
 # `INTERFACE` libraries.
-set(MLIRSparseTensorEnums_srcs
-    ${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/SparseTensor/IR/Enums.h)
+set(MLIRSparseTensorEnums_hdrs
+    mlir/Dialect/SparseTensor/IR/Enums.h)
 # This conditional is copypasta from `add_mlir_library`.
 if(MSVC_IDE OR XCODE)
-  set_source_files_properties(${MLIRSparseTensorEnums_srcs}
-    PROPERTIES HEADER_FILE_ONLY ON)
+  foreach(hdr ${MLIRSparseTensorEnums_hdrs})
+    set_source_files_properties(${MLIR_MAIN_INCLUDE_DIR}/${hdr}
+      PROPERTIES HEADER_FILE_ONLY ON)
+  endforeach()
 endif()
 # Older versions of cmake (< 3.19) require INTERFACE libraries to separate
 # the `add_library` and `target_sources` calls.
 add_library(MLIRSparseTensorEnums INTERFACE)
-target_sources(MLIRSparseTensorEnums INTERFACE
-	$<BUILD_INTERFACE:${MLIRSparseTensorEnums_srcs}>
-	$<INSTALL_INTERFACE:mlir/Dialect/SparseTensor/IR/Enums.h>)
+# If we call target_sources naively, then the library won't be
+# installed properly (i.e., so that it can be used by projects outside
+# the llvm-project repo).  To correct this, we must use BUILD_INTERFACE /
+# INSTALL_INTERFACE generator expressions to avoid paths being interpreted
+# as absolute; for more details, see <https://stackoverflow.com/a/62465051>.
+# Unfortunately BUILD_INTERFACE and INSTALL_INTERFACE require their file
+# paths to be relative to 
diff erent things, hence why we use a foreach loop
+# to iterate over the sources (in case we ever need to have more than one).
+foreach(hdr ${MLIRSparseTensorEnums_hdrs})
+  target_sources(MLIRSparseTensorEnums INTERFACE
+    $<BUILD_INTERFACE:${MLIR_MAIN_INCLUDE_DIR}/${hdr}>
+    $<INSTALL_INTERFACE:${hdr}>)
+endforeach()
 # The `add_mlir_library_install` is required for other libraries to
 # depend on this one, but the conditional itself and the phony target
 # are copypasta from `add_mlir_library`.  Afaict (wrengr), the version


        


More information about the Mlir-commits mailing list