This review proposes a fix for bug 28127 https://llvm.org/bugs/show_bug.cgi?id=28127.
LLDB maintainers require lldb-server to be built statically, so it can be quickly copied to a remote target for debugging without having to deal with dependency problems.
When LLVM is built using -DLLVM_LINK_LLVM_DYLIB=ON -DLLVM_BUILD_LLVM_DYLIB=ON, lldb-server breaks because a CommandLine option is registered twice.
Those are the options used when building LLVM's debian packages.
To achieve a static executable, lldb-server is linked only against .a libraries such as the LLVM .a individual components and the clang .a static libraries.
The problem is that when using -DLLVM_LINK_LLVM_DYLIB=ON -DLLVM_BUILD_LLVM_DYLIB=ON, clang .a static libraries introduce a cmake transitive dependency with target_link_libraries to a single libLLVM.so dynamic library which contains all the llvm components symbols.
This results in symbols defined twice in lldb-server: through the static .a llvm components and transitively through the .a clang libraries which require libLLVM.so.
This patch resolves the issue by ensuring that when static .a libraries are build they only introduce cmake transitive dependencies to other .a components.
Because Polly uses its own macros for adding libraries dependencies and does not go through the llvm_add_library_name, this patch also changes Polly build process.
The patch has been tested on the debian snapshot package of LLVM and fixes the issue.
I add Pavel, Brad and Sylvestre as initial reviewers since they have been involved in the discussion and fix. Tobias could you please have a look at the Polly part of the fix ? I'm not sure who should review the changes to AddLLVM.cmake.
Thanks,