summaryrefslogtreecommitdiff
path: root/mlir/cmake
diff options
context:
space:
mode:
authorValentin Churavy <v.churavy@gmail.com>2020-02-08 19:27:54 -0800
committerStephen Neuendorffer <stephen.neuendorffer@xilinx.com>2020-02-28 11:35:19 -0800
commit1246e867164b06fc3f0de6bfaaa0922d99cb5ce9 (patch)
tree8375577381823a02ed6ecba309962c76337a8f44 /mlir/cmake
parent8a2b86b2c20a50f4a32931ae311b8e2457e591eb (diff)
downloadllvm-libc-1246e867164b06fc3f0de6bfaaa0922d99cb5ce9.tar.gz
[MLIR] Add support for libMLIR.so
Putting this up mainly for discussion on how this should be done. I am interested in MLIR from the Julia side and we currently have a strong preference to dynamically linking against the LLVM shared library, and would like to have a MLIR shared library. This patch adds a new cmake function add_mlir_library() which accumulates a list of targets to be compiled into libMLIR.so. Note that not all libraries make sense to be compiled into libMLIR.so. In particular, we want to avoid libraries which primarily exist to support certain tools (such as mlir-opt and mlir-cpu-runner). Note that the resulting libMLIR.so depends on LLVM, but does not contain any LLVM components. As a result, it is necessary to link with libLLVM.so to avoid linkage errors. So, libMLIR.so requires LLVM_BUILD_LLVM_DYLIB=on FYI, Currently it appears that LLVM_LINK_LLVM_DYLIB is broken because mlir-tblgen is linked against libLLVM.so and and independent LLVM components (updated by Stephen Neuendorffer) Differential Revision: https://reviews.llvm.org/D73130
Diffstat (limited to 'mlir/cmake')
-rw-r--r--mlir/cmake/modules/AddMLIR.cmake31
1 files changed, 29 insertions, 2 deletions
diff --git a/mlir/cmake/modules/AddMLIR.cmake b/mlir/cmake/modules/AddMLIR.cmake
index d8944532c6ff..cd7860ca2fe3 100644
--- a/mlir/cmake/modules/AddMLIR.cmake
+++ b/mlir/cmake/modules/AddMLIR.cmake
@@ -49,14 +49,41 @@ function(add_mlir_dialect dialect dialect_doc_filename)
add_dependencies(mlir-doc ${dialect_doc_filename}DocGen)
endfunction()
+# Declare a library which can be compiled in libMLIR.so
+macro(add_mlir_library name)
+ cmake_parse_arguments(ARG
+ "SHARED;INSTALL_WITH_TOOLCHAIN"
+ ""
+ "ADDITIONAL_HEADERS"
+ ${ARGN})
+ set(srcs)
+ if(ARG_SHARED)
+ set(LIBTYPE SHARED)
+ else()
+ # llvm_add_library ignores BUILD_SHARED_LIBS if STATIC is explicitly set,
+ # so we need to handle it here.
+ if(BUILD_SHARED_LIBS)
+ set(LIBTYPE SHARED)
+ else()
+ set(LIBTYPE STATIC)
+ endif()
+ if(NOT XCODE)
+ # The Xcode generator doesn't handle object libraries correctly.
+ list(APPEND LIBTYPE OBJECT)
+ endif()
+ set_property(GLOBAL APPEND PROPERTY MLIR_ALL_LIBS ${name})
+ endif()
+ add_llvm_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
+endmacro(add_mlir_library)
+
# Declare the library associated with a dialect.
function(add_mlir_dialect_library name)
set_property(GLOBAL APPEND PROPERTY MLIR_DIALECT_LIBS ${name})
- add_llvm_library(${ARGV})
+ add_mlir_library(${ARGV})
endfunction(add_mlir_dialect_library)
# Declare the library associated with a conversion.
function(add_mlir_conversion_library name)
set_property(GLOBAL APPEND PROPERTY MLIR_CONVERSION_LIBS ${name})
- add_llvm_library(${ARGV})
+ add_mlir_library(${ARGV})
endfunction(add_mlir_conversion_library)