This repository was archived by the owner on Dec 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathbuild_api.cmake
82 lines (66 loc) · 2.23 KB
/
build_api.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
if (__build_api_def)
return()
endif ()
set(__build_api_def YES)
# Might be reviewed
cmake_minimum_required(VERSION 3.2)
# Set for latter use
set(CORE_DIR ${CMAKE_CURRENT_LIST_DIR})
# Requried to improve function managament
include(CMakeParseArguments)
# Add modules dir to search path
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/modules)
# Registers a project
macro(register_project project_name path_to_exe_file)
set(EXEC_PATH ${path_to_exe_file})
# Make sure the core is included
add_subdirectory(${CORE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/core)
endmacro()
# Creates a host unit test with name unit_test_${test_name}
# TODO: move this to separate module
#
# Syntax:
# add_unit_host_test(NAME test_name
# SOURCES test_sources_files...
# [DEPENDS list_of_dependencies...]
# [INC_DIRS list_of_include_directories...])
function(add_unit_host_test)
# All test can use most recent standart
set(CMAKE_CXX_STANDARD 14)
# Add test only if not cross-compiling
if (${CMAKE_HOST_SYSTEM_NAME} STREQUAL ${CMAKE_SYSTEM_NAME})
find_package(CppUTest REQUIRED)
cmake_parse_arguments(
UNIT_TEST
"OPTIONAL"
"NAME"
"SOURCES;DEPENDS;INC_DIRS"
${ARGN}
)
if(DEFINED UNIT_TEST_NAME AND DEFINED UNIT_TEST_SOURCES)
set(UNIT_TEST_NAME unit_test_${UNIT_TEST_NAME})
message("-----------------------------------------------")
message(" Test added: ${UNIT_TEST_NAME}")
message(" Test sources: ${UNIT_TEST_SOURCES}")
add_executable(${UNIT_TEST_NAME} ${UNIT_TEST_SOURCES})
add_test(NAME ${UNIT_TEST_NAME} COMMAND ${UNIT_TEST_NAME})
target_link_libraries(${UNIT_TEST_NAME} CppUTest)
target_link_libraries(${UNIT_TEST_NAME} CppUTestExt)
else()
message(FATAL_ERROR "Test sources and name must be defined!")
endif()
if(UNIT_TEST_DEPENDS)
message(" Test dependencies: ${UNIT_TEST_DEPENDS}")
target_link_libraries(${UNIT_TEST_NAME} ${UNIT_TEST_DEPENDS})
endif()
if(UNIT_TEST_INC_DIRS)
message(" Test includes: ${UNIT_TEST_INC_DIRS}")
target_include_directories(
${UNIT_TEST_NAME}
PRIVATE
${UNIT_TEST_INC_DIRS})
endif()
target_include_directories(${UNIT_TEST_NAME} PRIVATE ${CPPUTEST_INCLUDE_DIRS})
message("-----------------------------------------------")
endif()
endfunction()