[CMake] Build debugserver & debugserver_nonui
authorChris Bieneman <beanz@apple.com>
Tue, 25 Jul 2017 20:31:53 +0000 (20:31 +0000)
committerChris Bieneman <beanz@apple.com>
Tue, 25 Jul 2017 20:31:53 +0000 (20:31 +0000)
When building for iOS we build two variants of debugserver. One which supports UI functionality like Springboard for launching applications, and one which does not.

This patch adds support for building debugserver with and without UI support libraries being available.

llvm-svn: 309026

lldb/tools/debugserver/source/CMakeLists.txt

index f49d0fa..7c9df19 100644 (file)
@@ -94,26 +94,72 @@ add_library(lldbDebugserverCommon ${lldbDebugserverCommonSources})
 
 if (APPLE)
   if(IOS)
-    find_library(COCOA_LIBRARY UIKit)
+    find_library(BACKBOARD_LIBRARY BackBoardServices
+      PATHS ${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks)
+    find_library(FRONTBOARD_LIBRARY FrontBoardServices
+      PATHS ${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks)
+    find_library(SPRINGBOARD_LIBRARY SpringBoardServices
+      PATHS ${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks)
+    find_library(MOBILESERVICES_LIBRARY MobileCoreServices
+      PATHS ${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks)
+    find_library(LOCKDOWN_LIBRARY lockdown)
+
+    if(NOT BACKBOARD_LIBRARY)
+      set(SKIP_DEBUGSERVER True)
+    endif()
   else()
     find_library(COCOA_LIBRARY Cocoa)
   endif()
 endif()
 
-target_link_libraries(lldbDebugserverCommon
+if(NOT SKIP_DEBUGSERVER)
+  target_link_libraries(lldbDebugserverCommon
+                        INTERFACE ${COCOA_LIBRARY}
+                        ${CORE_FOUNDATION_LIBRARY}
+                        ${FOUNDATION_LIBRARY}
+                        ${BACKBOARD_LIBRARY}
+                        ${FRONTBOARD_LIBRARY}
+                        ${SPRINGBOARD_LIBRARY}
+                        ${MOBILESERVICES_LIBRARY}
+                        ${LOCKDOWN_LIBRARY}
+                        lldbDebugserverArchSupport
+                        lldbDebugserverDarwin_DarwinLog)
+
+  set(LLVM_OPTIONAL_SOURCES ${lldbDebugserverCommonSources})
+  add_lldb_tool(debugserver INCLUDE_IN_FRAMEWORK
+    debugserver.cpp
+
+    LINK_LIBS
+      lldbDebugserverCommon
+    )
+  if(IOS)
+    set_property(TARGET lldbDebugserverCommon APPEND PROPERTY COMPILE_DEFINITIONS
+      WITH_LOCKDOWN
+      WITH_FBS
+      WITH_BKS
+      )
+    set_property(TARGET lldbDebugserverCommon APPEND PROPERTY COMPILE_FLAGS
+      -F${CMAKE_OSX_SYSROOT}/System/Library/PrivateFrameworks
+      )
+  endif()
+endif()
+
+if(IOS)
+  add_library(lldbDebugserverCommon_NonUI ${lldbDebugserverCommonSources})
+  target_link_libraries(lldbDebugserverCommon_NonUI
                       INTERFACE ${COCOA_LIBRARY}
                       ${CORE_FOUNDATION_LIBRARY}
                       ${FOUNDATION_LIBRARY}
                       lldbDebugserverArchSupport
                       lldbDebugserverDarwin_DarwinLog)
 
-set(LLVM_OPTIONAL_SOURCES ${lldbDebugserverCommonSources})
-add_lldb_tool(debugserver INCLUDE_IN_FRAMEWORK
-  debugserver.cpp
+  add_lldb_tool(debugserver_nonui INCLUDE_IN_FRAMEWORK
+    debugserver.cpp
 
-  LINK_LIBS
-    lldbDebugserverCommon
-  )
+    LINK_LIBS
+      lldbDebugserverCommon_NonUI
+    )
+endif()
 
 set(entitlements_xml ${CMAKE_CURRENT_SOURCE_DIR}/debugserver-macosx-entitlements.plist)
 if(IOS)
@@ -136,6 +182,16 @@ if (NOT ("${LLDB_CODESIGN_IDENTITY}" STREQUAL ""))
             $<TARGET_FILE:debugserver>
     WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin
   )
+  if(IOS)
+    add_custom_command(TARGET debugserver_nonui
+      POST_BUILD
+      COMMAND ${CMAKE_COMMAND} -E env CODESIGN_ALLOCATE=${CODESIGN_ALLOCATE}
+              codesign --force --sign ${LLDB_CODESIGN_IDENTITY}
+              --entitlements ${entitlements_xml}
+              $<TARGET_FILE:debugserver>
+      WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin
+    )
+  endif()
 endif()