Skip to content

Commit 5dc9036

Browse files
[CMake] LLDB.framework tools handling
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
1 parent 5b363c1 commit 5dc9036

File tree

11 files changed

+83
-19
lines changed

11 files changed

+83
-19
lines changed

lldb/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ if(LLDB_INCLUDE_TESTS)
151151
list(APPEND LLDB_TEST_DEPS dsymutil)
152152
endif()
153153

154+
if(TARGET lldb-framework)
155+
list(APPEND LLDB_TEST_DEPS lldb-framework)
156+
endif()
157+
154158
add_custom_target(lldb-test-deps)
155159
add_dependencies(lldb-test-deps ${LLDB_TEST_DEPS})
156160
set_target_properties(lldb-test-deps PROPERTIES FOLDER "lldb misc")

lldb/cmake/modules/AddLLDB.cmake

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,32 @@ function(lldb_setup_framework_rpaths_in_tool name)
208208

209209
add_dependencies(${name} lldb-framework)
210210
endfunction()
211+
212+
# Unified handling for executable LLDB.framework resources. Given the name of an
213+
# executable target, this function adds a post-build step to copy it to the
214+
# framework bundle in the build-tree.
215+
function(lldb_add_to_framework name)
216+
set(subdir "LLDB.framework/Versions/${LLDB_FRAMEWORK_VERSION}/Resources")
217+
218+
# Destination for the copy in the build-tree. While the framework target may
219+
# not exist yet, it will exist when the generator expression gets expanded.
220+
set(copy_dest "$<TARGET_FILE_DIR:liblldb>/../../../${subdir}")
221+
222+
# Copy into the framework's Resources directory for testing.
223+
add_custom_command(TARGET ${name} POST_BUILD
224+
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${name}> ${copy_dest}
225+
COMMENT "Copy ${name} to ${copy_dest}"
226+
)
227+
endfunction()
228+
229+
# CMake's set_target_properties() doesn't allow to pass lists for RPATH
230+
# properties directly (error: "called with incorrect number of arguments").
231+
# Instead of defining two list variables each time, use this helper function.
232+
function(lldb_setup_rpaths name)
233+
cmake_parse_arguments(LIST "" "" "BUILD_RPATH;INSTALL_RPATH" ${ARGN})
234+
set_target_properties(${name} PROPERTIES
235+
BUILD_WITH_INSTALL_RPATH OFF
236+
BUILD_RPATH "${LIST_BUILD_RPATH}"
237+
INSTALL_RPATH "${LIST_INSTALL_RPATH}"
238+
)
239+
endfunction()

lldb/cmake/modules/LLDBConfig.cmake

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ if(LLDB_BUILD_FRAMEWORK)
6464
set(LLDB_FRAMEWORK_VERSION A CACHE STRING "LLDB.framework version (default is A)")
6565
set(LLDB_FRAMEWORK_BUILD_DIR bin CACHE STRING "Output directory for LLDB.framework")
6666
set(LLDB_FRAMEWORK_INSTALL_DIR Library/Frameworks CACHE STRING "Install directory for LLDB.framework")
67-
set(LLDB_FRAMEWORK_TOOLS darwin-debug;debugserver;lldb-argdumper;lldb-server CACHE STRING
68-
"List of tools to include in LLDB.framework/Resources")
6967

7068
# Set designated directory for all dSYMs. Essentially, this emits the
7169
# framework's dSYM outside of the framework directory.

lldb/cmake/modules/LLDBFramework.cmake

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,9 @@ else()
3636
endif()
3737

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

