Index: cmake/modules/AddLLVM.cmake =================================================================== --- cmake/modules/AddLLVM.cmake +++ cmake/modules/AddLLVM.cmake @@ -475,13 +475,15 @@ # property has been set to an empty value. get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${name}) - if (LLVM_LINK_LLVM_DYLIB AND NOT ARG_STATIC AND NOT ARG_DISABLE_LLVM_LINK_LLVM_DYLIB) - set(llvm_libs LLVM) - else() - llvm_map_components_to_libnames(llvm_libs - ${ARG_LINK_COMPONENTS} - ${LLVM_LINK_COMPONENTS} - ) + if (DEFINED LLVM_LINK_COMPONENTS OR DEFINED ARG_LINK_COMPONENTS) + if (LLVM_LINK_LLVM_DYLIB AND NOT ARG_DISABLE_LLVM_LINK_LLVM_DYLIB) + set(llvm_libs LLVM) + else() + llvm_map_components_to_libnames(llvm_libs + ${ARG_LINK_COMPONENTS} + ${LLVM_LINK_COMPONENTS} + ) + endif() endif() if(CMAKE_VERSION VERSION_LESS 2.8.12) @@ -886,10 +888,9 @@ set(outdir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}) set_output_directory(${test_name} BINARY_DIR ${outdir} LIBRARY_DIR ${outdir}) target_link_libraries(${test_name} - gtest - gtest_main - LLVMSupport # gtest needs it for raw_ostream. - ) + gtest + gtest_main + ) add_dependencies(${test_suite} ${test_name}) get_target_property(test_suite_folder ${test_suite} FOLDER) Index: cmake/modules/LLVM-Config.cmake =================================================================== --- cmake/modules/LLVM-Config.cmake +++ cmake/modules/LLVM-Config.cmake @@ -40,10 +40,17 @@ # done in case libLLVM does not contain all of the components # the target requires. # - # TODO strip LLVM_DYLIB_COMPONENTS out of link_components. + # Strip LLVM_DYLIB_COMPONENTS out of link_components. # To do this, we need special handling for "all", since that # may imply linking to libraries that are not included in # libLLVM. + if (DEFINED link_components AND DEFINED LLVM_DYLIB_COMPONENTS) + if("${LLVM_DYLIB_COMPONENTS}" STREQUAL "all") + set(link_components "") + else() + list(REMOVE_ITEM link_components ${LLVM_DYLIB_COMPONENTS}) + endif() + endif() target_link_libraries(${executable} LLVM) endif() Index: unittests/DebugInfo/DWARF/CMakeLists.txt =================================================================== --- unittests/DebugInfo/DWARF/CMakeLists.txt +++ unittests/DebugInfo/DWARF/CMakeLists.txt @@ -1,5 +1,6 @@ set(LLVM_LINK_COMPONENTS DebugInfoDWARF + Support ) set(DebugInfoSources Index: unittests/DebugInfo/PDB/CMakeLists.txt =================================================================== --- unittests/DebugInfo/PDB/CMakeLists.txt +++ unittests/DebugInfo/PDB/CMakeLists.txt @@ -1,5 +1,6 @@ set(LLVM_LINK_COMPONENTS DebugInfoPDB + Support ) set(DebugInfoPDBSources Index: unittests/Linker/CMakeLists.txt =================================================================== --- unittests/Linker/CMakeLists.txt +++ unittests/Linker/CMakeLists.txt @@ -2,6 +2,7 @@ AsmParser core linker + Support ) set(LinkerSources Index: utils/FileCheck/CMakeLists.txt =================================================================== --- utils/FileCheck/CMakeLists.txt +++ utils/FileCheck/CMakeLists.txt @@ -2,4 +2,5 @@ FileCheck.cpp ) -target_link_libraries(FileCheck LLVMSupport) +set(LLVM_LINK_COMPONENTS Support) +target_link_libraries(FileCheck) Index: utils/KillTheDoctor/CMakeLists.txt =================================================================== --- utils/KillTheDoctor/CMakeLists.txt +++ utils/KillTheDoctor/CMakeLists.txt @@ -2,4 +2,5 @@ KillTheDoctor.cpp ) -target_link_libraries(KillTheDoctor LLVMSupport) +set(LLVM_LINK_COMPONENTS Support) +target_link_libraries(KillTheDoctor) Index: utils/not/CMakeLists.txt =================================================================== --- utils/not/CMakeLists.txt +++ utils/not/CMakeLists.txt @@ -2,4 +2,5 @@ not.cpp ) -target_link_libraries(not LLVMSupport) +set(LLVM_LINK_COMPONENTS Support) +target_link_libraries(not) Index: utils/unittest/CMakeLists.txt =================================================================== --- utils/unittest/CMakeLists.txt +++ utils/unittest/CMakeLists.txt @@ -32,10 +32,6 @@ add_definitions( -DGTEST_HAS_PTHREAD=0 ) endif() -set(LIBS - LLVMSupport # Depends on llvm::raw_ostream -) - find_library(PTHREAD_LIBRARY_PATH pthread) if (PTHREAD_LIBRARY_PATH) list(APPEND LIBS pthread) Index: utils/unittest/UnitTestMain/CMakeLists.txt =================================================================== --- utils/unittest/UnitTestMain/CMakeLists.txt +++ utils/unittest/UnitTestMain/CMakeLists.txt @@ -3,5 +3,4 @@ LINK_LIBS gtest - LLVMSupport # Depends on llvm::cl - ) + ) Index: utils/yaml-bench/CMakeLists.txt =================================================================== --- utils/yaml-bench/CMakeLists.txt +++ utils/yaml-bench/CMakeLists.txt @@ -2,4 +2,5 @@ YAMLBench.cpp ) -target_link_libraries(yaml-bench LLVMSupport) +set(LLVM_LINK_COMPONENTS Support) +target_link_libraries(yaml-bench)