@@ -6,6 +6,58 @@ include_directories(MacOSX/DarwinLog)
6
6
7
7
include_directories (MacOSX)
8
8
9
+ function (check_certificate identity result_valid)
10
+ execute_process (
11
+ COMMAND security find -certificate -Z -p -c ${identity} /Library/Keychains/System .keychain
12
+ RESULT_VARIABLE exit_code OUTPUT_QUIET ERROR_QUIET)
13
+ if (exit_code)
14
+ set (${result_valid} FALSE PARENT_SCOPE)
15
+ else ()
16
+ set (${result_valid} TRUE PARENT_SCOPE)
17
+ endif ()
18
+ endfunction ()
19
+
20
+ function (get_debugserver_codesign_identity result)
21
+ string (CONCAT not_found_help
22
+ "This will cause failures in the test suite."
23
+ "Pass '-DLLDB_USE_SYSTEM_DEBUGSERVER=ON' to use the system one instead."
24
+ "See 'Code Signing on macOS' in the documentation."
25
+ )
26
+
27
+ # Explicit override: warn if unavailable
28
+ if (LLDB_CODESIGN_IDENTITY)
29
+ set (${result} ${LLDB_CODESIGN_IDENTITY} PARENT_SCOPE)
30
+ check_certificate(${LLDB_CODESIGN_IDENTITY} available)
31
+ if (NOT available AND NOT LLDB_USE_SYSTEM_DEBUGSERVER)
32
+ message (WARNING "LLDB_CODESIGN_IDENTITY not found: '${LLDB_CODESIGN_IDENTITY} ' ${not_found_help} " )
33
+ endif ()
34
+ return ()
35
+ endif ()
36
+
37
+ # Development signing identity: use if available
38
+ check_certificate(lldb_codesign available)
39
+ if (available)
40
+ set (${result} lldb_codesign PARENT_SCOPE)
41
+ return ()
42
+ endif ()
43
+
44
+ if (NOT LLDB_USE_SYSTEM_DEBUGSERVER)
45
+ message (WARNING "Development code sign identiy not found: 'lldb_codesign' ${not_found_help} " )
46
+ endif ()
47
+
48
+ # LLVM pendant: fallback if available
49
+ if (LLVM_CODESIGNING_IDENTITY)
50
+ check_certificate(${LLVM_CODESIGNING_IDENTITY} available)
51
+ if (available)
52
+ set (${result} ${LLVM_CODESIGNING_IDENTITY} PARENT_SCOPE)
53
+ return ()
54
+ endif ()
55
+ endif ()
56
+
57
+ # Ad-hoc signing: last resort
58
+ set (${result} "-" PARENT_SCOPE)
59
+ endfunction ()
60
+
9
61
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -Wl,-sectcreate,__TEXT,__info_plist,${CMAKE_CURRENT_SOURCE_DIR} /../resources/lldb-debugserver-Info.plist" )
10
62
11
63
check_cxx_compiler_flag("-Wno-gnu-zero-variadic-macro-arguments"
@@ -30,132 +82,17 @@ check_library_exists(compression compression_encode_buffer "" HAVE_LIBCOMPRESSIO
30
82
31
83
add_subdirectory (MacOSX)
32
84
33
- # LLDB-specific identity, currently used for code signing debugserver.
34
85
set (LLDB_CODESIGN_IDENTITY "" CACHE STRING
35
- "Override code sign identity for debugserver and for use in tests; falls back to LLVM_CODESIGNING_IDENTITY if set or lldb_codesign otherwise (Darwin only)" )
36
-
37
- # Determine which identity to use and store it in the separate cache entry.
38
- # We will query it later for LLDB_TEST_COMMON_ARGS.
39
- if (LLDB_CODESIGN_IDENTITY)
40
- set (LLDB_CODESIGN_IDENTITY_USED ${LLDB_CODESIGN_IDENTITY} CACHE INTERNAL "" FORCE)
41
- elseif (LLVM_CODESIGNING_IDENTITY)
42
- set (LLDB_CODESIGN_IDENTITY_USED ${LLVM_CODESIGNING_IDENTITY} CACHE INTERNAL "" FORCE)
43
- else ()
44
- set (LLDB_CODESIGN_IDENTITY_USED lldb_codesign CACHE INTERNAL "" FORCE)
45
- endif ()
86
+ "Identity override for debugserver; see 'Code Signing on macOS' in the documentation (Darwin only)" )
46
87
47
- # Override locally, so the identity is used for targets created in this scope.
48
- set (LLVM_CODESIGNING_IDENTITY ${LLDB_CODESIGN_IDENTITY_USED} )
49
-
50
- option (LLDB_NO_DEBUGSERVER "Disable the debugserver target" OFF )
51
- option (LLDB_USE_SYSTEM_DEBUGSERVER "Use the system's debugserver instead of building it from source (Darwin only)." OFF )
88
+ get_debugserver_codesign_identity(debugserver_codesign_identity)
52
89
53
- # Incompatible options
54
- if (LLDB_NO_DEBUGSERVER AND LLDB_USE_SYSTEM_DEBUGSERVER)
55
- message (FATAL_ERROR "Inconsistent options: LLDB_NO_DEBUGSERVER and LLDB_USE_SYSTEM_DEBUGSERVER" )
56
- endif ()
57
-
58
- # Try to locate the system debugserver.
59
- # Subsequent feasibility checks depend on it.
60
- if (APPLE AND CMAKE_HOST_APPLE )
61
- execute_process (
62
- COMMAND xcode-select -p
63
- OUTPUT_VARIABLE xcode_dev_dir)
64
- string (STRIP ${xcode_dev_dir} xcode_dev_dir)
65
-
66
- set (debugserver_rel_path "LLDB.framework/Resources/debugserver" )
67
- set (debugserver_shared "${xcode_dev_dir} /../SharedFrameworks/${debugserver_rel_path} " )
68
- set (debugserver_private "${xcode_dev_dir} /Library/PrivateFrameworks/${debugserver_rel_path} " )
69
-
70
- if (EXISTS ${debugserver_shared} )
71
- set (system_debugserver ${debugserver_shared} )
72
- elseif (EXISTS ${debugserver_private} )
73
- set (system_debugserver ${debugserver_private} )
74
- endif ()
75
- endif ()
76
-
77
- # Handle unavailability
78
- if (LLDB_USE_SYSTEM_DEBUGSERVER)
79
- if (system_debugserver)
80
- set (use_system_debugserver ON )
81
- elseif (APPLE AND CMAKE_HOST_APPLE )
82
- # Binary not found on system. Keep cached variable, to try again on reconfigure.
83
- message (SEND_ERROR
84
- "LLDB_USE_SYSTEM_DEBUGSERVER option set, but no debugserver found in:\
85
- ${debugserver_shared} \
86
- ${debugserver_private} " )
87
- else ()
88
- # Non-Apple target platform or non-Darwin host. Reset invalid cached variable.
89
- message (WARNING "Reverting invalid option LLDB_USE_SYSTEM_DEBUGSERVER (Darwin only)" )
90
- set (LLDB_USE_SYSTEM_DEBUGSERVER OFF CACHE BOOL "" FORCE)
91
- endif ()
92
- elseif (NOT LLDB_NO_DEBUGSERVER)
93
- # Default case: on Darwin we need the right code signing ID.
94
- # See lldb/docs/code-signing.txt for details.
95
- if (CMAKE_HOST_APPLE AND NOT LLVM_CODESIGNING_IDENTITY STREQUAL "lldb_codesign" )
96
- message (WARNING "Codesigning debugserver with identity ${LLVM_CODESIGNING_IDENTITY} . "
97
- "The usual setup uses the \" lldb_codesign\" identity created with "
98
- "scripts/macos-setup-codesign.sh. As a result your debugserver might "
99
- "not be able to attach to processes.\n "
100
- "Pass -DLLDB_CODESIGN_IDENTITY=lldb_codesign to use the development "
101
- "signing identity." )
102
- endif ()
103
- set (build_and_sign_debugserver ON )
104
- endif ()
105
-
106
- # TODO: We don't use the $<TARGET_FILE:debugserver> generator expression here,
107
- # because the value of DEBUGSERVER_PATH is used to build LLDB_DOTEST_ARGS,
108
- # which is used for configuring lldb-dotest.in, which does not have a generator
109
- # step at the moment.
110
- set (default_debugserver_path "${LLVM_RUNTIME_OUTPUT_INTDIR} /debugserver${CMAKE_EXECUTABLE_SUFFIX} " )
111
-
112
- # Remember where debugserver binary goes and whether or not we have to test it.
113
- set (DEBUGSERVER_PATH "" CACHE FILEPATH "Path to debugserver" )
114
- set (SKIP_TEST_DEBUGSERVER OFF CACHE BOOL "Building the in-tree debugserver was skipped" )
115
-
116
- # Reset values in all cases in order to correctly support reconfigurations.
117
- if (use_system_debugserver)
118
- add_custom_target (debugserver
119
- COMMAND ${CMAKE_COMMAND} -E copy_if_different
120
- ${system_debugserver} ${LLVM_RUNTIME_OUTPUT_INTDIR}
121
- COMMENT "Copying the system debugserver to LLDB's binaries directory." )
122
-
123
- set_target_properties (debugserver PROPERTIES FOLDER "lldb libraries/debugserver" )
124
-
125
- # Don't test debugserver itself.
126
- # Tests that require debugserver will use the copy.
127
- set (DEBUGSERVER_PATH ${default_debugserver_path} CACHE FILEPATH "" FORCE)
128
- set (SKIP_TEST_DEBUGSERVER ON CACHE BOOL "" FORCE)
129
-
130
- message (STATUS "Copy system debugserver from: ${system_debugserver} " )
131
- elseif (build_and_sign_debugserver)
132
- # Build, sign and test debugserver (below)
133
- set (DEBUGSERVER_PATH ${default_debugserver_path} CACHE FILEPATH "" FORCE)
134
- set (SKIP_TEST_DEBUGSERVER OFF CACHE BOOL "" FORCE)
135
-
136
- message (STATUS "lldb debugserver: ${DEBUGSERVER_PATH} " )
137
- else ()
138
- # No tests for debugserver, no tests that require it.
139
- set (DEBUGSERVER_PATH "" CACHE FILEPATH "" FORCE)
140
- set (SKIP_TEST_DEBUGSERVER ON CACHE BOOL "" FORCE)
141
-
142
- message (STATUS "lldb debugserver will not be available." )
143
- endif ()
90
+ # Override locally, so the identity is used for targets created in this scope.
91
+ set (LLVM_CODESIGNING_IDENTITY ${debugserver_codesign_identity} )
144
92
145
- # On MacOS, debugserver needs to be codesigned when built. Check if we have
146
- # a certificate instead of failing in the middle of the build.
147
- if (build_and_sign_debugserver)
148
- execute_process (
149
- COMMAND security find -certificate -Z -p -c ${LLDB_CODESIGN_IDENTITY_USED} /Library/Keychains/System .keychain
150
- RESULT_VARIABLE cert_return
151
- OUTPUT_QUIET
152
- ERROR_QUIET)
153
-
154
- if (cert_return)
155
- message (FATAL_ERROR "Certificate for debugserver not found. Run scripts/macos-setup-codesign.sh or "
156
- "use the system debugserver passing -DLLDB_USE_SYSTEM_DEBUGSERVER=ON to CMake" )
157
- endif ()
158
- endif ()
93
+ # Use the same identity later in the test suite.
94
+ set_property (GLOBAL PROPERTY
95
+ LLDB_DEBUGSERVER_CODESIGN_IDENTITY ${debugserver_codesign_identity} )
159
96
160
97
if (APPLE )
161
98
if (IOS)
@@ -190,7 +127,7 @@ if(LLDB_USE_ENTITLEMENTS)
190
127
endif ()
191
128
endif ()
192
129
193
- if (build_and_sign_debugserver)
130
+ # if(build_and_sign_debugserver)
194
131
set (generated_mach_interfaces
195
132
${CMAKE_CURRENT_BINARY_DIR} /mach_exc.h
196
133
${CMAKE_CURRENT_BINARY_DIR} /mach_excServer.c
@@ -318,4 +255,4 @@ if(build_and_sign_debugserver)
318
255
${entitlements}
319
256
)
320
257
endif ()
321
- endif ()
258
+ # endif()
0 commit comments