Imre Kis | ed98e9c | 2019-10-15 16:17:55 +0200 | [diff] [blame^] | 1 | # |
| 2 | # Copyright (c) 2019, Arm Limited. All rights reserved. |
| 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | |
| 7 | cmake_minimum_required(VERSION 3.11...3.15) # TODO: test with ubuntu |
| 8 | project(tf-a-unit-tests) |
| 9 | |
| 10 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake) |
| 11 | |
| 12 | include(CTest) |
| 13 | include(ExternalProject) |
| 14 | include(FetchContent) |
| 15 | |
| 16 | # Configuration variables |
| 17 | set(TF_A_PATH "" CACHE PATH "Path of the Trusted Firmware A directory") |
| 18 | set(TF_A_UNIT_TESTS_PATH ${CMAKE_CURRENT_LIST_DIR} CACHE PATH "Path of root directory of the unit test repository") |
| 19 | set(CPPUTEST_URL "https://github.com/cpputest/cpputest.git" CACHE STRING "CppUTest repository URL") |
| 20 | set(CPPUTEST_REFSPEC "v3.8" CACHE STRING "CppUTest git refspec") |
| 21 | set(CPPUTEST_INSTALL_PATH ${CMAKE_CURRENT_BINARY_DIR}/CppUTest_install CACHE PATH "CppUTest installation directory") |
| 22 | set(CPPUTEST_PACKAGE_PATH ${CPPUTEST_INSTALL_PATH}/lib/CppUTest/cmake CACHE PATH "CppUTest CMake package directory") |
| 23 | set(CPICKER_CACHE_PATH ${CMAKE_CURRENT_BINARY_DIR}/cpicker_cache CACHE PATH "Directory of c-picker generated file") |
| 24 | set(UNIT_TEST_COMMON_SOURCES ${CMAKE_CURRENT_LIST_DIR}/common/main.cpp) |
| 25 | set(CMAKE_CXX_STANDARD 11) |
| 26 | |
| 27 | # Checking TF-A |
| 28 | if (NOT TF_A_PATH) |
| 29 | message(FATAL_ERROR "TF_A_PATH is not set") |
| 30 | endif() |
| 31 | |
| 32 | # Checking c-picker |
| 33 | find_program(CPICKER_COMMAND "c-picker") |
| 34 | if (NOT CPICKER_COMMAND) |
| 35 | message(FATAL_ERROR "Please install c-picker using pip") |
| 36 | endif() |
| 37 | |
| 38 | # Checking git |
| 39 | find_program(GIT_COMMAND "git") |
| 40 | if (NOT GIT_COMMAND) |
| 41 | message(FATAL_ERROR "Please install git") |
| 42 | endif() |
| 43 | |
| 44 | # Fetching CppUTest |
| 45 | FetchContent_Declare( |
| 46 | cpputest |
| 47 | GIT_REPOSITORY ${CPPUTEST_URL} |
| 48 | GIT_TAG ${CPPUTEST_REFSPEC} |
| 49 | GIT_SHALLOW TRUE |
| 50 | PATCH_COMMAND git apply ${CMAKE_CURRENT_LIST_DIR}/common/cpputest-cmake-fix.patch |
| 51 | ) |
| 52 | |
| 53 | # FetchContent_GetProperties exports cpputest_SOURCE_DIR and cpputest_BINARY_DIR variables |
| 54 | FetchContent_GetProperties(cpputest) |
| 55 | if(NOT cpputest_POPULATED) |
| 56 | message(STATUS "Fetching CppUTest") |
| 57 | FetchContent_Populate(cpputest) |
| 58 | endif() |
| 59 | |
| 60 | # Build and install CppUTest in CMake time. This makes us able to use CppUTest as a CMake package later. |
| 61 | # Memory leak detection is turned off to avoid conflict with memcheck. |
| 62 | execute_process(COMMAND |
| 63 | ${CMAKE_COMMAND} |
| 64 | -DMEMORY_LEAK_DETECTION=OFF |
| 65 | -DLONGLONG=ON |
| 66 | -DC++11=ON |
| 67 | -DCMAKE_INSTALL_PREFIX=${CPPUTEST_INSTALL_PATH} |
| 68 | -GUnix\ Makefiles |
| 69 | ${cpputest_SOURCE_DIR} |
| 70 | WORKING_DIRECTORY |
| 71 | ${cpputest_BINARY_DIR} |
| 72 | ) |
| 73 | execute_process(COMMAND ${CMAKE_COMMAND} --build ${cpputest_BINARY_DIR} -- install -j) |
| 74 | |
| 75 | # Finding CppUTest package. CMake will check [package name]_DIR variable. |
| 76 | set(CppUTest_DIR ${CPPUTEST_PACKAGE_PATH} CACHE PATH "Path of CppUTestConfig.cmake") |
| 77 | find_package(CppUTest CONFIG REQUIRED) |
| 78 | |
| 79 | # find_package sets the CppUTest_INCLUDE_DIRS and CppUTest_LIBRARIES variables |
| 80 | include_directories(${CppUTest_INCLUDE_DIRS}) |
| 81 | link_libraries(${CppUTest_LIBRARIES}) |
| 82 | |
| 83 | # Project level include directory |
| 84 | include_directories(${CMAKE_CURRENT_LIST_DIR}/include) |
| 85 | |
| 86 | include(tests/lib/libc/test_libc.cmake) |