forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathO2AddTest.cmake
137 lines (118 loc) · 4.37 KB
/
O2AddTest.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# Copyright 2019-2020 CERN and copyright holders of ALICE O2.
# See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
# All rights not expressly granted are reserved.
#
# This software is distributed under the terms of the GNU General Public
# License v3 (GPL Version 3), copied verbatim in the file "COPYING".
#
# In applying this license CERN does not waive the privileges and immunities
# granted to it by virtue of its status as an Intergovernmental Organization
# or submit itself to any jurisdiction.
include_guard()
include(O2AddExecutable)
#
# o2_add_test(testName SOURCES) adds an executable that is also a test.
#
# It is a convenience function that groups the actions of cmake intrinsics
# add_executable and add_test.
#
# If BUILD_TESTING if not set this function does nothing at all.
#
# The test name is the name of the first source file in SOURCES, unless the NAME
# parameter is given (see below).
#
# o2_add_test accept the following parameters :
#
# required
#
# * SOURCES : same meaning as for o2_add_executable
#
# recommended/often needed :
#
# * PUBLIC_LINK_LIBRARIES : same meaning as for
# o2_add_executable
# * COMMAND_LINE_ARGS : the arguments to pass to the executable, if any
# * COMPONENT_NAME : a short name that will be used to create the
# executable name (if not provided with NAME) : o2-test-[COMPONENT_NAME]-...
# * LABELS : labels attached to the test, that can then be used to filter
# which tests are executed with the `ctest -L` command
#
# optional/less frequently used :
#
# * NAME: if given, will be used verbatim as the test name
# * ENVIRONMENT: extra environment needed by the test to run properly
# * TIMEOUT : the number of seconds allowed for the test to run. Past this time
# failure is assumed.
# * WORKING_DIRECTORY: the directory in which the test will be ran
#
# rarely needed/for special cases :
#
# * NO_BOOST_TEST : we assume most of the tests are using the Boost::Test
# framework and thus link the test with the Boost::unit_test_framework target.
# If the test is known to not depend on Boost::Test, then the NO_BOOST_TEST
# option can be given to forego this dependency
# * INSTALL : by default tests are _not_ installed. If that option is present
# then the test is installed (under ${CMAKE_INSTALL_PREFIX}/tests, not in
# ${CMAKE_INSTALL_PREFIX}/bin like other binaries)
# * CONFIGURATIONS : the test will only be ran for those named configurations
# * TARGETVARNAME : same meaning as for o2_add_executable
#
function(o2_add_test)
if(NOT BUILD_TESTING)
return()
endif()
cmake_parse_arguments(
PARSE_ARGV
1
A
"INSTALL;NO_BOOST_TEST"
"COMPONENT_NAME;TIMEOUT;WORKING_DIRECTORY;NAME;TARGETVARNAME"
"SOURCES;PUBLIC_LINK_LIBRARIES;COMMAND_LINE_ARGS;LABELS;CONFIGURATIONS;ENVIRONMENT"
)
if(A_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "Unexpected unparsed arguments: ${A_UNPARSED_ARGUMENTS}")
endif()
set(testName ${ARGV0})
set(linkLibraries ${A_PUBLIC_LINK_LIBRARIES})
if(NOT A_NO_BOOST_TEST)
set(linkLibraries ${linkLibraries} Boost::unit_test_framework)
if(A_COMMAND_LINE_ARGS)
# Boost test programs are to be called like this :
#
# testProgram -- arg1 arg2 ...
#
# if they have arguments.
set(A_COMMAND_LINE_ARGS "--" ${A_COMMAND_LINE_ARGS})
endif()
endif()
set(noInstall NO_INSTALL)
if(A_INSTALL)
set(noInstall "")
endif()
# create the executable
o2_add_executable(${testName}
SOURCES ${A_SOURCES}
PUBLIC_LINK_LIBRARIES ${linkLibraries}
COMPONENT_NAME ${A_COMPONENT_NAME}
IS_TEST ${noInstall} TARGETVARNAME targetName)
if(A_TARGETVARNAME)
set(${A_TARGETVARNAME} ${targetName} PARENT_SCOPE)
endif()
# create a test for the executable above
set(name "")
if(A_NAME)
set(name ${A_NAME})
else()
list(GET A_SOURCES 0 firstSource)
get_filename_component(src ${firstSource} ABSOLUTE)
file(RELATIVE_PATH name ${CMAKE_SOURCE_DIR} ${src})
endif()
add_test(NAME ${name}
COMMAND ${targetName} ${A_COMMAND_LINE_ARGS}
WORKING_DIRECTORY ${A_WORKING_DIRECTORY}
CONFIGURATIONS ${A_CONFIGURATIONS}
)
set_property(TEST ${name} PROPERTY LABELS ${A_LABELS})
set_property(TEST ${name} PROPERTY ENVIRONMENT "${A_ENVIRONMENT}")
set_property(TEST ${name} PROPERTY TIMEOUT ${A_TIMEOUT})
endfunction()