[mlir] Avoid building some shared libraries when PIC is off
authorHan Zhu <zhuhan7737@gmail.com>
Mon, 30 Jan 2023 23:45:47 +0000 (15:45 -0800)
committerHan Zhu <zhuhan7737@gmail.com>
Mon, 13 Feb 2023 18:12:57 +0000 (10:12 -0800)
commit8e628f72b00cd6d8224b1d2aee3266ee49f50973
treec3f4a65e207353a9acb32d3962724d7f34cf2233
parentbf7c421617007d7202dcd74762cef3a49425bfab
[mlir] Avoid building some shared libraries when PIC is off

When `LLVM_ENABLE_PIC = OFF`, shared libraries cannot be built against code
that's compiled without -fPIC. Example error message:
``
ld.lld: error: relocation R_X86_64_32 cannot be used against local symbol;
recompile with -fPIC
>>> defined in lib/libLLVMSupport.a(StringMap.cpp.o)
>>> referenced by StringMap.cpp
>>>               StringMap.cpp.o:(llvm::StringMapImpl::StringMapImpl(unsigned
>>>               int, unsigned int)) in archive lib/libLLVMSupport.a
``
Similar to [how libclang handles
this](https://github.com/llvm/llvm-project/blob/main/clang/tools/clang-shlib/CMakeLists.txt#L2-L4),
skip building these shared libraries when `LLVM_ENABLE_PIC = OFF`.

Differential Revision: https://reviews.llvm.org/D142941
mlir/lib/ExecutionEngine/CMakeLists.txt
mlir/test/CMakeLists.txt