Current trunk suffers several thousand llvm test suite failures for the LLVM_LINK_LLVM_DYLIB build due to incorrect linkages of both libLLVM and the individual LLVM component static libraries. The proposed changes to the llvm_config() macro in cmake/modules/LLVM-Config.cmake and the llvm_add_library() function in cmake/modules/AddLLVM.cmake solves this issue by stripping the individual LLVM component libraries from LLVM_LINK_COMPONENTS and LINK_COMPONENTS for the LLVM_LINK_LLVM_DYLIB build. To address the remaining instances where the unittests executables are incorrectly linked against both libLLVM and libLLVMSupport in the LLVM_LINK_LLVM_DYLIB build, the explicit linkage of LLVMSupport is removed from utils/unittest/CMakeLists.txt. However, the explicit linkage on LLVMSupport in the llvm_add_library name function of cmake/modules/AddLLVM.cmake and utils/unittest/UnitTestMain/CMakeLists.txt are retained and conditionalized on LLVM_LINK_LLVM_DYLIB. These are required to prevent the BUILD_SHARED_LIBS build from missing required the LLVMSupport linkages on unittests executables. Finally a new --enable-llvm-link-llvm-dylib is introduced in utils/llvm-build/llvmbuild/main.py and utilized in the top-level CMakeLists.txt file for the LLVM_LINK_LLVM_DYLIB build. In utils/llvm-build/llvmbuild/main.py, this new option sets a use_llvm_link_llvm_dylib global which is then tested in the write_library_table routine to control pruning 'Support' from the required dependencies of the gtest library. This produces the desired result for the DLLVM_LINK_LLVM_DYLIB build of the producing a tools/llvm-config/LibraryDependencies.inc file containing...
{ "gtest", "libgtest.a", false, { } },
instead of
{ "gtest", "libgtest.a", false, { "support" } },
The command...
find . -name link.txt -print0 | xargs -0 cat | grep libgtest | grep -v -c libLLVMSupport
was used to verify that none of the linkages on libgtest were missing the required linkages of libLLVMSupport for the stock and BUILD_SHARED_LIBS builds.
find . -name link.txt -print0 | xargs -0 cat | grep libgtest | grep libLLVM | grep -c libLLVMSupport
was used to verify that none of the unitests linkages on the LLVM_LINK_LLVM_DYLIB build had both libLLVM.dylib and libLLVMSupport.
Confirmed bootstraps on x86_64 darwin for the stock (static), BUILD_SHARED_LIBS and LLVM_LINK_LLVM_DYLIB builds of current trunk with this patch.