[Lldb-commits] [lldb] r365617 - [CMake] `install-distribution` for LLDB on Darwin
Stefan Granitz via lldb-commits
lldb-commits at lists.llvm.org
Wed Jul 10 04:09:29 PDT 2019
Author: stefan.graenitz
Date: Wed Jul 10 04:09:29 2019
New Revision: 365617
URL: http://llvm.org/viewvc/llvm-project?rev=365617&view=rev
Log:
[CMake] `install-distribution` for LLDB on Darwin
Summary:
There's a number of requirements for installing LLDB on macOS that are untypical for LLVM projects: use special install-prefix for LLDB.framework, ship headers and tools as framework resources, patch RPATHs, externalize debug-info to dSYM's and strip binaries with `-ST`. For some of it we could use `llvm_externalize_debuginfo()` in the past and just add special cases. However, this complicates the code for all projects and comes with the major drawback, that it adds all these actions at build-time, i.e. dSYM creation and stripping take a lot of time and don't make sense at build-time.
LLVM's distribution mechanism (https://llvm.org/docs/BuildingADistribution.html) appears to be the natural candidate to install LLDB. Based on D64399 (enable in standalone builds), this patch integrates framework installation with the distribution mechanism and adds custom stripping flags and dSYM creation at install-time. Unlike the abandoned D61952, it leaves build-tree binaries untouched, so there's no side-effects on testing. Potential install-order issues must be handled externally.
Please let me know what you think, while I run a few more tests and add remarks+documentation.
Reviewers: xiaobai, compnerd, JDevlieghere, davide, labath, mgorny
Reviewed By: xiaobai, JDevlieghere
Subscribers: lldb-commits, #lldb
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D64408
Modified:
lldb/trunk/cmake/caches/Apple-lldb-macOS.cmake
lldb/trunk/cmake/modules/AddLLDB.cmake
lldb/trunk/cmake/modules/LLDBConfig.cmake
lldb/trunk/cmake/modules/LLDBFramework.cmake
lldb/trunk/source/API/CMakeLists.txt
lldb/trunk/tools/argdumper/CMakeLists.txt
lldb/trunk/tools/darwin-debug/CMakeLists.txt
lldb/trunk/tools/debugserver/source/CMakeLists.txt
Modified: lldb/trunk/cmake/caches/Apple-lldb-macOS.cmake
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/cmake/caches/Apple-lldb-macOS.cmake?rev=365617&r1=365616&r2=365617&view=diff
==============================================================================
--- lldb/trunk/cmake/caches/Apple-lldb-macOS.cmake (original)
+++ lldb/trunk/cmake/caches/Apple-lldb-macOS.cmake Wed Jul 10 04:09:29 2019
@@ -13,6 +13,9 @@ set(CMAKE_INSTALL_PREFIX /Applications/X
# 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 "")
Modified: lldb/trunk/cmake/modules/AddLLDB.cmake
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/cmake/modules/AddLLDB.cmake?rev=365617&r1=365616&r2=365617&view=diff
==============================================================================
--- lldb/trunk/cmake/modules/AddLLDB.cmake (original)
+++ lldb/trunk/cmake/modules/AddLLDB.cmake Wed Jul 10 04:09:29 2019
@@ -3,7 +3,7 @@ function(add_lldb_library name)
# 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 @@ function(add_lldb_library name)
${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 @@ endfunction(add_lldb_library)
function(add_lldb_executable name)
cmake_parse_arguments(ARG
"GENERATE_INSTALL"
- "ENTITLEMENTS"
+ "INSTALL_PREFIX;ENTITLEMENTS"
"LINK_LIBS;LINK_COMPONENTS"
${ARGN}
)
@@ -134,16 +122,22 @@ function(add_lldb_executable name)
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 @@ macro(add_lldb_tool_subdirectory name)
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 @@ function(lldb_append_link_flags target_n
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 "$<TARGET_FILE_DIR:liblldb>/../../../${subdir}")
@@ -187,6 +188,61 @@ function(lldb_add_to_framework name)
)
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.
Modified: lldb/trunk/cmake/modules/LLDBConfig.cmake
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/cmake/modules/LLDBConfig.cmake?rev=365617&r1=365616&r2=365617&view=diff
==============================================================================
--- lldb/trunk/cmake/modules/LLDBConfig.cmake (original)
+++ lldb/trunk/cmake/modules/LLDBConfig.cmake Wed Jul 10 04:09:29 2019
@@ -65,12 +65,9 @@ if(LLDB_BUILD_FRAMEWORK)
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")
Modified: lldb/trunk/cmake/modules/LLDBFramework.cmake
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/cmake/modules/LLDBFramework.cmake?rev=365617&r1=365616&r2=365617&view=diff
==============================================================================
--- lldb/trunk/cmake/modules/LLDBFramework.cmake (original)
+++ lldb/trunk/cmake/modules/LLDBFramework.cmake Wed Jul 10 04:09:29 2019
@@ -33,6 +33,8 @@ set_output_directory(liblldb
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
Modified: lldb/trunk/source/API/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/CMakeLists.txt?rev=365617&r1=365616&r2=365617&view=diff
==============================================================================
--- lldb/trunk/source/API/CMakeLists.txt (original)
+++ lldb/trunk/source/API/CMakeLists.txt Wed Jul 10 04:09:29 2019
@@ -9,8 +9,8 @@ if(NOT LLDB_DISABLE_PYTHON)
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 @@ add_lldb_library(liblldb SHARED
${LLDB_ALL_PLUGINS}
LINK_COMPONENTS
Support
- )
+
+ ${option_install_prefix}
+)
if (MSVC)
set_source_files_properties(SBReproducer.cpp PROPERTIES COMPILE_FLAGS /bigobj)
Modified: lldb/trunk/tools/argdumper/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/argdumper/CMakeLists.txt?rev=365617&r1=365616&r2=365617&view=diff
==============================================================================
--- lldb/trunk/tools/argdumper/CMakeLists.txt (original)
+++ lldb/trunk/tools/argdumper/CMakeLists.txt Wed Jul 10 04:09:29 2019
@@ -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()
+)
Modified: lldb/trunk/tools/darwin-debug/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/darwin-debug/CMakeLists.txt?rev=365617&r1=365616&r2=365617&view=diff
==============================================================================
--- lldb/trunk/tools/darwin-debug/CMakeLists.txt (original)
+++ lldb/trunk/tools/darwin-debug/CMakeLists.txt Wed Jul 10 04:09:29 2019
@@ -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()
+)
Modified: lldb/trunk/tools/debugserver/source/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/CMakeLists.txt?rev=365617&r1=365616&r2=365617&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/CMakeLists.txt (original)
+++ lldb/trunk/tools/debugserver/source/CMakeLists.txt Wed Jul 10 04:09:29 2019
@@ -272,22 +272,14 @@ if(build_and_sign_debugserver)
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
More information about the lldb-commits
mailing list