1 include(CheckCXXCompilerFlag)
2 include(CheckLibraryExists)
3 include_directories(${CMAKE_CURRENT_BINARY_DIR}/..)
4 include_directories(${LLDB_SOURCE_DIR}/source)
5 include_directories(MacOSX)
6 include_directories(MacOSX/x86_64)
7 include_directories(MacOSX/arm64)
9 function(check_certificate identity result_valid)
11 COMMAND security find-certificate -Z -p -c ${identity} /Library/Keychains/System.keychain
12 RESULT_VARIABLE exit_code OUTPUT_QUIET ERROR_QUIET)
14 set(${result_valid} FALSE PARENT_SCOPE)
16 set(${result_valid} TRUE PARENT_SCOPE)
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."
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)
32 message(WARNING "LLDB_CODESIGN_IDENTITY not found: '${LLDB_CODESIGN_IDENTITY}' ${not_found_help}")
37 # Development signing identity: use if available
38 check_certificate(lldb_codesign available)
40 set(${result} lldb_codesign PARENT_SCOPE)
44 message(WARNING "Development code sign identity not found: 'lldb_codesign' ${not_found_help}")
46 # LLVM pendant: fallback if available
47 if(LLVM_CODESIGNING_IDENTITY)
48 check_certificate(${LLVM_CODESIGNING_IDENTITY} available)
50 set(${result} ${LLVM_CODESIGNING_IDENTITY} PARENT_SCOPE)
55 # Ad-hoc signing: last resort
56 set(${result} "-" PARENT_SCOPE)
59 # debugserver does not depend on intrinsics_gen, or on llvm. Set the common
60 # llvm dependencies in the current scope to the empty set.
61 set(LLVM_COMMON_DEPENDS)
63 set(DEBUGSERVER_RESOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../resources")
64 set(DEBUGSERVER_INFO_PLIST "${DEBUGSERVER_RESOURCE_DIR}/lldb-debugserver-Info.plist")
66 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -Wl,-sectcreate,__TEXT,__info_plist,${DEBUGSERVER_INFO_PLIST}")
68 check_cxx_compiler_flag("-Wno-gnu-zero-variadic-macro-arguments"
69 CXX_SUPPORTS_NO_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS)
70 if (CXX_SUPPORTS_NO_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS)
71 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-gnu-zero-variadic-macro-arguments")
74 check_cxx_compiler_flag("-Wno-zero-length-array"
75 CXX_SUPPORTS_NO_ZERO_LENGTH_ARRAY)
76 if (CXX_SUPPORTS_NO_ZERO_LENGTH_ARRAY)
77 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-zero-length-array")
80 check_cxx_compiler_flag("-Wno-extended-offsetof"
81 CXX_SUPPORTS_NO_EXTENDED_OFFSETOF)
82 if (CXX_SUPPORTS_NO_EXTENDED_OFFSETOF)
83 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-extended-offsetof")
86 include(CheckCSourceCompiles)
87 check_c_source_compiles(
89 #include <TargetConditionals.h>
92 #warning Building for macOS
94 #error Not building for macOS
97 #error Not building for ARM64
99 int main(void) { return 0; }
101 BUILDING_FOR_ARM64_OSX
104 # You can only debug arm64e processes using an arm64e debugserver.
105 option(LLDB_ENABLE_ARM64E_DEBUGSERVER "Build debugserver for arm64 and arm64e" OFF)
106 if (BUILDING_FOR_ARM64_OSX AND LLDB_ENABLE_ARM64E_DEBUGSERVER)
107 set(CMAKE_OSX_ARCHITECTURES "arm64;arm64e")
110 find_library(SECURITY_LIBRARY Security)
112 set(LLDB_CODESIGN_IDENTITY "" CACHE STRING
113 "Identity override for debugserver; see 'Code Signing on macOS' in the documentation (Darwin only)")
115 get_debugserver_codesign_identity(debugserver_codesign_identity)
117 # Override locally, so the identity is used for targets created in this scope.
118 set(LLVM_CODESIGNING_IDENTITY ${debugserver_codesign_identity})
121 set(LIBCOMPRESSION compression)
123 find_library(BACKBOARD_LIBRARY BackBoardServices
124 PATHS ${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks)
125 find_library(FRONTBOARD_LIBRARY FrontBoardServices
126 PATHS ${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks)
127 find_library(SPRINGBOARD_LIBRARY SpringBoardServices
128 PATHS ${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks)
129 find_library(MOBILESERVICES_LIBRARY MobileCoreServices
130 PATHS ${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks)
131 find_library(LOCKDOWN_LIBRARY lockdown)
132 if (APPLE_EMBEDDED STREQUAL "watchos")
133 find_library(CAROUSELSERVICES_LIBRARY CarouselServices
134 PATHS ${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks)
137 if(NOT BACKBOARD_LIBRARY)
138 set(SKIP_TEST_DEBUGSERVER ON CACHE BOOL "" FORCE)
143 if(LLDB_USE_ENTITLEMENTS)
145 set(entitlements ${DEBUGSERVER_RESOURCE_DIR}/debugserver-entitlements.plist)
147 if (LLDB_USE_PRIVATE_ENTITLEMENTS)
148 set(entitlements ${DEBUGSERVER_RESOURCE_DIR}/debugserver-macosx-private-entitlements.plist)
150 set(entitlements ${DEBUGSERVER_RESOURCE_DIR}/debugserver-macosx-entitlements.plist)
155 add_definitions(-DLLDB_USE_OS_LOG)
157 if(${CMAKE_OSX_SYSROOT} MATCHES ".Internal.sdk$")
158 message(STATUS "LLDB debugserver energy support is enabled")
159 add_definitions(-DLLDB_ENERGY)
160 set(ENERGY_LIBRARY -lpmenergy -lpmsample)
162 message(STATUS "LLDB debugserver energy support is disabled")
165 set(generated_mach_interfaces
166 ${CMAKE_CURRENT_BINARY_DIR}/mach_exc.h
167 ${CMAKE_CURRENT_BINARY_DIR}/mach_excServer.c
168 ${CMAKE_CURRENT_BINARY_DIR}/mach_excUser.c
171 set(MIG_ARCH_FLAGS "")
172 if (DEFINED MIG_ARCHS)
173 foreach(ARCH ${MIG_ARCHS})
174 set(MIG_ARCH_FLAGS "${MIG_ARCH_FLAGS} -arch ${ARCH}")
177 separate_arguments(MIG_ARCH_FLAGS_SEPARTED NATIVE_COMMAND "${MIG_ARCH_FLAGS}")
179 add_custom_command(OUTPUT ${generated_mach_interfaces}
180 VERBATIM COMMAND mig ${MIG_ARCH_FLAGS_SEPARTED} -isysroot ${CMAKE_OSX_SYSROOT} ${CMAKE_CURRENT_SOURCE_DIR}/MacOSX/dbgnub-mig.defs
181 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/MacOSX/dbgnub-mig.defs
184 set(DEBUGSERVER_VERS_GENERATED_FILE ${CMAKE_CURRENT_BINARY_DIR}/debugserver_vers.c)
185 configure_file(debugserver_vers.c.in
186 ${DEBUGSERVER_VERS_GENERATED_FILE} @ONLY)
188 set(lldbDebugserverCommonSources
196 DNBThreadResumeActions.cpp
198 StdStringExtractor.cpp
200 # JSON reader depends on the following LLDB-common files
201 ${LLDB_SOURCE_DIR}/source/Host/common/SocketAddress.cpp
202 # end JSON reader dependencies
217 MacOSX/MachException.cpp
218 MacOSX/MachProcess.mm
220 MacOSX/MachThread.cpp
221 MacOSX/MachThreadList.cpp
222 MacOSX/MachVMMemory.cpp
223 MacOSX/MachVMRegion.cpp
225 MacOSX/arm64/DNBArchImplARM64.cpp
226 MacOSX/x86_64/DNBArchImplX86_64.cpp
227 ${generated_mach_interfaces}
228 ${DEBUGSERVER_VERS_GENERATED_FILE})
230 # Tell LLVM not to complain about these source files.
231 set(LLVM_OPTIONAL_SOURCES
232 ${lldbDebugserverCommonSources}
235 add_lldb_library(lldbDebugserverCommon ${lldbDebugserverCommonSources})
236 set_target_properties(lldbDebugserverCommon PROPERTIES FOLDER "lldb libraries/debugserver")
238 target_link_libraries(lldbDebugserverCommon
239 INTERFACE ${COCOA_LIBRARY}
240 ${CORE_FOUNDATION_LIBRARY}
241 ${FOUNDATION_LIBRARY}
243 ${FRONTBOARD_LIBRARY}
244 ${SPRINGBOARD_LIBRARY}
245 ${MOBILESERVICES_LIBRARY}
247 ${CAROUSELSERVICES_LIBRARY}
248 ${FOUNDATION_LIBRARY}
252 add_lldb_tool(debugserver ADD_TO_FRAMEWORK
254 LINK_LIBS lldbDebugserverCommon
255 ENTITLEMENTS ${entitlements}
258 # Workaround for Xcode-specific code-signing behavior:
259 # The XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY option causes debugserver to be copied
260 # into the framework first and code-signed afterwards. Sign the copy manually.
261 if (debugserver_codesign_identity AND LLDB_BUILD_FRAMEWORK AND
262 CMAKE_GENERATOR STREQUAL "Xcode")
263 if(NOT CMAKE_CODESIGN_ALLOCATE)
265 COMMAND xcrun -f codesign_allocate
266 OUTPUT_STRIP_TRAILING_WHITESPACE
267 OUTPUT_VARIABLE CMAKE_CODESIGN_ALLOCATE
271 set(pass_entitlements --entitlements ${entitlements})
274 set(copy_location ${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Versions/${LLDB_FRAMEWORK_VERSION}/Resources/debugserver)
276 add_custom_command(TARGET debugserver POST_BUILD
277 COMMAND ${CMAKE_COMMAND} -E
278 env CODESIGN_ALLOCATE=${CMAKE_CODESIGN_ALLOCATE}
279 xcrun codesign -f -s ${debugserver_codesign_identity}
280 ${pass_entitlements} ${copy_location}
281 COMMENT "Code-sign debugserver copy in the build-tree framework: ${copy_location}"
285 set_target_properties(debugserver PROPERTIES FOLDER "lldb libraries/debugserver")
288 set_property(TARGET lldbDebugserverCommon APPEND PROPERTY COMPILE_DEFINITIONS
293 if(CAROUSELSERVICES_LIBRARY)
294 set_property(TARGET lldbDebugserverCommon APPEND PROPERTY COMPILE_DEFINITIONS
298 set_property(TARGET debugserver APPEND PROPERTY COMPILE_DEFINITIONS
303 set_property(TARGET lldbDebugserverCommon APPEND PROPERTY COMPILE_FLAGS
304 -F${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks
307 add_lldb_library(lldbDebugserverCommon_NonUI ${lldbDebugserverCommonSources})
308 target_link_libraries(lldbDebugserverCommon_NonUI
309 INTERFACE ${COCOA_LIBRARY}
310 ${CORE_FOUNDATION_LIBRARY}
311 ${FOUNDATION_LIBRARY}
315 add_lldb_tool(debugserver-nonui
319 lldbDebugserverCommon_NonUI