Skip to content

Commit

Permalink
[CMake] LLDB.framework tools handling
Browse files Browse the repository at this point in the history
Summary:
Modify the way LLDB.framework tools are collected. This allows for better fine-tuning of the install behavior downstream. Each target calls `lldb_add_to_framework()` individually. When entering the function, the target exists and we can tweak its very own post-build and install steps. This was not possible with the old `LLDB_FRAMEWORK_TOOLS` approach.

No function change otherwise.
This is a reduced follow-up from the proposal in D61952.

Reviewers: xiaobai, compnerd, JDevlieghere

Reviewed By: JDevlieghere

Subscribers: clayborg, friss, ki.stfu, mgorny, lldb-commits, labath, #lldb

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D62472

llvm-svn: 361946
  • Loading branch information
weliveindetail committed May 29, 2019
1 parent 5b363c1 commit 5dc9036
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 19 deletions.
4 changes: 4 additions & 0 deletions lldb/CMakeLists.txt
Expand Up @@ -151,6 +151,10 @@ if(LLDB_INCLUDE_TESTS)
list(APPEND LLDB_TEST_DEPS dsymutil)
endif()

if(TARGET lldb-framework)
list(APPEND LLDB_TEST_DEPS lldb-framework)
endif()

add_custom_target(lldb-test-deps)
add_dependencies(lldb-test-deps ${LLDB_TEST_DEPS})
set_target_properties(lldb-test-deps PROPERTIES FOLDER "lldb misc")
Expand Down
29 changes: 29 additions & 0 deletions lldb/cmake/modules/AddLLDB.cmake
Expand Up @@ -208,3 +208,32 @@ function(lldb_setup_framework_rpaths_in_tool name)

add_dependencies(${name} lldb-framework)
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")

# 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}")

# Copy into the framework's Resources directory for testing.
add_custom_command(TARGET ${name} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${name}> ${copy_dest}
COMMENT "Copy ${name} to ${copy_dest}"
)
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.
function(lldb_setup_rpaths name)
cmake_parse_arguments(LIST "" "" "BUILD_RPATH;INSTALL_RPATH" ${ARGN})
set_target_properties(${name} PROPERTIES
BUILD_WITH_INSTALL_RPATH OFF
BUILD_RPATH "${LIST_BUILD_RPATH}"
INSTALL_RPATH "${LIST_INSTALL_RPATH}"
)
endfunction()
2 changes: 0 additions & 2 deletions lldb/cmake/modules/LLDBConfig.cmake
Expand Up @@ -64,8 +64,6 @@ if(LLDB_BUILD_FRAMEWORK)
set(LLDB_FRAMEWORK_VERSION A CACHE STRING "LLDB.framework version (default is A)")
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(LLDB_FRAMEWORK_TOOLS darwin-debug;debugserver;lldb-argdumper;lldb-server CACHE STRING
"List of tools to include in LLDB.framework/Resources")

# Set designated directory for all dSYMs. Essentially, this emits the
# framework's dSYM outside of the framework directory.
Expand Down
15 changes: 1 addition & 14 deletions lldb/cmake/modules/LLDBFramework.cmake
Expand Up @@ -36,22 +36,9 @@ else()
endif()

# Target to capture extra steps for a fully functional framework bundle.
add_custom_target(lldb-framework)
add_custom_target(lldb-framework ALL)
add_dependencies(lldb-framework liblldb)

# Dependencies are defined once tools are added (see AddLLDB.cmake)
if(LLDB_FRAMEWORK_TOOLS)
message(STATUS "LLDB.framework: adding tools ${LLDB_FRAMEWORK_TOOLS}")
foreach(tool ${LLDB_FRAMEWORK_TOOLS})
add_custom_command(TARGET lldb-framework POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${tool}> $<TARGET_FILE_DIR:liblldb>/Resources
COMMENT "LLDB.framework: copy additional tool ${tool}"
)
endforeach()
else()
message(WARNING "LLDB.framework: no additional tools configured (set via LLDB_FRAMEWORK_TOOLS)")
endif()

