Index: cmake/modules/AddLLVM.cmake =================================================================== --- cmake/modules/AddLLVM.cmake +++ cmake/modules/AddLLVM.cmake @@ -473,17 +473,23 @@ # It would be nice to verify that we have the dependencies for this library # name, but using get_property(... SET) doesn't suffice to determine if a # 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) + if (LLVM_LINK_LLVM_DYLIB AND ${name} STREQUAL gtest) + set_property(GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_gtest LLVM) else() - llvm_map_components_to_libnames(llvm_libs - ${ARG_LINK_COMPONENTS} - ${LLVM_LINK_COMPONENTS} - ) + get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${name}) endif() + 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) # Link libs w/o keywords, assuming PUBLIC. target_link_libraries(${name} @@ -885,11 +891,18 @@ add_llvm_executable(${test_name} IGNORE_EXTERNALIZE_DEBUGINFO ${ARGN}) set(outdir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}) set_output_directory(${test_name} BINARY_DIR ${outdir} LIBRARY_DIR ${outdir}) + if (LLVM_LINK_LLVM_DYLIB) + target_link_libraries(${test_name} + gtest + gtest_main + ) + else() target_link_libraries(${test_name} - gtest - gtest_main - LLVMSupport # gtest needs it for raw_ostream. - ) + gtest + gtest_main + LLVMSupport # Depends on llvm::cl + ) + endif() 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: utils/FileCheck/CMakeLists.txt =================================================================== --- utils/FileCheck/CMakeLists.txt +++ utils/FileCheck/CMakeLists.txt @@ -2,4 +2,8 @@ FileCheck.cpp ) -target_link_libraries(FileCheck LLVMSupport) +if (LLVM_LINK_LLVM_DYLIB) + target_link_libraries(FileCheck LLVM) +else() + target_link_libraries(FileCheck LLVMSupport) +endif() Index: utils/KillTheDoctor/CMakeLists.txt =================================================================== --- utils/KillTheDoctor/CMakeLists.txt +++ utils/KillTheDoctor/CMakeLists.txt @@ -2,4 +2,8 @@ KillTheDoctor.cpp ) -target_link_libraries(KillTheDoctor LLVMSupport) +if (LLVM_LINK_LLVM_DYLIB) + target_link_libraries(KillTheDoctor LLVM) +else() + target_link_libraries(KillTheDoctor LLVMSupport) +endif() Index: utils/not/CMakeLists.txt =================================================================== --- utils/not/CMakeLists.txt +++ utils/not/CMakeLists.txt @@ -2,4 +2,8 @@ not.cpp ) -target_link_libraries(not LLVMSupport) +if (LLVM_LINK_LLVM_DYLIB) + target_link_libraries(not LLVM) +else() + target_link_libraries(not LLVMSupport) +endif() Index: utils/unittest/CMakeLists.txt =================================================================== --- utils/unittest/CMakeLists.txt +++ utils/unittest/CMakeLists.txt @@ -32,9 +32,15 @@ add_definitions( -DGTEST_HAS_PTHREAD=0 ) endif() -set(LIBS - LLVMSupport # Depends on llvm::raw_ostream -) +if (LLVM_LINK_LLVM_DYLIB) + set(LIBS + LLVM # Depends on llvm::raw_ostream + ) +else() + set(LIBS + LLVMSupport # Depends on llvm::raw_ostream + ) +endif() find_library(PTHREAD_LIBRARY_PATH pthread) if (PTHREAD_LIBRARY_PATH) Index: utils/unittest/UnitTestMain/CMakeLists.txt =================================================================== --- utils/unittest/UnitTestMain/CMakeLists.txt +++ utils/unittest/UnitTestMain/CMakeLists.txt @@ -1,7 +1,17 @@ -add_llvm_library(gtest_main - TestMain.cpp +if (LLVM_LINK_LLVM_DYLIB) + add_llvm_library(gtest_main + TestMain.cpp - LINK_LIBS - gtest - LLVMSupport # Depends on llvm::cl - ) + LINK_LIBS + gtest + LLVM # Depends on llvm::cl + ) +else() + add_llvm_library(gtest_main + TestMain.cpp + + LINK_LIBS + gtest + LLVMSupport # Depends on llvm::cl + ) +endif() Index: utils/yaml-bench/CMakeLists.txt =================================================================== --- utils/yaml-bench/CMakeLists.txt +++ utils/yaml-bench/CMakeLists.txt @@ -2,4 +2,8 @@ YAMLBench.cpp ) -target_link_libraries(yaml-bench LLVMSupport) +if (LLVM_LINK_LLVM_DYLIB) + target_link_libraries(yaml-bench LLVM) +else() + target_link_libraries(yaml-bench LLVMSupport) +endif()