blob: 86029e0db9c2cba6b8476e2d49a9d8064e80030e [file] [log] [blame]
#
# Copyright (c) 2019, Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
cmake_minimum_required(VERSION 3.11...3.15) # TODO: test with ubuntu
project(tf-a-unit-tests)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
include(CTest)
include(ExternalProject)
include(FetchContent)
# Configuration variables
set(TF_A_PATH "" CACHE PATH "Path of the Trusted Firmware A directory")
set(TF_A_UNIT_TESTS_PATH ${CMAKE_CURRENT_LIST_DIR} CACHE PATH "Path of root directory of the unit test repository")
set(CPPUTEST_URL "https://github.com/cpputest/cpputest.git" CACHE STRING "CppUTest repository URL")
set(CPPUTEST_REFSPEC "v3.8" CACHE STRING "CppUTest git refspec")
set(CPPUTEST_INSTALL_PATH ${CMAKE_CURRENT_BINARY_DIR}/CppUTest_install CACHE PATH "CppUTest installation directory")
set(CPPUTEST_PACKAGE_PATH ${CPPUTEST_INSTALL_PATH}/lib/CppUTest/cmake CACHE PATH "CppUTest CMake package directory")
set(CPICKER_CACHE_PATH ${CMAKE_CURRENT_BINARY_DIR}/cpicker_cache CACHE PATH "Directory of c-picker generated file")
set(UNIT_TEST_COMMON_SOURCES ${CMAKE_CURRENT_LIST_DIR}/common/main.cpp)
set(CMAKE_CXX_STANDARD 11)
# Checking TF-A
if (NOT TF_A_PATH)
message(FATAL_ERROR "TF_A_PATH is not set")
endif()
# Checking c-picker
find_program(CPICKER_COMMAND "c-picker")
if (NOT CPICKER_COMMAND)
message(FATAL_ERROR "Please install c-picker using pip")
endif()
# Checking git
find_program(GIT_COMMAND "git")
if (NOT GIT_COMMAND)
message(FATAL_ERROR "Please install git")
endif()
# Fetching CppUTest
FetchContent_Declare(
cpputest
GIT_REPOSITORY ${CPPUTEST_URL}
GIT_TAG ${CPPUTEST_REFSPEC}
GIT_SHALLOW TRUE
PATCH_COMMAND git apply ${CMAKE_CURRENT_LIST_DIR}/common/cpputest-cmake-fix.patch
)
# FetchContent_GetProperties exports cpputest_SOURCE_DIR and cpputest_BINARY_DIR variables
FetchContent_GetProperties(cpputest)
if(NOT cpputest_POPULATED)
message(STATUS "Fetching CppUTest")
FetchContent_Populate(cpputest)
endif()
# Build and install CppUTest in CMake time. This makes us able to use CppUTest as a CMake package later.
# Memory leak detection is turned off to avoid conflict with memcheck.
execute_process(COMMAND
${CMAKE_COMMAND}
-DMEMORY_LEAK_DETECTION=OFF
-DLONGLONG=ON
-DC++11=ON
-DCMAKE_INSTALL_PREFIX=${CPPUTEST_INSTALL_PATH}
-GUnix\ Makefiles
${cpputest_SOURCE_DIR}
WORKING_DIRECTORY
${cpputest_BINARY_DIR}
)
execute_process(COMMAND ${CMAKE_COMMAND} --build ${cpputest_BINARY_DIR} -- install -j)
# Finding CppUTest package. CMake will check [package name]_DIR variable.
set(CppUTest_DIR ${CPPUTEST_PACKAGE_PATH} CACHE PATH "Path of CppUTestConfig.cmake")
find_package(CppUTest CONFIG REQUIRED)
# find_package sets the CppUTest_INCLUDE_DIRS and CppUTest_LIBRARIES variables
include_directories(${CppUTest_INCLUDE_DIRS})
link_libraries(${CppUTest_LIBRARIES})
# Project level include directory
include_directories(${CMAKE_CURRENT_LIST_DIR}/include)
include(tests/lib/libc/test_libc.cmake)