llvm-project/clang/cmake/modules
Han Zhu 0c9230dad1 Reland [libclang] Install both libclang.a and libclang.so when LIBCLANG_BUILD_STATIC=ON
f8990feb12 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
/b/s/w/ir/cache/builder/src/third_party/llvm/clang/tools/libclang/CMakeLists.txt:123
(target_compile_definitions):
    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
mapping:

| SHARED only | libclang |
| STATIC only | libclang |
| SHARED and STATIC | libclang 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
accordingly.

Reviewed By: smeenai

Differential Revision: https://reviews.llvm.org/D79059
2020-05-06 19:33:58 -07:00
..
AddClang.cmake Reland [libclang] Install both libclang.a and libclang.so when LIBCLANG_BUILD_STATIC=ON 2020-05-06 19:33:58 -07:00
CMakeLists.txt [clang] Add CMake target for installing clang's CMake exports 2019-02-20 23:16:15 +00:00
ClangConfig.cmake.in [CMake] NFC. Add clang-tablegen-targets utility target 2017-07-28 15:33:47 +00:00
ProtobufMutator.cmake [clang-fuzzer] Include ExternalProject before using it. 2019-04-05 19:47:17 +00:00