1 include(CheckCXXCompilerFlag)
2 include(CheckLibraryExists)
3 include_directories(${CMAKE_CURRENT_BINARY_DIR}/..)
4 include_directories(${LLDB_SOURCE_DIR}/source)
6 include_directories(MacOSX)
8 function(check_certificate identity result_valid)
10 COMMAND security find-certificate -Z -p -c ${identity} /Library/Keychains/System.keychain
11 RESULT_VARIABLE exit_code OUTPUT_QUIET ERROR_QUIET)
13 set(${result_valid} FALSE PARENT_SCOPE)
15 set(${result_valid} TRUE PARENT_SCOPE)
19 function(get_debugserver_codesign_identity result)
20 string(CONCAT not_found_help
21 "This will cause failures in the test suite."
22 "Pass '-DLLDB_USE_SYSTEM_DEBUGSERVER=ON' to use the system one instead."
23 "See 'Code Signing on macOS' in the documentation."
26 # Explicit override: warn if unavailable
27 if(LLDB_CODESIGN_IDENTITY)
28 set(${result} ${LLDB_CODESIGN_IDENTITY} PARENT_SCOPE)
29 check_certificate(${LLDB_CODESIGN_IDENTITY} available)
31 message(WARNING "LLDB_CODESIGN_IDENTITY not found: '${LLDB_CODESIGN_IDENTITY}' ${not_found_help}")
36 # Development signing identity: use if available
37 check_certificate(lldb_codesign available)
39 set(${result} lldb_codesign PARENT_SCOPE)
43 message(WARNING "Development code sign identity not found: 'lldb_codesign' ${not_found_help}")
45 # LLVM pendant: fallback if available
46 if(LLVM_CODESIGNING_IDENTITY)
47 check_certificate(${LLVM_CODESIGNING_IDENTITY} available)
49 set(${result} ${LLVM_CODESIGNING_IDENTITY} PARENT_SCOPE)
54 # Ad-hoc signing: last resort
55 set(${result} "-" PARENT_SCOPE)
58 # debugserver does not depend on intrinsics_gen, or on llvm. Set the common
59 # llvm dependencies in the current scope to the empty set.
60 set(LLVM_COMMON_DEPENDS)
62 set(DEBUGSERVER_RESOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../resources")
63 set(DEBUGSERVER_INFO_PLIST "${DEBUGSERVER_RESOURCE_DIR}/lldb-debugserver-Info.plist")
65 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -Wl,-sectcreate,__TEXT,__info_plist,${DEBUGSERVER_INFO_PLIST}")
67 check_cxx_compiler_flag("-Wno-gnu-zero-variadic-macro-arguments"
68 CXX_SUPPORTS_NO_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS)
69 if (CXX_SUPPORTS_NO_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS)
70 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-gnu-zero-variadic-macro-arguments")
73 check_cxx_compiler_flag("-Wno-zero-length-array"
74 CXX_SUPPORTS_NO_ZERO_LENGTH_ARRAY)
75 if (CXX_SUPPORTS_NO_ZERO_LENGTH_ARRAY)
76 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-zero-length-array")
79 check_cxx_compiler_flag("-Wno-extended-offsetof"
80 CXX_SUPPORTS_NO_EXTENDED_OFFSETOF)
81 if (CXX_SUPPORTS_NO_EXTENDED_OFFSETOF)
82 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-extended-offsetof")
85 include(CheckCSourceCompiles)
86 check_c_source_compiles(
88 #include <TargetConditionals.h>
91 #warning Building for macOS
93 #error Not building for macOS
96 #error Not building for ARM64
98 int main() { return 0; }
100 BUILDING_FOR_ARM64_OSX
103 # You can only debug arm64e processes using an arm64e debugserver.
104 option(LLDB_ENABLE_ARM64E_DEBUGSERVER "Build debugserver for arm64 and arm64e" OFF)
105 if (BUILDING_FOR_ARM64_OSX AND LLDB_ENABLE_ARM64E_DEBUGSERVER)
106 set(CMAKE_OSX_ARCHITECTURES "arm64;arm64e")
109 check_library_exists(compression compression_encode_buffer "" HAVE_LIBCOMPRESSION)
111 find_library(SECURITY_LIBRARY Security)
113 add_subdirectory(MacOSX)
115 set(LLDB_CODESIGN_IDENTITY "" CACHE STRING
116 "Identity override for debugserver; see 'Code Signing on macOS' in the documentation (Darwin only)")
118 get_debugserver_codesign_identity(debugserver_codesign_identity)
120 # Override locally, so the identity is used for targets created in this scope.
121 set(LLVM_CODESIGNING_IDENTITY ${debugserver_codesign_identity})
123 # Use the same identity later in the test suite.
124 set_property(GLOBAL PROPERTY
125 LLDB_DEBUGSERVER_CODESIGN_IDENTITY ${debugserver_codesign_identity})
129 find_library(BACKBOARD_LIBRARY BackBoardServices
130 PATHS ${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks)
131 find_library(FRONTBOARD_LIBRARY FrontBoardServices
132 PATHS ${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks)
133 find_library(SPRINGBOARD_LIBRARY SpringBoardServices
134 PATHS ${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks)
135 find_library(MOBILESERVICES_LIBRARY MobileCoreServices
136 PATHS ${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks)
137 find_library(LOCKDOWN_LIBRARY lockdown)
138 if (APPLE_EMBEDDED STREQUAL "watchos")
139 find_library(CAROUSELSERVICES_LIBRARY CarouselServices
140 PATHS ${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks)
143 if(NOT BACKBOARD_LIBRARY)
144 set(SKIP_TEST_DEBUGSERVER ON CACHE BOOL "" FORCE)
149 if(HAVE_LIBCOMPRESSION)
150 set(LIBCOMPRESSION compression)
153 if(LLDB_USE_ENTITLEMENTS)
155 set(entitlements ${DEBUGSERVER_RESOURCE_DIR}/debugserver-entitlements.plist)
157 if (LLDB_USE_PRIVATE_ENTITLEMENTS)
158 set(entitlements ${DEBUGSERVER_RESOURCE_DIR}/debugserver-macosx-private-entitlements.plist)
160 set(entitlements ${DEBUGSERVER_RESOURCE_DIR}/debugserver-macosx-entitlements.plist)
165 add_definitions(-DLLDB_USE_OS_LOG)
167 if(${CMAKE_OSX_SYSROOT} MATCHES ".Internal.sdk$")
168 message(STATUS "LLDB debugserver energy support is enabled")
169 add_definitions(-DLLDB_ENERGY)
170 set(ENERGY_LIBRARY -lpmenergy -lpmsample)
172 message(STATUS "LLDB debugserver energy support is disabled")
175 set(generated_mach_interfaces
176 ${CMAKE_CURRENT_BINARY_DIR}/mach_exc.h
177 ${CMAKE_CURRENT_BINARY_DIR}/mach_excServer.c
178 ${CMAKE_CURRENT_BINARY_DIR}/mach_excUser.c
181 set(MIG_ARCH_FLAGS "")
182 if (DEFINED MIG_ARCHS)
183 foreach(ARCH ${MIG_ARCHS})
184 set(MIG_ARCH_FLAGS "${MIG_ARCH_FLAGS} -arch ${ARCH}")
187 separate_arguments(MIG_ARCH_FLAGS_SEPARTED NATIVE_COMMAND "${MIG_ARCH_FLAGS}")
189 add_custom_command(OUTPUT ${generated_mach_interfaces}
190 VERBATIM COMMAND mig ${MIG_ARCH_FLAGS_SEPARTED} -isysroot ${CMAKE_OSX_SYSROOT} ${CMAKE_CURRENT_SOURCE_DIR}/MacOSX/dbgnub-mig.defs
191 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/MacOSX/dbgnub-mig.defs
194 set(DEBUGSERVER_VERS_GENERATED_FILE ${CMAKE_CURRENT_BINARY_DIR}/debugserver_vers.c)
195 configure_file(debugserver_vers.c.in
196 ${DEBUGSERVER_VERS_GENERATED_FILE} @ONLY)
198 set(lldbDebugserverCommonSources
206 DNBThreadResumeActions.cpp
208 StdStringExtractor.cpp
210 # JSON reader depends on the following LLDB-common files
211 ${LLDB_SOURCE_DIR}/source/Host/common/SocketAddress.cpp
212 # end JSON reader dependencies
227 MacOSX/MachException.cpp
228 MacOSX/MachProcess.mm
230 MacOSX/MachThread.cpp
231 MacOSX/MachThreadList.cpp
232 MacOSX/MachVMMemory.cpp
233 MacOSX/MachVMRegion.cpp
235 ${generated_mach_interfaces}
236 ${DEBUGSERVER_VERS_GENERATED_FILE})
238 # Tell LLVM not to complain about these source files.
239 set(LLVM_OPTIONAL_SOURCES
240 ${lldbDebugserverCommonSources}
243 add_lldb_library(lldbDebugserverCommon ${lldbDebugserverCommonSources})
244 set_target_properties(lldbDebugserverCommon PROPERTIES FOLDER "lldb libraries/debugserver")
246 target_link_libraries(lldbDebugserverCommon
247 INTERFACE ${COCOA_LIBRARY}
248 ${CORE_FOUNDATION_LIBRARY}
249 ${FOUNDATION_LIBRARY}
251 ${FRONTBOARD_LIBRARY}
252 ${SPRINGBOARD_LIBRARY}
253 ${MOBILESERVICES_LIBRARY}
255 ${CAROUSELSERVICES_LIBRARY}
256 lldbDebugserverArchSupport
257 ${FOUNDATION_LIBRARY}
261 if(HAVE_LIBCOMPRESSION)
262 set_property(TARGET lldbDebugserverCommon APPEND PROPERTY
263 COMPILE_DEFINITIONS HAVE_LIBCOMPRESSION)
265 add_lldb_tool(debugserver ADD_TO_FRAMEWORK
267 LINK_LIBS lldbDebugserverCommon
268 ENTITLEMENTS ${entitlements}
271 # Workaround for Xcode-specific code-signing behavior:
272 # The XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY option causes debugserver to be copied
273 # into the framework first and code-signed afterwards. Sign the copy manually.
274 if (debugserver_codesign_identity AND LLDB_BUILD_FRAMEWORK AND
275 CMAKE_GENERATOR STREQUAL "Xcode")
276 if(NOT CMAKE_CODESIGN_ALLOCATE)
278 COMMAND xcrun -f codesign_allocate
279 OUTPUT_STRIP_TRAILING_WHITESPACE
280 OUTPUT_VARIABLE CMAKE_CODESIGN_ALLOCATE
284 set(pass_entitlements --entitlements ${entitlements})
287 set(copy_location ${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Versions/${LLDB_FRAMEWORK_VERSION}/Resources/debugserver)
289 add_custom_command(TARGET debugserver POST_BUILD
290 COMMAND ${CMAKE_COMMAND} -E
291 env CODESIGN_ALLOCATE=${CMAKE_CODESIGN_ALLOCATE}
292 xcrun codesign -f -s ${debugserver_codesign_identity}
293 ${pass_entitlements} ${copy_location}
294 COMMENT "Code-sign debugserver copy in the build-tree framework: ${copy_location}"
298 set_target_properties(debugserver PROPERTIES FOLDER "lldb libraries/debugserver")
301 set_property(TARGET lldbDebugserverCommon APPEND PROPERTY COMPILE_DEFINITIONS
306 if(CAROUSELSERVICES_LIBRARY)
307 set_property(TARGET lldbDebugserverCommon APPEND PROPERTY COMPILE_DEFINITIONS
311 set_property(TARGET debugserver APPEND PROPERTY COMPILE_DEFINITIONS
316 set_property(TARGET lldbDebugserverCommon APPEND PROPERTY COMPILE_FLAGS
317 -F${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks
320 add_lldb_library(lldbDebugserverCommon_NonUI ${lldbDebugserverCommonSources})
321 target_link_libraries(lldbDebugserverCommon_NonUI
322 INTERFACE ${COCOA_LIBRARY}
323 ${CORE_FOUNDATION_LIBRARY}
324 ${FOUNDATION_LIBRARY}
325 lldbDebugserverArchSupport
328 if(HAVE_LIBCOMPRESSION)
329 set_property(TARGET lldbDebugserverCommon_NonUI APPEND PROPERTY
330 COMPILE_DEFINITIONS HAVE_LIBCOMPRESSION)
333 add_lldb_tool(debugserver-nonui
337 lldbDebugserverCommon_NonUI