42-
# Dependencies are defined once tools are added (see AddLLDB.cmake)
43-
if(LLDB_FRAMEWORK_TOOLS)
44-
message(STATUS "LLDB.framework: adding tools ${LLDB_FRAMEWORK_TOOLS}")
45-
foreach(tool ${LLDB_FRAMEWORK_TOOLS})
46-
add_custom_command(TARGET lldb-framework POST_BUILD
47-
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${tool}> $<TARGET_FILE_DIR:liblldb>/Resources
48-
COMMENT "LLDB.framework: copy additional tool ${tool}"
49-
)
50-
endforeach()
51-
else()
52-
message(WARNING "LLDB.framework: no additional tools configured (set via LLDB_FRAMEWORK_TOOLS)")
53-
endif()
54-
5542
# Apart from this one, CMake creates all required symlinks in the framework bundle.
5643
add_custom_command(TARGET lldb-framework POST_BUILD
5744
COMMAND ${CMAKE_COMMAND} -E create_symlink

lldb/tools/argdumper/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ add_lldb_tool(lldb-argdumper
44
LINK_LIBS
55
lldbUtility
66
)
7+
8+
if(LLDB_BUILD_FRAMEWORK)
9+
lldb_add_to_framework(lldb-argdumper)
10+
endif()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
add_lldb_tool(darwin-debug
22
darwin-debug.cpp
33
)
4+
5+
if(LLDB_BUILD_FRAMEWORK)
6+
lldb_add_to_framework(darwin-debug)
7+
endif()

lldb/tools/debugserver/source/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ if(build_and_sign_debugserver)
265265
${entitlements}
266266
)
267267

268+
if(LLDB_BUILD_FRAMEWORK)
269+
lldb_add_to_framework(debugserver)
270+
endif()
271+
268272
if(IOS)
269273
set_property(TARGET lldbDebugserverCommon APPEND PROPERTY COMPILE_DEFINITIONS
270274
WITH_LOCKDOWN

lldb/tools/driver/CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,15 @@ add_dependencies(lldb
3131
set_target_properties(LLDBOptionsTableGen PROPERTIES FOLDER "lldb misc")
3232

3333
if(LLDB_BUILD_FRAMEWORK)
34-
lldb_setup_framework_rpaths_in_tool(lldb)
34+
# In the build-tree, we know the exact path to the framework directory.
35+
# The installed framework can be in different locations.
36+
get_target_property(framework_build_dir liblldb LIBRARY_OUTPUT_DIRECTORY)
37+
lldb_setup_rpaths(lldb
38+
BUILD_RPATH
39+
"${framework_build_dir}"
40+
INSTALL_RPATH
41+
"@loader_path/../../../SharedFrameworks"
42+
"@loader_path/../../System/Library/PrivateFrameworks"
43+
"@loader_path/../../Library/PrivateFrameworks"
44+
)
3545
endif()

lldb/tools/lldb-mi/CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,15 @@ add_lldb_tool(lldb-mi
9595
)
9696

9797
if(LLDB_BUILD_FRAMEWORK)
98-
lldb_setup_framework_rpaths_in_tool(lldb-mi)
98+
# In the build-tree, we know the exact path to the framework directory.
99+
# The installed framework can be in different locations.
100+
get_target_property(framework_build_dir liblldb LIBRARY_OUTPUT_DIRECTORY)
101+
lldb_setup_rpaths(lldb-mi
102+
BUILD_RPATH
103+
"${framework_build_dir}"
104+
INSTALL_RPATH
105+
"@loader_path/../../../SharedFrameworks"
106+
"@loader_path/../../System/Library/PrivateFrameworks"
107+
"@loader_path/../../Library/PrivateFrameworks"
108+
)
99109
endif()

lldb/tools/lldb-server/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,7 @@ add_lldb_tool(lldb-server
7777
)
7878

7979
target_link_libraries(lldb-server PRIVATE ${LLDB_SYSTEM_LIBS})
80+
81+
if(LLDB_BUILD_FRAMEWORK)
82+
lldb_add_to_framework(lldb-server)
83+
endif()

lldb/tools/lldb-vscode/CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,15 @@ add_lldb_tool(lldb-vscode
3131
)
3232

3333
if(LLDB_BUILD_FRAMEWORK)
34-
lldb_setup_framework_rpaths_in_tool(lldb-vscode)
34+
# In the build-tree, we know the exact path to the framework directory.
35+
# The installed framework can be in different locations.
36+
get_target_property(framework_build_dir liblldb LIBRARY_OUTPUT_DIRECTORY)
37+
lldb_setup_rpaths(lldb-vscode
38+
BUILD_RPATH
39+
"${framework_build_dir}"
40+
INSTALL_RPATH
41+
"@loader_path/../../../SharedFrameworks"
42+
"@loader_path/../../System/Library/PrivateFrameworks"
43+
"@loader_path/../../Library/PrivateFrameworks"
44+
)
3545
endif()

0 commit comments

Comments
 (0)