MLECO-3747: Minor changes to Catch2 inclusion

Catch2, included for tests on native target, is now added
using FetchContent to download it at configuration stage.
Minor improvements added to prevent name clashes if this
project is used as a submodule in other projects where
Catch2 is already a named dependency/target.

Change-Id: I6f0ff02704e54a5c4cefe499ac80d434cf89b463
Signed-off-by: Kshitij Sisodia <kshitij.sisodia@arm.com>
diff --git a/scripts/cmake/platforms/native/build_configuration.cmake b/scripts/cmake/platforms/native/build_configuration.cmake
index a858f50..d0b4dfb 100644
--- a/scripts/cmake/platforms/native/build_configuration.cmake
+++ b/scripts/cmake/platforms/native/build_configuration.cmake
@@ -28,19 +28,25 @@
     file(MAKE_DIRECTORY ${TEST_TPIP})
     set(TEST_TPIP_INCLUDE ${TEST_TPIP}/include)
     file(MAKE_DIRECTORY ${TEST_TPIP_INCLUDE})
+    set(CATCH_HEADER_URL "https://github.com/catchorg/Catch2/releases/download/v2.11.1/catch.hpp")
+    set(CATCH_HEADER_MD5 dc6bb8ce282ad134476b37275804c44c)
 
-    ExternalProject_Add(catch2-headers
-            URL https://github.com/catchorg/Catch2/releases/download/v2.11.1/catch.hpp
-            DOWNLOAD_NO_EXTRACT 1
-            CONFIGURE_COMMAND ""
-            BUILD_COMMAND ${CMAKE_COMMAND} -E copy <DOWNLOAD_DIR>/catch.hpp ${TEST_TPIP_INCLUDE}
-            INSTALL_COMMAND "")
 
-    add_library(catch2 INTERFACE)
-    target_include_directories(catch2
+    include(FetchContent)
+    FetchContent_Declare(catch2-header-download
+        URL                 ${CATCH_HEADER_URL}
+        URL_HASH            MD5=${CATCH_HEADER_MD5}
+        DOWNLOAD_DIR        ${TEST_TPIP_INCLUDE}
+        DOWNLOAD_NO_EXTRACT ON
+    )
+    FetchContent_MakeAvailable(catch2-header-download)
+
+    add_library(mlek-catch2 INTERFACE)
+    target_include_directories(mlek-catch2
             INTERFACE
             ${TEST_TPIP_INCLUDE})
-    add_dependencies(catch2 catch2-headers)
+    add_dependencies(mlek-catch2 catch2-header-download)
+    add_library(mlek::Catch2 ALIAS mlek-catch2)
 
 endfunction()
 
@@ -106,7 +112,7 @@
         set(TEST_TARGET_NAME "${use_case}_tests")
         add_executable(${TEST_TARGET_NAME} ${TEST_SOURCES})
         target_include_directories(${TEST_TARGET_NAME} PRIVATE ${TEST_RESOURCES_INCLUDE})
-        target_link_libraries(${TEST_TARGET_NAME} PRIVATE ${UC_LIB_NAME} catch2)
+        target_link_libraries(${TEST_TARGET_NAME} PRIVATE ${UC_LIB_NAME} mlek::Catch2)
         target_compile_definitions(${TEST_TARGET_NAME} PRIVATE
                 "ACTIVATION_BUF_SZ=${${use_case}_ACTIVATION_BUF_SZ}"
                 TESTS)