Refactor desktop_capture build.

This CL removes the split of "desktop_capture" in 2 build targets
(one for C++ and one for Obj-C++) by moving the C++ part to
"desktop_capture" itself and keeping the Obj-C++ variant but allowing
it to include .h files that are also part of "desktop_capture".

This removes the build cycle between the two targets (which conceptually
are the same target).

Clients should never depend on "desktop_capture_objc", which will
be linked by "desktop_capture" when needed.

Bug: b/36882554
Change-Id: Id219a15e549275870c54375c07f00cfe704ab7cb
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/266743
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Oleh Prypin <oprypin@google.com>
Cr-Commit-Position: refs/heads/main@{#37337}
diff --git a/modules/desktop_capture/BUILD.gn b/modules/desktop_capture/BUILD.gn
index 864732b..af00596 100644
--- a/modules/desktop_capture/BUILD.gn
+++ b/modules/desktop_capture/BUILD.gn
@@ -57,6 +57,7 @@
     defines = []
     sources = []
     deps = [
+      ":desktop_capture",
       "../../api:function_view",
       "../../api:scoped_refptr",
       "../../rtc_base:checks",
@@ -171,8 +172,6 @@
   rtc_library("screen_drawer") {
     testonly = true
 
-    public_deps = [ ":desktop_capture" ]  # no-presubmit-check TODO(webrtc:8603)
-
     sources = [
       "screen_drawer.cc",
       "screen_drawer.h",
@@ -191,6 +190,7 @@
     }
 
     deps = [
+      ":desktop_capture",
       ":primitives",
       "../../api:scoped_refptr",
       "../../rtc_base:checks",
@@ -209,14 +209,13 @@
   rtc_library("desktop_capture_mock") {
     testonly = true
 
-    public_deps = [ ":desktop_capture" ]  # no-presubmit-check TODO(webrtc:8603)
-
     sources = [
       "mock_desktop_capturer_callback.cc",
       "mock_desktop_capturer_callback.h",
     ]
 
     deps = [
+      ":desktop_capture",
       ":primitives",
       "../../test:test_support",
     ]
@@ -294,63 +293,32 @@
   }
 }
 
-rtc_source_set("desktop_capture") {
-  visibility = [ "*" ]
-  public_deps =  # no-presubmit-check TODO(webrtc:8603)
-      [ ":desktop_capture_generic" ]
-  if (is_mac) {
-    public_deps += [ ":desktop_capture_objc" ]
-  }
-}
-
-if (is_mac) {
-  rtc_library("desktop_capture_objc") {
-    visibility = [ ":desktop_capture" ]
-    sources = [
-      "mac/desktop_configuration.mm",
-      "mac/desktop_frame_cgimage.h",
-      "mac/desktop_frame_cgimage.mm",
-      "mac/desktop_frame_iosurface.h",
-      "mac/desktop_frame_iosurface.mm",
-      "mac/desktop_frame_provider.h",
-      "mac/desktop_frame_provider.mm",
-      "mac/screen_capturer_mac.h",
-      "mac/screen_capturer_mac.mm",
-      "mouse_cursor_monitor_mac.mm",
-      "screen_capturer_darwin.mm",
-      "window_capturer_mac.mm",
-      "window_finder_mac.h",
-      "window_finder_mac.mm",
-    ]
-    deps = [
-      ":desktop_capture_generic",
-      ":primitives",
-      "../../api:scoped_refptr",
-      "../../api:sequence_checker",
-      "../../rtc_base",
-      "../../rtc_base:checks",
-      "../../rtc_base:event_tracer",
-      "../../rtc_base:logging",
-      "../../rtc_base:timeutils",
-      "../../rtc_base/system:rtc_export",
-      "../../sdk:helpers_objc",
-    ]
-    frameworks = [
-      "AppKit.framework",
-      "IOKit.framework",
-      "IOSurface.framework",
-    ]
-  }
-}
-
-rtc_library("desktop_capture_generic") {
-  defines = []
-  public_configs = [ ":x11_config" ]
-  visibility = [
+# TODO(mbonadei): Just for backwards compatibility, remove.
+rtc_source_set("desktop_capture_generic") {
+  deps = [
     ":desktop_capture",
-    ":desktop_capture_objc",
+    ":primitives",
+    "../../api:scoped_refptr",
+    "../../rtc_base/system:rtc_export",
   ]
   sources = [
+    "desktop_capture_options.h",
+    "desktop_capturer.h",
+    "desktop_frame_generator.h",
+    "fake_desktop_capturer.h",
+  ]
+  if (rtc_use_x11_extensions) {
+    sources += [ "linux/x11/shared_x_display.h" ]
+    deps += [ "../../api:refcountedbase" ]
+  }
+}
+
+rtc_library("desktop_capture") {
+  visibility = [ "*" ]
+  defines = []
+  deps = []
+  public_configs = [ ":x11_config" ]
+  sources = [
     "blank_detector_desktop_capturer_wrapper.cc",
     "blank_detector_desktop_capturer_wrapper.h",
     "cropped_desktop_frame.cc",
@@ -409,6 +377,7 @@
       "mac/window_list_utils.cc",
       "mac/window_list_utils.h",
     ]
+    deps += [ ":desktop_capture_objc" ]
   }
 
   if (build_with_mozilla) {
@@ -487,14 +456,13 @@
     ]
   }
 
-  deps = [
+  deps += [
     ":primitives",
     "../../api:function_view",
     "../../api:make_ref_counted",
     "../../api:refcountedbase",
     "../../api:scoped_refptr",
     "../../api:sequence_checker",
-    "../../rtc_base",  # TODO(kjellander): Cleanup in bugs.webrtc.org/3806.
     "../../rtc_base:checks",
     "../../rtc_base:event_tracer",
     "../../rtc_base:logging",
@@ -673,6 +641,71 @@
   }
 }
 
+if (is_mac) {
+  rtc_library("desktop_capture_objc") {
+    # This target, needs to be separated from ":desktop_capture" because
+    # that is the C++ part of the target while this one is the Obj-C++ part.
+    # Aside from this, both represent a "desktop_capture" target.
+    # This target separation based on programming languages introduces a
+    # dependency cycle between ":desktop_capture" and
+    # ":desktop_capture_objc".
+    # To break this, ":desktop_capture_objc" shares some .h files with
+    # ":desktop_capture" but when external targets need one of these
+    # headers, they should depend on ":desktop_capture" and consider
+    # this target as private.
+    visibility = [ ":desktop_capture" ]
+    sources = [
+      "desktop_capture_options.h",
+      "desktop_capturer.h",
+      "full_screen_application_handler.h",
+      "full_screen_window_detector.h",
+      "mac/desktop_configuration.h",
+      "mac/desktop_configuration.mm",
+      "mac/desktop_configuration_monitor.h",
+      "mac/desktop_frame_cgimage.h",
+      "mac/desktop_frame_cgimage.mm",
+      "mac/desktop_frame_iosurface.h",
+      "mac/desktop_frame_iosurface.mm",
+      "mac/desktop_frame_provider.h",
+      "mac/desktop_frame_provider.mm",
+      "mac/screen_capturer_mac.h",
+      "mac/screen_capturer_mac.mm",
+      "mac/window_list_utils.h",
+      "mouse_cursor.h",
+      "mouse_cursor_monitor.h",
+      "mouse_cursor_monitor_mac.mm",
+      "screen_capture_frame_queue.h",
+      "screen_capturer_darwin.mm",
+      "screen_capturer_helper.h",
+      "window_capturer_mac.mm",
+      "window_finder.h",
+      "window_finder_mac.h",
+      "window_finder_mac.mm",
+    ]
+    deps = [
+      ":primitives",
+      "../../api:function_view",
+      "../../api:refcountedbase",
+      "../../api:scoped_refptr",
+      "../../api:sequence_checker",
+      "../../rtc_base",
+      "../../rtc_base:checks",
+      "../../rtc_base:event_tracer",
+      "../../rtc_base:logging",
+      "../../rtc_base:macromagic",
+      "../../rtc_base:timeutils",
+      "../../rtc_base/synchronization:mutex",
+      "../../rtc_base/system:rtc_export",
+      "../../sdk:helpers_objc",
+    ]
+    frameworks = [
+      "AppKit.framework",
+      "IOKit.framework",
+      "IOSurface.framework",
+    ]
+  }
+}
+
 if (use_desktop_capture_differ_sse2) {
   # Have to be compiled as a separate target because it needs to be compiled
   # with SSE2 enabled.