Revert "Build: fetch_remote_library function to fetch remote libraries."

This reverts commit 2e5af6eb005b6c4e9544bc72e8f4200fbc5651a1.

Reason for revert: git apply logic breaks incremental build.

Change-Id: Iee63ab12f78d76f4f0d21e95d017d7cc6c49d5bb
diff --git a/lib/ext/mcuboot/CMakeLists.txt b/lib/ext/mcuboot/CMakeLists.txt
index a1a0242..03f888e 100644
--- a/lib/ext/mcuboot/CMakeLists.txt
+++ b/lib/ext/mcuboot/CMakeLists.txt
@@ -1,28 +1,38 @@
 #-------------------------------------------------------------------------------
 # Copyright (c) 2020, Arm Limited. All rights reserved.
-# Copyright (c) 2022 Cypress Semiconductor Corporation (an Infineon company)
-# or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
 #-------------------------------------------------------------------------------
 
+include(FetchContent)
+set(FETCHCONTENT_QUIET FALSE)
+
+# Set to not download submodules if that option is available.
 # Because of https://gitlab.kitware.com/cmake/cmake/-/issues/20579 CMP0097 is
 # non-functional until cmake 3.18.0.
-if(${CMAKE_VERSION} VERSION_LESS "3.18.0")
-    # Workaround for not having CMP0097. Use existing directory.
-    set(MCUBOOT_SUBMODULES "docs")
+if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.18.0")
+    cmake_policy(SET CMP0097 NEW)
+    set(MCUBOOT_SUBMODULES "")
+else()
+    # Workaround for not having CMP0097. Fetch the smallest submodule.
+    set(MCUBOOT_SUBMODULES "boot/cypress/libs/cy-mbedtls-acceleration/")
 endif()
 
-fetch_remote_library(
-    LIB_NAME                mcuboot
-    LIB_SOURCE_PATH_VAR     MCUBOOT_PATH
-    FETCH_CONTENT_ARGS
-        GIT_REPOSITORY      https://github.com/mcu-tools/mcuboot.git
-        GIT_TAG             ${MCUBOOT_VERSION}
-        # ToDo: set GIT_SHALLOW to 'TRUE' when MCUBOOT_VERSION will be set to a tag
-        # (instead of a commit hash) with the new release.
-        GIT_SHALLOW         FALSE
-        GIT_PROGRESS        TRUE
-        GIT_SUBMODULES      "${MCUBOOT_SUBMODULES}"
-)
+if ("${MCUBOOT_PATH}" STREQUAL "DOWNLOAD")
+    FetchContent_Declare(mcuboot
+        GIT_REPOSITORY https://github.com/mcu-tools/mcuboot.git
+        GIT_TAG ${MCUBOOT_VERSION}
+        GIT_SHALLOW FALSE
+        GIT_PROGRESS TRUE
+        GIT_SUBMODULES "${MCUBOOT_SUBMODULES}"
+    )
+    # ToDo: set GIT_SHALLOW to 'TRUE' when MCUBOOT_VERSION will be set to a tag
+    # (instead of a commit hash) with the new release.
+
+    FetchContent_GetProperties(mcuboot)
+    if(NOT mcuboot_POPULATED)
+        FetchContent_Populate(mcuboot)
+        set(MCUBOOT_PATH ${mcuboot_SOURCE_DIR} CACHE PATH "Path to MCUBOOT (or DOWNLOAD to get automatically" FORCE)
+    endif()
+endif()