From ee82c60e5ec707faa5eaa638f397dde7df820dac Mon Sep 17 00:00:00 2001 From: Kshitij Sisodia Date: Thu, 29 Dec 2022 11:53:23 +0000 Subject: 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 --- CMakeLists.txt | 1 - .../platforms/native/build_configuration.cmake | 26 +++++++++++++--------- scripts/cmake/toolchains/toolchain-preset.json | 11 +++++++++ 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 91568f8..a36d00d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,6 @@ # limitations under the License. #---------------------------------------------------------------------------- cmake_minimum_required(VERSION 3.21.0) -include(ExternalProject) # Build in release mode by default if (NOT CMAKE_BUILD_TYPE STREQUAL Debug) 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 @@ function(set_platform_global_defaults) 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 /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 @@ function(platform_custom_post_build) 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) diff --git a/scripts/cmake/toolchains/toolchain-preset.json b/scripts/cmake/toolchains/toolchain-preset.json index 30b5366..19ea6f8 100644 --- a/scripts/cmake/toolchains/toolchain-preset.json +++ b/scripts/cmake/toolchains/toolchain-preset.json @@ -6,10 +6,19 @@ "patch": 0 }, "configurePresets": [ + { + "name": "source-dir", + "description": "Sets the root of the ml-embedded-eval-kit repo. This should be overridden if this repo is used as a submodule/dependency.", + "hidden": true, + "environment": { + "MLEK_BASE_DIR": "${sourceDir}/" + } + }, { "name": "gcc-toolchain", "description": "Use gcc toolchain.", "hidden": true, + "inherits": ["source-dir"], "cacheVariables": { "CMAKE_TOOLCHAIN_FILE": { "type": "STRING", @@ -21,6 +30,7 @@ "name": "armclang-toolchain", "description": "Use armclang toolchain.", "hidden": true, + "inherits": ["source-dir"], "cacheVariables": { "CMAKE_TOOLCHAIN_FILE": { "type": "STRING", @@ -32,6 +42,7 @@ "name": "native-toolchain", "description": "Use native toolchain.", "hidden": true, + "inherits": ["source-dir"], "cacheVariables": { "CMAKE_TOOLCHAIN_FILE": { "type": "STRING", -- cgit v1.2.1