Reland [libclang] Install both libclang.a and libclang.so when…

Authored by zhuhan0 on Wed, May 6, 7:31 PM.


Reland [libclang] Install both libclang.a and libclang.so when LIBCLANG_BUILD_STATIC=ON

f8990feb125a enabled installing PIC version of both libclang.a and
libclang.so when LIBCLANG_BUILD_STATIC is ON. But it broke the no-PIC
build when LLVM_ENABLE_PIC=OFF with the following error:

CMake Error at
    target_compile_definitions called with non-compilable target type

This is because as the code loops through ${name} and ${name}_static, it
introduced a side effect, which is adding an empty libclang_static to
targets. Later target_compile_definitions is called on libclang_static.
That function requires that target must have been created by a command
such as add_executable() or add_library(), so it crashed.

The solution is to not naively loop through both libclang and
libclang_static, but only the ones that are actually added by
llvm_add_library(). Here's the library build type to library target name

SHARED onlylibclang
STATIC onlylibclang
SHARED and STATIClibclang and libclang_static

So only when SHARED and STATIC are both set should we loop through two
targets. Explicitly parse the STATIC argument and set the list

Reviewed By: smeenai

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