Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 1 | include(CheckCXXCompilerFlag) |
| 2 | include(CheckLibraryExists) |
| 3 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/..) |
| 4 | include_directories(${LLDB_SOURCE_DIR}/source) |
| 5 | include_directories(MacOSX/DarwinLog) |
| 6 | |
| 7 | include_directories(MacOSX) |
| 8 | |
Chih-Hung Hsieh | 43f0694 | 2019-12-19 15:01:08 -0800 | [diff] [blame^] | 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 | |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 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") |
| 62 | |
| 63 | check_cxx_compiler_flag("-Wno-gnu-zero-variadic-macro-arguments" |
| 64 | CXX_SUPPORTS_NO_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS) |
| 65 | if (CXX_SUPPORTS_NO_GNU_ZERO_VARIADIC_MACRO_ARGUMENTS) |
| 66 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-gnu-zero-variadic-macro-arguments") |
| 67 | endif () |
| 68 | |
| 69 | check_cxx_compiler_flag("-Wno-zero-length-array" |
| 70 | CXX_SUPPORTS_NO_ZERO_LENGTH_ARRAY) |
| 71 | if (CXX_SUPPORTS_NO_ZERO_LENGTH_ARRAY) |
| 72 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-zero-length-array") |
| 73 | endif () |
| 74 | |
| 75 | check_cxx_compiler_flag("-Wno-extended-offsetof" |
| 76 | CXX_SUPPORTS_NO_EXTENDED_OFFSETOF) |
| 77 | if (CXX_SUPPORTS_NO_EXTENDED_OFFSETOF) |
| 78 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-extended-offsetof") |
| 79 | endif () |
| 80 | |
| 81 | check_library_exists(compression compression_encode_buffer "" HAVE_LIBCOMPRESSION) |
| 82 | |
| 83 | add_subdirectory(MacOSX) |
| 84 | |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 85 | set(LLDB_CODESIGN_IDENTITY "" CACHE STRING |
Chih-Hung Hsieh | 43f0694 | 2019-12-19 15:01:08 -0800 | [diff] [blame^] | 86 | "Identity override for debugserver; see 'Code Signing on macOS' in the documentation (Darwin only)") |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 87 | |
Chih-Hung Hsieh | 43f0694 | 2019-12-19 15:01:08 -0800 | [diff] [blame^] | 88 | get_debugserver_codesign_identity(debugserver_codesign_identity) |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 89 | |
| 90 | # Override locally, so the identity is used for targets created in this scope. |
Chih-Hung Hsieh | 43f0694 | 2019-12-19 15:01:08 -0800 | [diff] [blame^] | 91 | set(LLVM_CODESIGNING_IDENTITY ${debugserver_codesign_identity}) |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 92 | |
Chih-Hung Hsieh | 43f0694 | 2019-12-19 15:01:08 -0800 | [diff] [blame^] | 93 | # Use the same identity later in the test suite. |
| 94 | set_property(GLOBAL PROPERTY |
| 95 | LLDB_DEBUGSERVER_CODESIGN_IDENTITY ${debugserver_codesign_identity}) |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 96 | |
| 97 | if(APPLE) |
| 98 | if(IOS) |
| 99 | find_library(BACKBOARD_LIBRARY BackBoardServices |
| 100 | PATHS ${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks) |
| 101 | find_library(FRONTBOARD_LIBRARY FrontBoardServices |
| 102 | PATHS ${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks) |
| 103 | find_library(SPRINGBOARD_LIBRARY SpringBoardServices |
| 104 | PATHS ${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks) |
| 105 | find_library(MOBILESERVICES_LIBRARY MobileCoreServices |
| 106 | PATHS ${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks) |
| 107 | find_library(LOCKDOWN_LIBRARY lockdown) |
| 108 | |
| 109 | if(NOT BACKBOARD_LIBRARY) |
| 110 | set(SKIP_TEST_DEBUGSERVER ON CACHE BOOL "" FORCE) |
| 111 | endif() |
| 112 | else() |
| 113 | find_library(COCOA_LIBRARY Cocoa) |
| 114 | endif() |
| 115 | endif() |
| 116 | |
| 117 | if(HAVE_LIBCOMPRESSION) |
| 118 | set(LIBCOMPRESSION compression) |
| 119 | endif() |
| 120 | |
| 121 | if(LLDB_USE_ENTITLEMENTS) |
| 122 | if(IOS) |
| 123 | set(entitlements ${CMAKE_CURRENT_SOURCE_DIR}/debugserver-entitlements.plist) |
| 124 | else() |
| 125 | # Same entitlements file as used for lldb-server |
| 126 | set(entitlements ${LLDB_SOURCE_DIR}/resources/debugserver-macosx-entitlements.plist) |
| 127 | endif() |
| 128 | endif() |
| 129 | |
Chih-Hung Hsieh | 43f0694 | 2019-12-19 15:01:08 -0800 | [diff] [blame^] | 130 | #if(build_and_sign_debugserver) |
| 131 | set(generated_mach_interfaces |
| 132 | ${CMAKE_CURRENT_BINARY_DIR}/mach_exc.h |
| 133 | ${CMAKE_CURRENT_BINARY_DIR}/mach_excServer.c |
| 134 | ${CMAKE_CURRENT_BINARY_DIR}/mach_excUser.c |
| 135 | ) |
| 136 | add_custom_command(OUTPUT ${generated_mach_interfaces} |
| 137 | COMMAND mig ${CMAKE_CURRENT_SOURCE_DIR}/MacOSX/dbgnub-mig.defs |
| 138 | DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/MacOSX/dbgnub-mig.defs |
| 139 | ) |
| 140 | |
| 141 | set(DEBUGSERVER_VERS_GENERATED_FILE ${CMAKE_CURRENT_BINARY_DIR}/debugserver_vers.c) |
| 142 | set_source_files_properties(${DEBUGSERVER_VERS_GENERATED_FILE} PROPERTIES GENERATED 1) |
| 143 | |
| 144 | add_custom_command(OUTPUT ${DEBUGSERVER_VERS_GENERATED_FILE} |
| 145 | COMMAND ${LLDB_SOURCE_DIR}/scripts/generate-vers.pl |
| 146 | ${LLDB_SOURCE_DIR}/lldb.xcodeproj/project.pbxproj debugserver |
| 147 | > ${DEBUGSERVER_VERS_GENERATED_FILE} |
| 148 | DEPENDS ${LLDB_SOURCE_DIR}/scripts/generate-vers.pl |
| 149 | ${LLDB_SOURCE_DIR}/lldb.xcodeproj/project.pbxproj |
| 150 | ) |
| 151 | |
| 152 | set(lldbDebugserverCommonSources |
| 153 | DNBArch.cpp |
| 154 | DNBBreakpoint.cpp |
| 155 | DNB.cpp |
| 156 | DNBDataRef.cpp |
| 157 | DNBError.cpp |
| 158 | DNBLog.cpp |
| 159 | DNBRegisterInfo.cpp |
| 160 | DNBThreadResumeActions.cpp |
| 161 | JSON.cpp |
| 162 | StdStringExtractor.cpp |
| 163 | # JSON reader depends on the following LLDB-common files |
| 164 | ${LLDB_SOURCE_DIR}/source/Host/common/StringConvert.cpp |
| 165 | ${LLDB_SOURCE_DIR}/source/Host/common/SocketAddress.cpp |
| 166 | # end JSON reader dependencies |
| 167 | libdebugserver.cpp |
| 168 | PseudoTerminal.cpp |
| 169 | PThreadEvent.cpp |
| 170 | PThreadMutex.cpp |
| 171 | RNBContext.cpp |
| 172 | RNBRemote.cpp |
| 173 | RNBServices.cpp |
| 174 | RNBSocket.cpp |
| 175 | SysSignal.cpp |
| 176 | TTYState.cpp |
| 177 | |
| 178 | MacOSX/CFBundle.cpp |
| 179 | MacOSX/CFString.cpp |
| 180 | MacOSX/Genealogy.cpp |
| 181 | MacOSX/MachException.cpp |
| 182 | MacOSX/MachProcess.mm |
| 183 | MacOSX/MachTask.mm |
| 184 | MacOSX/MachThread.cpp |
| 185 | MacOSX/MachThreadList.cpp |
| 186 | MacOSX/MachVMMemory.cpp |
| 187 | MacOSX/MachVMRegion.cpp |
| 188 | MacOSX/OsLogger.cpp |
| 189 | ${generated_mach_interfaces} |
| 190 | ${DEBUGSERVER_VERS_GENERATED_FILE}) |
| 191 | |
| 192 | add_library(lldbDebugserverCommon ${lldbDebugserverCommonSources}) |
| 193 | set_target_properties(lldbDebugserverCommon PROPERTIES FOLDER "lldb libraries/debugserver") |
| 194 | |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 195 | target_link_libraries(lldbDebugserverCommon |
| 196 | INTERFACE ${COCOA_LIBRARY} |
| 197 | ${CORE_FOUNDATION_LIBRARY} |
| 198 | ${FOUNDATION_LIBRARY} |
| 199 | ${BACKBOARD_LIBRARY} |
| 200 | ${FRONTBOARD_LIBRARY} |
| 201 | ${SPRINGBOARD_LIBRARY} |
| 202 | ${MOBILESERVICES_LIBRARY} |
| 203 | ${LOCKDOWN_LIBRARY} |
| 204 | lldbDebugserverArchSupport |
| 205 | lldbDebugserverDarwin_DarwinLog |
| 206 | ${LIBCOMPRESSION}) |
| 207 | if(HAVE_LIBCOMPRESSION) |
| 208 | set_property(TARGET lldbDebugserverCommon APPEND PROPERTY |
| 209 | COMPILE_DEFINITIONS HAVE_LIBCOMPRESSION) |
| 210 | endif() |
| 211 | set(LLVM_OPTIONAL_SOURCES ${lldbDebugserverCommonSources}) |
Chih-Hung Hsieh | 43f0694 | 2019-12-19 15:01:08 -0800 | [diff] [blame^] | 212 | add_lldb_tool(debugserver ADD_TO_FRAMEWORK |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 213 | debugserver.cpp |
Chih-Hung Hsieh | 43f0694 | 2019-12-19 15:01:08 -0800 | [diff] [blame^] | 214 | LINK_LIBS lldbDebugserverCommon |
| 215 | ENTITLEMENTS ${entitlements} |
| 216 | ) |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 217 | |
Chih-Hung Hsieh | 43f0694 | 2019-12-19 15:01:08 -0800 | [diff] [blame^] | 218 | set_target_properties(debugserver PROPERTIES FOLDER "lldb libraries/debugserver") |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 219 | |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 220 | if(IOS) |
| 221 | set_property(TARGET lldbDebugserverCommon APPEND PROPERTY COMPILE_DEFINITIONS |
| 222 | WITH_LOCKDOWN |
| 223 | WITH_FBS |
| 224 | WITH_BKS |
| 225 | ) |
| 226 | set_property(TARGET debugserver APPEND PROPERTY COMPILE_DEFINITIONS |
| 227 | WITH_LOCKDOWN |
| 228 | WITH_FBS |
| 229 | WITH_BKS |
| 230 | ) |
| 231 | set_property(TARGET lldbDebugserverCommon APPEND PROPERTY COMPILE_FLAGS |
| 232 | -F${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks |
| 233 | ) |
Chih-Hung Hsieh | 43f0694 | 2019-12-19 15:01:08 -0800 | [diff] [blame^] | 234 | |
| 235 | add_library(lldbDebugserverCommon_NonUI ${lldbDebugserverCommonSources}) |
| 236 | target_link_libraries(lldbDebugserverCommon_NonUI |
| 237 | INTERFACE ${COCOA_LIBRARY} |
| 238 | ${CORE_FOUNDATION_LIBRARY} |
| 239 | ${FOUNDATION_LIBRARY} |
| 240 | lldbDebugserverArchSupport |
| 241 | lldbDebugserverDarwin_DarwinLog |
| 242 | ${LIBCOMPRESSION}) |
| 243 | if(HAVE_LIBCOMPRESSION) |
| 244 | set_property(TARGET lldbDebugserverCommon_NonUI APPEND PROPERTY |
| 245 | COMPILE_DEFINITIONS HAVE_LIBCOMPRESSION) |
| 246 | endif() |
| 247 | |
| 248 | add_lldb_tool(debugserver-nonui |
| 249 | debugserver.cpp |
| 250 | |
| 251 | LINK_LIBS |
| 252 | lldbDebugserverCommon_NonUI |
| 253 | |
| 254 | ENTITLEMENTS |
| 255 | ${entitlements} |
| 256 | ) |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 257 | endif() |
Chih-Hung Hsieh | 43f0694 | 2019-12-19 15:01:08 -0800 | [diff] [blame^] | 258 | #endif() |