[clang] Fix implicit integer conversion for opaque enums declared in class templates...
[llvm-project.git] / lldb / tools / debugserver / source / CMakeLists.txt
blob1a433898f6aa48baa701e87df565a8243e40a08a
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)
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()
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   )
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)
32       message(WARNING "LLDB_CODESIGN_IDENTITY not found: '${LLDB_CODESIGN_IDENTITY}' ${not_found_help}")
33     endif()
34     return()
35   endif()
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()
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)
49     if(available)
50       set(${result} ${LLVM_CODESIGNING_IDENTITY} PARENT_SCOPE)
51       return()
52     endif()
53   endif()
55   # Ad-hoc signing: last resort
56   set(${result} "-" PARENT_SCOPE)
57 endfunction()
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")
72 endif ()
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")
78 endif ()
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")
84 endif ()
86 include(CheckCSourceCompiles)
87 check_c_source_compiles(
88     "
89     #include <TargetConditionals.h>
90     #if TARGET_CPU_ARM64
91     #if TARGET_OS_OSX
92     #warning Building for macOS
93     #else
94     #error Not building for macOS
95     #endif
96     #else
97     #error Not building for ARM64
98     #endif
99     int main(void) { return 0; }
100     "
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")
108 endif ()
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})
120 if(APPLE)
121   set(LIBCOMPRESSION compression)
122   if(APPLE_EMBEDDED)
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)
135     endif()
137     if(NOT BACKBOARD_LIBRARY)
138       set(SKIP_TEST_DEBUGSERVER ON CACHE BOOL "" FORCE)
139     endif()
140   endif()
141 endif()
143 if(LLDB_USE_ENTITLEMENTS)
144   if(APPLE_EMBEDDED)
145     set(entitlements ${DEBUGSERVER_RESOURCE_DIR}/debugserver-entitlements.plist)
146   else()
147     if (LLDB_USE_PRIVATE_ENTITLEMENTS)
148       set(entitlements ${DEBUGSERVER_RESOURCE_DIR}/debugserver-macosx-private-entitlements.plist)
149     else()
150       set(entitlements ${DEBUGSERVER_RESOURCE_DIR}/debugserver-macosx-entitlements.plist)
151     endif()
152   endif()
153 endif()
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)
161 else()
162   message(STATUS "LLDB debugserver energy support is disabled")
163 endif()
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
169   )
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}")
175   endforeach()
176 endif()
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
182   )
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
189   DNBArch.cpp
190   DNBBreakpoint.cpp
191   DNB.cpp
192   DNBDataRef.cpp
193   DNBError.cpp
194   DNBLog.cpp
195   DNBRegisterInfo.cpp
196   DNBThreadResumeActions.cpp
197   JSON.cpp
198   StdStringExtractor.cpp
199   StringConvert.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
203   libdebugserver.cpp
204   PseudoTerminal.cpp
205   PThreadEvent.cpp
206   PThreadMutex.cpp
207   RNBContext.cpp
208   RNBRemote.cpp
209   RNBServices.cpp
210   RNBSocket.cpp
211   SysSignal.cpp
212   TTYState.cpp
214   MacOSX/CFBundle.cpp
215   MacOSX/CFString.cpp
216   MacOSX/Genealogy.cpp
217   MacOSX/MachException.cpp
218   MacOSX/MachProcess.mm
219   MacOSX/MachTask.mm
220   MacOSX/MachThread.cpp
221   MacOSX/MachThreadList.cpp
222   MacOSX/MachVMMemory.cpp
223   MacOSX/MachVMRegion.cpp
224   MacOSX/OsLogger.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}
233   debugserver.cpp)
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}
242                       ${BACKBOARD_LIBRARY}
243                       ${FRONTBOARD_LIBRARY}
244                       ${SPRINGBOARD_LIBRARY}
245                       ${MOBILESERVICES_LIBRARY}
246                       ${LOCKDOWN_LIBRARY}
247                       ${CAROUSELSERVICES_LIBRARY}
248                       ${FOUNDATION_LIBRARY}
249                       ${SECURITY_LIBRARY}
250                       ${LIBCOMPRESSION}
251                       ${ENERGY_LIBRARY})
252 add_lldb_tool(debugserver ADD_TO_FRAMEWORK
253   debugserver.cpp
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)
264     execute_process(
265       COMMAND xcrun -f codesign_allocate
266       OUTPUT_STRIP_TRAILING_WHITESPACE
267       OUTPUT_VARIABLE CMAKE_CODESIGN_ALLOCATE
268     )
269   endif()
270   if(entitlements)
271     set(pass_entitlements --entitlements ${entitlements})
272   endif()
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}"
282   )
283 endif()
285 set_target_properties(debugserver PROPERTIES FOLDER "lldb libraries/debugserver")
287 if(APPLE_EMBEDDED)
288   set_property(TARGET lldbDebugserverCommon APPEND PROPERTY COMPILE_DEFINITIONS
289     WITH_LOCKDOWN
290     WITH_FBS
291     WITH_BKS
292     )
293   if(CAROUSELSERVICES_LIBRARY)
294     set_property(TARGET lldbDebugserverCommon APPEND PROPERTY COMPILE_DEFINITIONS
295       WITH_CAROUSEL
296       )
297   endif()
298   set_property(TARGET debugserver APPEND PROPERTY COMPILE_DEFINITIONS
299     WITH_LOCKDOWN
300     WITH_FBS
301     WITH_BKS
302     )
303   set_property(TARGET lldbDebugserverCommon APPEND PROPERTY COMPILE_FLAGS
304     -F${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks
305     )
307   add_lldb_library(lldbDebugserverCommon_NonUI ${lldbDebugserverCommonSources})
308   target_link_libraries(lldbDebugserverCommon_NonUI
309                       INTERFACE ${COCOA_LIBRARY}
310                       ${CORE_FOUNDATION_LIBRARY}
311                       ${FOUNDATION_LIBRARY}
312                       ${SECURITY_LIBRARY}
313                       ${LIBCOMPRESSION})
315   add_lldb_tool(debugserver-nonui
316     debugserver.cpp
318     LINK_LIBS
319       lldbDebugserverCommon_NonUI
321     ENTITLEMENTS
322       ${entitlements}
323     )
324 endif()