blob: 86029e0db9c2cba6b8476e2d49a9d8064e80030e [file] [log] [blame]
Imre Kised98e9c2019-10-15 16:17:55 +02001#
2# Copyright (c) 2019, Arm Limited. All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6
7cmake_minimum_required(VERSION 3.11...3.15) # TODO: test with ubuntu
8project(tf-a-unit-tests)
9
10list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
11
12include(CTest)
13include(ExternalProject)
14include(FetchContent)
15
16# Configuration variables
17set(TF_A_PATH "" CACHE PATH "Path of the Trusted Firmware A directory")
18set(TF_A_UNIT_TESTS_PATH ${CMAKE_CURRENT_LIST_DIR} CACHE PATH "Path of root directory of the unit test repository")
19set(CPPUTEST_URL "https://github.com/cpputest/cpputest.git" CACHE STRING "CppUTest repository URL")
20set(CPPUTEST_REFSPEC "v3.8" CACHE STRING "CppUTest git refspec")
21set(CPPUTEST_INSTALL_PATH ${CMAKE_CURRENT_BINARY_DIR}/CppUTest_install CACHE PATH "CppUTest installation directory")
22set(CPPUTEST_PACKAGE_PATH ${CPPUTEST_INSTALL_PATH}/lib/CppUTest/cmake CACHE PATH "CppUTest CMake package directory")
23set(CPICKER_CACHE_PATH ${CMAKE_CURRENT_BINARY_DIR}/cpicker_cache CACHE PATH "Directory of c-picker generated file")
24set(UNIT_TEST_COMMON_SOURCES ${CMAKE_CURRENT_LIST_DIR}/common/main.cpp)
25set(CMAKE_CXX_STANDARD 11)
26
27# Checking TF-A
28if (NOT TF_A_PATH)
29 message(FATAL_ERROR "TF_A_PATH is not set")
30endif()
31
32# Checking c-picker
33find_program(CPICKER_COMMAND "c-picker")
34if (NOT CPICKER_COMMAND)
35 message(FATAL_ERROR "Please install c-picker using pip")
36endif()
37
38# Checking git
39find_program(GIT_COMMAND "git")
40if (NOT GIT_COMMAND)
41 message(FATAL_ERROR "Please install git")
42endif()
43
44# Fetching CppUTest
45FetchContent_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
54FetchContent_GetProperties(cpputest)
55if(NOT cpputest_POPULATED)
56 message(STATUS "Fetching CppUTest")
57 FetchContent_Populate(cpputest)
58endif()
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.
62execute_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)
73execute_process(COMMAND ${CMAKE_COMMAND} --build ${cpputest_BINARY_DIR} -- install -j)
74
75# Finding CppUTest package. CMake will check [package name]_DIR variable.
76set(CppUTest_DIR ${CPPUTEST_PACKAGE_PATH} CACHE PATH "Path of CppUTestConfig.cmake")
77find_package(CppUTest CONFIG REQUIRED)
78
79# find_package sets the CppUTest_INCLUDE_DIRS and CppUTest_LIBRARIES variables
80include_directories(${CppUTest_INCLUDE_DIRS})
81link_libraries(${CppUTest_LIBRARIES})
82
83# Project level include directory
84include_directories(${CMAKE_CURRENT_LIST_DIR}/include)
85
86include(tests/lib/libc/test_libc.cmake)