Adding conditional compilation for jlink/segger_rtt code (#23777)

* Adding conditional compilation for jlink/segger_rtt code

* Review remarks addressed
diff --git a/src/platform/device.gni b/src/platform/device.gni
index 70cbe99..bddd80e 100755
--- a/src/platform/device.gni
+++ b/src/platform/device.gni
@@ -185,7 +185,7 @@
   build_tv_casting_common_a = false
 }
 
-assert(chip_disable_platform_kvs == false || chip_device_platform == "darwin",
+assert(!chip_disable_platform_kvs || chip_device_platform == "darwin",
        "Can only disable KVS on some platforms")
 
 if (_chip_device_layer != "none" && chip_device_platform != "external") {
@@ -201,6 +201,11 @@
       "<platform/" + _chip_device_layer + "/SystemPlatformConfig.h>"
 }
 
+declare_args() {
+  # Enable jlink/segger_rtt support.
+  chip_enable_segger_rtt = chip_device_platform != "qpg"
+}
+
 assert(
     (current_os != "freertos" && chip_device_platform == "none") ||
         chip_device_platform == "fake" ||
diff --git a/third_party/openthread/platforms/BUILD.gn b/third_party/openthread/platforms/BUILD.gn
index 3e0e4d2..7445a64 100644
--- a/third_party/openthread/platforms/BUILD.gn
+++ b/third_party/openthread/platforms/BUILD.gn
@@ -12,8 +12,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import("//build_overrides/chip.gni")
 import("//build_overrides/jlink.gni")
 import("//build_overrides/openthread.gni")
+import("${chip_root}/src/platform/device.gni")
 
 config("libopenthread-platform_config") {
   include_dirs = [ "${openthread_root}/examples/platforms" ]
@@ -45,8 +47,6 @@
     "${openthread_root}/examples/platforms/utils/code_utils.h",
     "${openthread_root}/examples/platforms/utils/debug_uart.c",
     "${openthread_root}/examples/platforms/utils/encoding.h",
-    "${openthread_root}/examples/platforms/utils/logging_rtt.c",
-    "${openthread_root}/examples/platforms/utils/logging_rtt.h",
     "${openthread_root}/examples/platforms/utils/mac_frame.cpp",
     "${openthread_root}/examples/platforms/utils/mac_frame.h",
     "${openthread_root}/examples/platforms/utils/settings.h",
@@ -54,10 +54,17 @@
     "${openthread_root}/examples/platforms/utils/soft_source_match_table.c",
     "${openthread_root}/examples/platforms/utils/soft_source_match_table.h",
   ]
-  public_deps = [
-    "${openthread_root}/src/core:libopenthread_core_headers",
-    "${segger_rtt_root}:segger_rtt",
-  ]
+
+  public_deps = [ "${openthread_root}/src/core:libopenthread_core_headers" ]
+
+  if (chip_enable_segger_rtt) {
+    sources += [
+      "${openthread_root}/examples/platforms/utils/logging_rtt.c",
+      "${openthread_root}/examples/platforms/utils/logging_rtt.h",
+    ]
+
+    public_deps += [ "${segger_rtt_root}:segger_rtt" ]
+  }
 
   public_configs = [ ":libopenthread-platform_config" ]
 }