Index: lldb/trunk/cmake/caches/Apple-lldb-macOS.cmake =================================================================== --- lldb/trunk/cmake/caches/Apple-lldb-macOS.cmake +++ lldb/trunk/cmake/caches/Apple-lldb-macOS.cmake @@ -13,6 +13,9 @@ # CMAKE_INSTALL_PREFIX. In any case, DESTDIR will be an extra prefix. set(LLDB_FRAMEWORK_INSTALL_DIR /Applications/Xcode.app/Contents/SharedFrameworks CACHE STRING "") +# DESTDIR will be an extra prefix +set(LLDB_DEBUGINFO_INSTALL_PREFIX /debuginfo CACHE STRING "") + # Release builds may change these: set(CMAKE_OSX_DEPLOYMENT_TARGET 10.11 CACHE STRING "") set(LLDB_USE_SYSTEM_DEBUGSERVER OFF CACHE BOOL "") Index: lldb/trunk/cmake/modules/AddLLDB.cmake =================================================================== --- lldb/trunk/cmake/modules/AddLLDB.cmake +++ lldb/trunk/cmake/modules/AddLLDB.cmake @@ -3,7 +3,7 @@ # MODULE;SHARED;STATIC library type and source files cmake_parse_arguments(PARAM "MODULE;SHARED;STATIC;OBJECT;PLUGIN" - "ENTITLEMENTS" + "INSTALL_PREFIX;ENTITLEMENTS" "EXTRA_CXXFLAGS;DEPENDS;LINK_LIBS;LINK_COMPONENTS" ${ARGN}) llvm_process_sources(srcs ${PARAM_UNPARSED_ARGUMENTS}) @@ -58,38 +58,26 @@ ${pass_ENTITLEMENTS} ${pass_NO_INSTALL_RPATH} ) + endif() - if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "liblldb") - if (PARAM_SHARED) - if(${name} STREQUAL "liblldb" AND LLDB_BUILD_FRAMEWORK) - if(LLDB_FRAMEWORK_INSTALL_DIR) - set(install_dir ${LLDB_FRAMEWORK_INSTALL_DIR}) - else() - set(install_dir ".") - endif() - else() - set(install_dir lib${LLVM_LIBDIR_SUFFIX}) - endif() - install(TARGETS ${name} - COMPONENT ${name} - RUNTIME DESTINATION bin - LIBRARY DESTINATION ${install_dir} - ARCHIVE DESTINATION ${install_dir}) - else() - install(TARGETS ${name} - COMPONENT ${name} - LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} - ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) - endif() - if (NOT CMAKE_CONFIGURATION_TYPES) - add_llvm_install_targets(install-${name} - DEPENDS ${name} - COMPONENT ${name}) - endif() + if(PARAM_SHARED) + set(install_dest lib${LLVM_LIBDIR_SUFFIX}) + if(PARAM_INSTALL_PREFIX) + set(install_dest ${PARAM_INSTALL_PREFIX}) + endif() + # RUNTIME is relevant for DLL platforms, FRAMEWORK for macOS + install(TARGETS ${name} COMPONENT ${name} + RUNTIME DESTINATION bin + LIBRARY DESTINATION ${install_dest} + ARCHIVE DESTINATION ${install_dest} + FRAMEWORK DESTINATION ${install_dest}) + if (NOT CMAKE_CONFIGURATION_TYPES) + add_llvm_install_targets(install-${name} + DEPENDS ${name} + COMPONENT ${name}) endif() endif() - # Hack: only some LLDB libraries depend on the clang autogenerated headers, # but it is simple enough to make all of LLDB depend on some of those # headers without negatively impacting much of anything. @@ -110,7 +98,7 @@ function(add_lldb_executable name) cmake_parse_arguments(ARG "GENERATE_INSTALL" - "ENTITLEMENTS" + "INSTALL_PREFIX;ENTITLEMENTS" "LINK_LIBS;LINK_COMPONENTS" ${ARGN} ) @@ -134,16 +122,22 @@ set_target_properties(${name} PROPERTIES FOLDER "lldb executables") if(ARG_GENERATE_INSTALL) - install(TARGETS ${name} - COMPONENT ${name} - RUNTIME DESTINATION bin) + set(install_dest bin) + if(ARG_INSTALL_PREFIX) + set(install_dest ${ARG_INSTALL_PREFIX}) + endif() + install(TARGETS ${name} COMPONENT ${name} + RUNTIME DESTINATION ${install_dest}) if (NOT CMAKE_CONFIGURATION_TYPES) add_llvm_install_targets(install-${name} DEPENDS ${name} COMPONENT ${name}) endif() + if(APPLE AND ARG_INSTALL_PREFIX) + lldb_add_post_install_steps_darwin(${name} ${ARG_INSTALL_PREFIX}) + endif() endif() -endfunction(add_lldb_executable) +endfunction() macro(add_lldb_tool_subdirectory name) @@ -151,7 +145,19 @@ endmacro() function(add_lldb_tool name) - add_lldb_executable(${name} GENERATE_INSTALL ${ARGN}) + cmake_parse_arguments(ARG "ADD_TO_FRAMEWORK" "" "" ${ARGN}) + if(LLDB_BUILD_FRAMEWORK AND ARG_ADD_TO_FRAMEWORK) + set(subdir LLDB.framework/Versions/${LLDB_FRAMEWORK_VERSION}/Resources) + add_lldb_executable(${name} + GENERATE_INSTALL + INSTALL_PREFIX ${LLDB_FRAMEWORK_INSTALL_DIR}/${subdir} + ${ARG_UNPARSED_ARGUMENTS} + ) + lldb_add_to_buildtree_lldb_framework(${name} ${subdir}) + return() + endif() + + add_lldb_executable(${name} GENERATE_INSTALL ${ARG_UNPARSED_ARGUMENTS}) endfunction() # Support appending linker flags to an existing target. @@ -170,12 +176,7 @@ set_target_properties(${target_name} PROPERTIES LINK_FLAGS ${new_link_flags}) endfunction() -# Unified handling for executable LLDB.framework resources. Given the name of an -# executable target, this function adds a post-build step to copy it to the -# framework bundle in the build-tree. -function(lldb_add_to_framework name) - set(subdir "LLDB.framework/Versions/${LLDB_FRAMEWORK_VERSION}/Resources") - +function(lldb_add_to_buildtree_lldb_framework name subdir) # Destination for the copy in the build-tree. While the framework target may # not exist yet, it will exist when the generator expression gets expanded. set(copy_dest "$/../../../${subdir}") @@ -187,6 +188,61 @@ ) endfunction() +function(lldb_add_post_install_steps_darwin name install_prefix) + if(NOT APPLE) + message(WARNING "Darwin-specific functionality; not currently available on non-Apple platforms.") + return() + endif() + + get_target_property(output_name ${name} OUTPUT_NAME) + if(NOT output_name) + set(output_name ${name}) + endif() + + get_target_property(is_framework ${name} FRAMEWORK) + if(is_framework) + get_target_property(buildtree_dir ${name} LIBRARY_OUTPUT_DIRECTORY) + if(buildtree_dir) + set(bundle_subdir ${output_name}.framework/Versions/${LLDB_FRAMEWORK_VERSION}/) + else() + message(SEND_ERROR "Framework target ${name} missing property for output directory. Cannot generate post-install steps.") + return() + endif() + else() + get_target_property(target_type ${name} TYPE) + if(target_type STREQUAL "EXECUTABLE") + set(buildtree_dir ${LLVM_RUNTIME_OUTPUT_INTDIR}) + else() + # Only ever install shared libraries. + set(output_name "lib${output_name}.dylib") + set(buildtree_dir ${LLVM_LIBRARY_OUTPUT_INTDIR}) + endif() + endif() + + # Generate dSYM in symroot + set(dsym_name ${output_name}.dSYM) + if(is_framework) + set(dsym_name ${output_name}.framework.dSYM) + endif() + if(LLDB_DEBUGINFO_INSTALL_PREFIX) + # This makes the path absolute, so we must respect DESTDIR. + set(dsym_name "\$ENV\{DESTDIR\}${LLDB_DEBUGINFO_INSTALL_PREFIX}/${dsym_name}") + endif() + + set(buildtree_name ${buildtree_dir}/${bundle_subdir}${output_name}) + install(CODE "message(STATUS \"Externalize debuginfo: ${dsym_name}\")" COMPONENT ${name}) + install(CODE "execute_process(COMMAND xcrun dsymutil -o=${dsym_name} ${buildtree_name})" + COMPONENT ${name}) + + # Strip distribution binary with -ST (removing debug symbol table entries and + # Swift symbols). Avoid CMAKE_INSTALL_DO_STRIP and llvm_externalize_debuginfo() + # as they can't be configured sufficiently. + set(installtree_name "\$ENV\{DESTDIR\}${install_prefix}/${bundle_subdir}${output_name}") + install(CODE "message(STATUS \"Stripping: ${installtree_name}\")" COMPONENT ${name}) + install(CODE "execute_process(COMMAND xcrun strip -ST ${installtree_name})" + COMPONENT ${name}) +endfunction() + # CMake's set_target_properties() doesn't allow to pass lists for RPATH # properties directly (error: "called with incorrect number of arguments"). # Instead of defining two list variables each time, use this helper function. Index: lldb/trunk/cmake/modules/LLDBConfig.cmake =================================================================== --- lldb/trunk/cmake/modules/LLDBConfig.cmake +++ lldb/trunk/cmake/modules/LLDBConfig.cmake @@ -65,12 +65,9 @@ set(LLDB_FRAMEWORK_BUILD_DIR bin CACHE STRING "Output directory for LLDB.framework") set(LLDB_FRAMEWORK_INSTALL_DIR Library/Frameworks CACHE STRING "Install directory for LLDB.framework") - # Set designated directory for all dSYMs. Essentially, this emits the - # framework's dSYM outside of the framework directory. - if(LLVM_EXTERNALIZE_DEBUGINFO) - set(LLVM_EXTERNALIZE_DEBUGINFO_OUTPUT_DIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin CACHE STRING - "Directory to emit dSYM files stripped from executables and libraries (Darwin Only)") - endif() + # Essentially, emit the framework's dSYM outside of the framework directory. + set(LLDB_DEBUGINFO_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin CACHE STRING + "Directory to emit dSYM files stripped from executables and libraries (Darwin Only)") endif() if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows") Index: lldb/trunk/cmake/modules/LLDBFramework.cmake =================================================================== --- lldb/trunk/cmake/modules/LLDBFramework.cmake +++ lldb/trunk/cmake/modules/LLDBFramework.cmake @@ -33,6 +33,8 @@ LIBRARY_DIR ${framework_target_dir} ) +lldb_add_post_install_steps_darwin(liblldb ${LLDB_FRAMEWORK_INSTALL_DIR}) + # Affects the layout of the framework bundle (default is macOS layout). if(IOS) set_target_properties(liblldb PROPERTIES Index: lldb/trunk/source/API/CMakeLists.txt =================================================================== --- lldb/trunk/source/API/CMakeLists.txt +++ lldb/trunk/source/API/CMakeLists.txt @@ -9,8 +9,8 @@ set(lldb_python_wrapper ${lldb_scripts_dir}/LLDBWrapPython.cpp) endif() -if(LLDB_BUILD_FRAMEWORK AND LLVM_EXTERNALIZE_DEBUGINFO) - set(LLVM_EXTERNALIZE_DEBUGINFO_EXTENSION framework.dSYM) +if(LLDB_BUILD_FRAMEWORK) + set(option_install_prefix INSTALL_PREFIX ${LLDB_FRAMEWORK_INSTALL_DIR}) endif() add_lldb_library(liblldb SHARED @@ -99,7 +99,9 @@ ${LLDB_ALL_PLUGINS} LINK_COMPONENTS Support - ) + + ${option_install_prefix} +) if (MSVC) set_source_files_properties(SBReproducer.cpp PROPERTIES COMPILE_FLAGS /bigobj) Index: lldb/trunk/tools/argdumper/CMakeLists.txt =================================================================== --- lldb/trunk/tools/argdumper/CMakeLists.txt +++ lldb/trunk/tools/argdumper/CMakeLists.txt @@ -1,10 +1,6 @@ -add_lldb_tool(lldb-argdumper +add_lldb_tool(lldb-argdumper ADD_TO_FRAMEWORK argdumper.cpp LINK_LIBS lldbUtility - ) - -if(LLDB_BUILD_FRAMEWORK) - lldb_add_to_framework(lldb-argdumper) -endif() +) Index: lldb/trunk/tools/darwin-debug/CMakeLists.txt =================================================================== --- lldb/trunk/tools/darwin-debug/CMakeLists.txt +++ lldb/trunk/tools/darwin-debug/CMakeLists.txt @@ -1,7 +1,3 @@ -add_lldb_tool(darwin-debug +add_lldb_tool(darwin-debug ADD_TO_FRAMEWORK darwin-debug.cpp - ) - -if(LLDB_BUILD_FRAMEWORK) - lldb_add_to_framework(darwin-debug) -endif() +) Index: lldb/trunk/tools/debugserver/source/CMakeLists.txt =================================================================== --- lldb/trunk/tools/debugserver/source/CMakeLists.txt +++ lldb/trunk/tools/debugserver/source/CMakeLists.txt @@ -272,22 +272,14 @@ COMPILE_DEFINITIONS HAVE_LIBCOMPRESSION) endif() set(LLVM_OPTIONAL_SOURCES ${lldbDebugserverCommonSources}) - add_lldb_tool(debugserver + add_lldb_tool(debugserver ADD_TO_FRAMEWORK debugserver.cpp - - LINK_LIBS - lldbDebugserverCommon - - ENTITLEMENTS - ${entitlements} - ) + LINK_LIBS lldbDebugserverCommon + ENTITLEMENTS ${entitlements} + ) set_target_properties(debugserver PROPERTIES FOLDER "lldb libraries/debugserver") - if(LLDB_BUILD_FRAMEWORK) - lldb_add_to_framework(debugserver) - endif() - if(IOS) set_property(TARGET lldbDebugserverCommon APPEND PROPERTY COMPILE_DEFINITIONS WITH_LOCKDOWN