Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ CMakeLists.txt @@ -460,9 +460,16 @@ set(LLVMOPTIONALCOMPONENTS ${LLVMOPTIONALCOMPONENTS} OProfileJIT) endif (LLVM_USE_OPROFILE) +if (LLVM_LINK_LLVM_DYLIB) + set(ENABLE_LLVM_LINK_LLVM_DYLIB "--enable-llvm-link-llvm-dylib") +else() + set(ENABLE_LLVM_LINK_LLVM_DYLIB "") +endif() + message(STATUS "Constructing LLVMBuild project information") execute_process( COMMAND ${PYTHON_EXECUTABLE} ${LLVMBUILDTOOL} + "${ENABLE_LLVM_LINK_LLVM_DYLIB}" --native-target "${LLVM_NATIVE_ARCH}" --enable-targets "${LLVM_TARGETS_TO_BUILD}" --enable-optional-components "${LLVMOPTIONALCOMPONENTS}" 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) @@ -885,11 +887,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/llvm-build/llvmbuild/main.py =================================================================== --- utils/llvm-build/llvmbuild/main.py +++ utils/llvm-build/llvmbuild/main.py @@ -350,6 +350,10 @@ library_name = None is_installed = True + # Check for gtest + if (library_name == 'gtest') and use_llvm_link_llvm_dylib: + c.required_libraries.remove('Support') + # Get the component names of all the required libraries. required_llvmconfig_component_names = [ self.component_info_map[dep].get_llvmconfig_component_name() @@ -907,6 +911,13 @@ help=("Enable the given space or semi-colon separated " "list of optional components"), action="store", default="") + group.add_option("", "--enable-llvm-link-llvm-dylib", + dest="llvm_link_llvm_dylib", + help=("Use libLLVM instead of LLVM component shared " + "libraries for linkage"), + action="store_true", default=False) + + parser.add_option_group(group) (opts, args) = parser.parse_args() @@ -937,6 +948,13 @@ # Validate the project component info. project_info.validate_components() + # Use libLLVM instead of LLVM component shared libraries for linkage + global use_llvm_link_llvm_dylib + if opts.llvm_link_llvm_dylib: + use_llvm_link_llvm_dylib = True + else: + use_llvm_link_llvm_dylib = False + # Print the component tree, if requested. if opts.print_tree: project_info.print_tree() 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,11 @@ add_definitions( -DGTEST_HAS_PTHREAD=0 ) endif() -set(LIBS - LLVMSupport # Depends on llvm::raw_ostream -) +if (NOT LLVM_LINK_LLVM_DYLIB) + 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()