[mlir][sparse] Fix breakage on older versions of cmake
authorwren romano <2998727+wrengr@users.noreply.github.com>
Wed, 19 Oct 2022 20:37:17 +0000 (13:37 -0700)
committerwren romano <2998727+wrengr@users.noreply.github.com>
Wed, 19 Oct 2022 20:55:54 +0000 (13:55 -0700)
Per https://reviews.llvm.org/D136005#3866692 the introduction of the MLIRSparseTensorEnums target in D136002 caused breakage on some versions of cmake.  This differential aims to fix those errors.

Reviewed By: aartbik

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

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

index 14511f5..019b5d0 100644 (file)
@@ -9,13 +9,31 @@
 # `INTERFACE` libraries.
 set(MLIRSparseTensorEnums_srcs
     ${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/SparseTensor/IR/Enums.h)
-add_library(MLIRSparseTensorEnums INTERFACE ${MLIRSparseTensorEnums_srcs})
+# This conditional is copypasta from `add_mlir_library`.
 if(MSVC_IDE OR XCODE)
   set_source_files_properties(${MLIRSparseTensorEnums_srcs}
     PROPERTIES HEADER_FILE_ONLY ON)
 endif()
-add_mlir_library_install(MLIRSparseTensorEnums)
-set_property(TARGET MLIRSparseTensorEnums PROPERTY CXX_STANDARD 17)
+# 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 ${MLIRSparseTensorEnums_srcs})
+# 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
+# in `add_mlir_library` is to prevent `add_mlir_library_install` from
+# raising additional errors whenever the underlying call to `add_llvm_library`
+# fails.  However, since we are using `add_library` directly, I'm not
+# sure if the conditional is helpful/required here or not.
+if(TARGET MLIRSparseTensorEnums)
+  add_mlir_library_install(MLIRSparseTensorEnums)
+else()
+  # Add empty "phony" target
+  add_custom_target(MLIRSparseTensorEnums)
+endif()
+# Older versions of cmake (i.e., 3.18.0 but not 3.24.2) disallow setting
+# the CXX_STANDARD property for INTERFACE libraries.  However, this library
+# must adhere to the same CXX_STANDARD restriction as mlir_c_runner_utils.
 
 
 add_mlir_dialect_library(MLIRSparseTensorDialect