# Apart from this one, CMake creates all required symlinks in the framework bundle.
add_custom_command(TARGET lldb-framework POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink
Expand Down
4 changes: 4 additions & 0 deletions lldb/tools/argdumper/CMakeLists.txt
Expand Up @@ -4,3 +4,7 @@ add_lldb_tool(lldb-argdumper
LINK_LIBS
lldbUtility
)

if(LLDB_BUILD_FRAMEWORK)
lldb_add_to_framework(lldb-argdumper)
endif()
4 changes: 4 additions & 0 deletions lldb/tools/darwin-debug/CMakeLists.txt
@@ -1,3 +1,7 @@
add_lldb_tool(darwin-debug
darwin-debug.cpp
)

if(LLDB_BUILD_FRAMEWORK)
lldb_add_to_framework(darwin-debug)
endif()
4 changes: 4 additions & 0 deletions lldb/tools/debugserver/source/CMakeLists.txt
Expand Up @@ -265,6 +265,10 @@ if(build_and_sign_debugserver)
${entitlements}
)

if(LLDB_BUILD_FRAMEWORK)
lldb_add_to_framework(debugserver)
endif()

if(IOS)
set_property(TARGET lldbDebugserverCommon APPEND PROPERTY COMPILE_DEFINITIONS
WITH_LOCKDOWN
Expand Down
12 changes: 11 additions & 1 deletion lldb/tools/driver/CMakeLists.txt
Expand Up @@ -31,5 +31,15 @@ add_dependencies(lldb
set_target_properties(LLDBOptionsTableGen PROPERTIES FOLDER "lldb misc")

if(LLDB_BUILD_FRAMEWORK)
lldb_setup_framework_rpaths_in_tool(lldb)
# In the build-tree, we know the exact path to the framework directory.
# The installed framework can be in different locations.
get_target_property(framework_build_dir liblldb LIBRARY_OUTPUT_DIRECTORY)
lldb_setup_rpaths(lldb
BUILD_RPATH
"${framework_build_dir}"
INSTALL_RPATH
"@loader_path/../../../SharedFrameworks"
"@loader_path/../../System/Library/PrivateFrameworks"
"@loader_path/../../Library/PrivateFrameworks"
)
endif()
12 changes: 11 additions & 1 deletion lldb/tools/lldb-mi/CMakeLists.txt
Expand Up @@ -95,5 +95,15 @@ add_lldb_tool(lldb-mi
)

if(LLDB_BUILD_FRAMEWORK)
lldb_setup_framework_rpaths_in_tool(lldb-mi)
# In the build-tree, we know the exact path to the framework directory.
# The installed framework can be in different locations.
get_target_property(framework_build_dir liblldb LIBRARY_OUTPUT_DIRECTORY)
lldb_setup_rpaths(lldb-mi
BUILD_RPATH
"${framework_build_dir}"
INSTALL_RPATH
"@loader_path/../../../SharedFrameworks"
"@loader_path/../../System/Library/PrivateFrameworks"
"@loader_path/../../Library/PrivateFrameworks"
)
endif()
4 changes: 4 additions & 0 deletions lldb/tools/lldb-server/CMakeLists.txt
Expand Up @@ -77,3 +77,7 @@ add_lldb_tool(lldb-server
)

target_link_libraries(lldb-server PRIVATE ${LLDB_SYSTEM_LIBS})

if(LLDB_BUILD_FRAMEWORK)
lldb_add_to_framework(lldb-server)
endif()
12 changes: 11 additions & 1 deletion lldb/tools/lldb-vscode/CMakeLists.txt
Expand Up @@ -31,5 +31,15 @@ add_lldb_tool(lldb-vscode
)

if(LLDB_BUILD_FRAMEWORK)
lldb_setup_framework_rpaths_in_tool(lldb-vscode)
# In the build-tree, we know the exact path to the framework directory.
# The installed framework can be in different locations.
get_target_property(framework_build_dir liblldb LIBRARY_OUTPUT_DIRECTORY)
lldb_setup_rpaths(lldb-vscode
BUILD_RPATH
"${framework_build_dir}"
INSTALL_RPATH
"@loader_path/../../../SharedFrameworks"
"@loader_path/../../System/Library/PrivateFrameworks"
"@loader_path/../../Library/PrivateFrameworks"
)
endif()

0 comments on commit 5dc9036

Please sign in to comment.