Index: clang/tools/driver/CMakeLists.txt =================================================================== --- clang/tools/driver/CMakeLists.txt +++ clang/tools/driver/CMakeLists.txt @@ -17,7 +17,7 @@ ) # Support plugins. -set(LLVM_NO_DEAD_STRIP 1) +set(LLVM_DEAD_STRIP OFF) add_clang_executable(clang driver.cpp Index: clang/utils/TableGen/CMakeLists.txt =================================================================== --- clang/utils/TableGen/CMakeLists.txt +++ clang/utils/TableGen/CMakeLists.txt @@ -1,5 +1,3 @@ -set(LLVM_LINK_COMPONENTS Support) - add_tablegen(clang-tblgen CLANG ClangASTNodesEmitter.cpp ClangAttrEmitter.cpp Index: llvm/CMakeLists.txt =================================================================== --- llvm/CMakeLists.txt +++ llvm/CMakeLists.txt @@ -298,6 +298,10 @@ "Default target for which LLVM will generate code." ) set(TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}") +if(NOT WIN32) + option(LLVM_ENABLE_SHARED "Build the big shared library libLLVM.so." OFF) +endif() + include(HandleLLVMOptions) # Verify that we can find a Python 2 interpreter. Python 3 is unsupported. Index: llvm/cmake/modules/AddLLVM.cmake =================================================================== --- llvm/cmake/modules/AddLLVM.cmake +++ llvm/cmake/modules/AddLLVM.cmake @@ -134,17 +134,19 @@ endfunction(add_llvm_symbol_exports) function(add_dead_strip target_name) - if(NOT LLVM_NO_DEAD_STRIP) - if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - set_property(TARGET ${target_name} APPEND_STRING PROPERTY - LINK_FLAGS " -Wl,-dead_strip") - elseif(NOT WIN32) - # Object files are compiled with -ffunction-data-sections. - set_property(TARGET ${target_name} APPEND_STRING PROPERTY - LINK_FLAGS " -Wl,--gc-sections") - endif() + if(NOT LLVM_DEAD_STRIP) + return() + endif() + + if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + set_property(TARGET ${target_name} APPEND_STRING PROPERTY + LINK_FLAGS " -Wl,-dead_strip") + elseif(NOT WIN32) + # Object files are compiled with -ffunction-data-sections. + set_property(TARGET ${target_name} APPEND_STRING PROPERTY + LINK_FLAGS " -Wl,--gc-sections") endif() -endfunction(add_dead_strip) +endfunction() # Set each output directory according to ${CMAKE_CONFIGURATION_TYPES}. # Note: Don't set variables CMAKE_*_OUTPUT_DIRECTORY any more, @@ -218,8 +220,16 @@ endif() endif() + set(build_objlib) # Generate objlib if(ARG_SHARED AND ARG_STATIC) + set(build_objlib TRUE) + endif() + if(LLVM_ENABLE_SHARED) + set(build_objlib TRUE) + endif() + + if(build_objlib AND NOT ARG_OBJLIBS) # Generate an obj library for both targets. set(obj_name "obj.${name}") add_library(${obj_name} OBJECT EXCLUDE_FROM_ALL @@ -296,10 +306,18 @@ # property has been set to an empty value. get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${name}) - llvm_map_components_to_libnames(llvm_libs - ${ARG_LINK_COMPONENTS} - ${LLVM_LINK_COMPONENTS} - ) + if((ARG_LINK_COMPONENTS OR LLVM_LINK_COMPONENTS) AND TARGET LLVM_shared) + set(llvm_libs) + # FIXME: It may be PRIVATE since SO knows its dependent libs. + target_link_libraries(${name} PUBLIC + LLVM_shared + ) + else() + llvm_map_components_to_libnames(llvm_libs + ${ARG_LINK_COMPONENTS} + ${LLVM_LINK_COMPONENTS} + ) + endif() if(CMAKE_VERSION VERSION_LESS 2.8.12) # Link libs w/o keywords, assuming PUBLIC. @@ -338,6 +356,10 @@ add_dependencies(${objlib} ${LLVM_COMMON_DEPENDS}) endforeach() endif() + + if(objlibs) + set_target_properties(${name} PROPERTIES LLVM_OBJLIBS ${objlibs}) + endif() endfunction() macro(add_llvm_library name) @@ -346,11 +368,11 @@ else() llvm_add_library(${name} ${ARGN}) endif() - set_property( GLOBAL APPEND PROPERTY LLVM_LIBS ${name} ) if( EXCLUDE_FROM_ALL ) set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON) else() + set_property( GLOBAL APPEND PROPERTY LLVM_LIBS ${name} ) if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LTO") install(TARGETS ${name} EXPORT LLVMExports @@ -401,7 +423,13 @@ set(EXCLUDE_FROM_ALL OFF) set_output_directory(${name} ${LLVM_RUNTIME_OUTPUT_INTDIR} ${LLVM_LIBRARY_OUTPUT_INTDIR}) - llvm_config( ${name} ${LLVM_LINK_COMPONENTS} ) + if(LLVM_LINK_COMPONENTS) + if(TARGET LLVM_shared) + target_link_libraries(${name} LLVM_shared) + else() + llvm_config(${name} ${LLVM_LINK_COMPONENTS}) + endif() + endif() if( LLVM_COMMON_DEPENDS ) add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} ) endif( LLVM_COMMON_DEPENDS ) @@ -456,7 +484,7 @@ include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) - add_llvm_library(LLVM${target_name} ${ARGN} ${TABLEGEN_OUTPUT}) + add_llvm_library(LLVM${target_name} ${ARGN}) set( CURRENT_LLVM_TARGET LLVM${target_name} ) endmacro(add_llvm_target) Index: llvm/cmake/modules/HandleLLVMOptions.cmake =================================================================== --- llvm/cmake/modules/HandleLLVMOptions.cmake +++ llvm/cmake/modules/HandleLLVMOptions.cmake @@ -353,8 +353,10 @@ # Add flags for add_dead_strip(). # FIXME: With MSVS, consider compiling with /Gy and linking with /OPT:REF? # But MinSizeRel seems to add that automatically, so maybe disable these -# flags instead if LLVM_NO_DEAD_STRIP is set. -if(NOT CYGWIN AND NOT WIN32) +# flags instead if LLVM_DEAD_STRIP is not set. +# With LLVM_ENABLE_SHARED, LLVM_DEAD_STRIP doesn't make sense. +if(NOT LLVM_ENABLE_SHARED AND NOT CYGWIN AND NOT WIN32) + set(LLVM_DEAD_STRIP ON) if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") check_c_compiler_flag("-Werror -fno-function-sections" C_SUPPORTS_FNO_FUNCTION_SECTIONS) if (C_SUPPORTS_FNO_FUNCTION_SECTIONS) Index: llvm/cmake/modules/TableGen.cmake =================================================================== --- llvm/cmake/modules/TableGen.cmake +++ llvm/cmake/modules/TableGen.cmake @@ -91,10 +91,9 @@ endif() macro(add_tablegen target project) - set(${target}_OLD_LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS}) - set(LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS} TableGen) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_TOOLS_BINARY_DIR}) + add_llvm_utility(${target} ${ARGN}) - set(LLVM_LINK_COMPONENTS ${${target}_OLD_LLVM_LINK_COMPONENTS}) set(${project}_TABLEGEN "${target}" CACHE STRING "Native TableGen executable. Saves building one when cross-compiling.") @@ -128,6 +127,7 @@ endif() endif() + target_link_libraries(${target} LLVMSupport LLVMTableGen) if( MINGW ) if(CMAKE_SIZEOF_VOID_P MATCHES "8") set_target_properties(${target} PROPERTIES LINK_FLAGS -Wl,--stack,16777216) Index: llvm/lib/Analysis/CMakeLists.txt =================================================================== --- llvm/lib/Analysis/CMakeLists.txt +++ llvm/lib/Analysis/CMakeLists.txt @@ -51,8 +51,7 @@ Trace.cpp TypeBasedAliasAnalysis.cpp ValueTracking.cpp + DEPENDS intrinsics_gen ) -add_dependencies(LLVMAnalysis intrinsics_gen) - add_subdirectory(IPA) Index: llvm/lib/Analysis/IPA/CMakeLists.txt =================================================================== --- llvm/lib/Analysis/IPA/CMakeLists.txt +++ llvm/lib/Analysis/IPA/CMakeLists.txt @@ -6,6 +6,5 @@ GlobalsModRef.cpp IPA.cpp InlineCost.cpp + DEPENDS intrinsics_gen ) - -add_dependencies(LLVMipa intrinsics_gen) Index: llvm/lib/Bitcode/Reader/CMakeLists.txt =================================================================== --- llvm/lib/Bitcode/Reader/CMakeLists.txt +++ llvm/lib/Bitcode/Reader/CMakeLists.txt @@ -2,6 +2,5 @@ BitReader.cpp BitcodeReader.cpp BitstreamReader.cpp + DEPENDS intrinsics_gen ) - -add_dependencies(LLVMBitReader intrinsics_gen) Index: llvm/lib/CodeGen/AsmPrinter/CMakeLists.txt =================================================================== --- llvm/lib/CodeGen/AsmPrinter/CMakeLists.txt +++ llvm/lib/CodeGen/AsmPrinter/CMakeLists.txt @@ -14,6 +14,5 @@ OcamlGCPrinter.cpp Win64Exception.cpp WinCodeViewLineTables.cpp + DEPENDS intrinsics_gen ) - -add_dependencies(LLVMAsmPrinter intrinsics_gen) Index: llvm/lib/CodeGen/CMakeLists.txt =================================================================== --- llvm/lib/CodeGen/CMakeLists.txt +++ llvm/lib/CodeGen/CMakeLists.txt @@ -111,9 +111,8 @@ TwoAddressInstructionPass.cpp UnreachableBlockElim.cpp VirtRegMap.cpp + DEPENDS intrinsics_gen ) -add_dependencies(LLVMCodeGen intrinsics_gen) - add_subdirectory(SelectionDAG) add_subdirectory(AsmPrinter) Index: llvm/lib/CodeGen/SelectionDAG/CMakeLists.txt =================================================================== --- llvm/lib/CodeGen/SelectionDAG/CMakeLists.txt +++ llvm/lib/CodeGen/SelectionDAG/CMakeLists.txt @@ -22,6 +22,5 @@ ScheduleDAGVLIW.cpp TargetLowering.cpp TargetSelectionDAGInfo.cpp + DEPENDS intrinsics_gen ) - -add_dependencies(LLVMSelectionDAG intrinsics_gen) Index: llvm/lib/ExecutionEngine/Interpreter/CMakeLists.txt =================================================================== --- llvm/lib/ExecutionEngine/Interpreter/CMakeLists.txt +++ llvm/lib/ExecutionEngine/Interpreter/CMakeLists.txt @@ -10,10 +10,9 @@ Execution.cpp ExternalFunctions.cpp Interpreter.cpp + DEPENDS intrinsics_gen ) if( LLVM_ENABLE_FFI ) target_link_libraries( LLVMInterpreter ${FFI_LIBRARY_PATH} ) endif() - -add_dependencies(LLVMInterpreter intrinsics_gen) Index: llvm/lib/IR/CMakeLists.txt =================================================================== --- llvm/lib/IR/CMakeLists.txt +++ llvm/lib/IR/CMakeLists.txt @@ -42,6 +42,5 @@ ValueSymbolTable.cpp ValueTypes.cpp Verifier.cpp + DEPENDS intrinsics_gen ) - -add_dependencies(LLVMCore intrinsics_gen) Index: llvm/lib/Transforms/IPO/CMakeLists.txt =================================================================== --- llvm/lib/Transforms/IPO/CMakeLists.txt +++ llvm/lib/Transforms/IPO/CMakeLists.txt @@ -20,6 +20,5 @@ PruneEH.cpp StripDeadPrototypes.cpp StripSymbols.cpp + DEPENDS intrinsics_gen ) - -add_dependencies(LLVMipo intrinsics_gen) Index: llvm/lib/Transforms/InstCombine/CMakeLists.txt =================================================================== --- llvm/lib/Transforms/InstCombine/CMakeLists.txt +++ llvm/lib/Transforms/InstCombine/CMakeLists.txt @@ -12,6 +12,5 @@ InstCombineShifts.cpp InstCombineSimplifyDemanded.cpp InstCombineVectorOps.cpp + DEPENDS intrinsics_gen ) - -add_dependencies(LLVMInstCombine intrinsics_gen) Index: llvm/lib/Transforms/Instrumentation/CMakeLists.txt =================================================================== --- llvm/lib/Transforms/Instrumentation/CMakeLists.txt +++ llvm/lib/Transforms/Instrumentation/CMakeLists.txt @@ -7,6 +7,5 @@ MemorySanitizer.cpp Instrumentation.cpp ThreadSanitizer.cpp + DEPENDS intrinsics_gen ) - -add_dependencies(LLVMInstrumentation intrinsics_gen) Index: llvm/lib/Transforms/ObjCARC/CMakeLists.txt =================================================================== --- llvm/lib/Transforms/ObjCARC/CMakeLists.txt +++ llvm/lib/Transforms/ObjCARC/CMakeLists.txt @@ -8,6 +8,5 @@ ObjCARCContract.cpp DependencyAnalysis.cpp ProvenanceAnalysis.cpp + DEPENDS intrinsics_gen ) - -add_dependencies(LLVMObjCARCOpts intrinsics_gen) Index: llvm/lib/Transforms/Scalar/CMakeLists.txt =================================================================== --- llvm/lib/Transforms/Scalar/CMakeLists.txt +++ llvm/lib/Transforms/Scalar/CMakeLists.txt @@ -35,6 +35,5 @@ Sink.cpp StructurizeCFG.cpp TailRecursionElimination.cpp + DEPENDS intrinsics_gen ) - -add_dependencies(LLVMScalarOpts intrinsics_gen) Index: llvm/lib/Transforms/Utils/CMakeLists.txt =================================================================== --- llvm/lib/Transforms/Utils/CMakeLists.txt +++ llvm/lib/Transforms/Utils/CMakeLists.txt @@ -36,6 +36,5 @@ UnifyFunctionExitNodes.cpp Utils.cpp ValueMapper.cpp + DEPENDS intrinsics_gen ) - -add_dependencies(LLVMTransformUtils intrinsics_gen) Index: llvm/lib/Transforms/Vectorize/CMakeLists.txt =================================================================== --- llvm/lib/Transforms/Vectorize/CMakeLists.txt +++ llvm/lib/Transforms/Vectorize/CMakeLists.txt @@ -3,6 +3,5 @@ Vectorize.cpp LoopVectorize.cpp SLPVectorizer.cpp + DEPENDS intrinsics_gen ) - -add_dependencies(LLVMVectorize intrinsics_gen) Index: llvm/tools/CMakeLists.txt =================================================================== --- llvm/tools/CMakeLists.txt +++ llvm/tools/CMakeLists.txt @@ -1,3 +1,7 @@ +if(LLVM_ENABLE_SHARED) + add_llvm_tool_subdirectory(llvm-shlib) +endif() + add_llvm_tool_subdirectory(llvm-config) add_llvm_tool_subdirectory(opt) Index: llvm/tools/bugpoint/CMakeLists.txt =================================================================== --- llvm/tools/bugpoint/CMakeLists.txt +++ llvm/tools/bugpoint/CMakeLists.txt @@ -18,7 +18,7 @@ ) # Support plugins. -set(LLVM_NO_DEAD_STRIP 1) +set(LLVM_DEAD_STRIP OFF) add_llvm_tool(bugpoint BugDriver.cpp Index: llvm/tools/llc/CMakeLists.txt =================================================================== --- llvm/tools/llc/CMakeLists.txt +++ llvm/tools/llc/CMakeLists.txt @@ -12,7 +12,7 @@ ) # Support plugins. -set(LLVM_NO_DEAD_STRIP 1) +set(LLVM_DEAD_STRIP OFF) add_llvm_tool(llc llc.cpp Index: llvm/tools/llvm-shlib/CMakeLists.txt =================================================================== --- /dev/null +++ llvm/tools/llvm-shlib/CMakeLists.txt @@ -0,0 +1,25 @@ +get_property(llvm_libs GLOBAL PROPERTY LLVM_LIBS) +list(REMOVE_ITEM llvm_libs LLVMTableGen gtest gtest_main) +foreach(lib ${llvm_libs}) + get_target_property(objlibs ${lib} LLVM_OBJLIBS) + foreach(objlib ${objlibs}) + list(APPEND all_objlibs "$") + endforeach() + # Collect dependent system libs. + get_target_property(dependent_libs ${lib} INTERFACE_LINK_LIBRARIES) + list(REMOVE_ITEM dependent_libs ${llvm_libs}) + if(dependent_libs) + list(REVERSE dependent_libs) + list(INSERT all_dependent_libs 0 ${dependent_libs}) + endif() +endforeach() +list(REMOVE_DUPLICATES all_dependent_libs) +list(REVERSE all_dependent_libs) + +add_llvm_library(LLVM_shared SHARED + OUTPUT_NAME "LLVM-3.5" + OBJLIBS ${all_objlibs} + LINK_LIBS ${all_dependent_libs} + ) + +set_target_properties(LLVM_shared PROPERTIES LINKER_LANGUAGE "CXX") Index: llvm/tools/opt/CMakeLists.txt =================================================================== --- llvm/tools/opt/CMakeLists.txt +++ llvm/tools/opt/CMakeLists.txt @@ -19,7 +19,7 @@ ) # Support plugins. -set(LLVM_NO_DEAD_STRIP 1) +set(LLVM_DEAD_STRIP OFF) add_llvm_tool(opt AnalysisWrappers.cpp Index: llvm/unittests/ExecutionEngine/JIT/CMakeLists.txt =================================================================== --- llvm/unittests/ExecutionEngine/JIT/CMakeLists.txt +++ llvm/unittests/ExecutionEngine/JIT/CMakeLists.txt @@ -52,7 +52,7 @@ endif() # The JIT tests need to dlopen things. -set(LLVM_NO_DEAD_STRIP 1) +set(LLVM_DEAD_STRIP OFF) add_llvm_unittest(JITTests ${JITTestsSources} Index: llvm/utils/TableGen/CMakeLists.txt =================================================================== --- llvm/utils/TableGen/CMakeLists.txt +++ llvm/utils/TableGen/CMakeLists.txt @@ -1,5 +1,3 @@ -set(LLVM_LINK_COMPONENTS Support) - add_tablegen(llvm-tblgen LLVM AsmMatcherEmitter.cpp AsmWriterEmitter.cpp