forked from mcoquet642/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathO2AddTestRootMacro.cmake
More file actions
147 lines (125 loc) · 4.92 KB
/
O2AddTestRootMacro.cmake
File metadata and controls
147 lines (125 loc) · 4.92 KB
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
138
139
140
141
142
143
144
145
146
147
# Copyright CERN and copyright holders of ALICE O2. This software is distributed
# under the terms of the GNU General Public License v3 (GPL Version 3), copied
# verbatim in the file "COPYING".
#
# See http://alice-o2.web.cern.ch/license for full licensing information.
#
# 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()
#
# o2_add_test_root_macro generate one or two tests for one root macro.
#
# * one test is trying to load the macro within a root.exe session using ".L
# macro.C"
# * one test is trying to compile the macro using ".L macro.C++"
#
# * arg LOAD_ONLY: if present we generate only the test to load the macro (i.e.
# we skip the compilation test)
# * arg COMPILE_ONLY: if present we generate only the test to compile the
# libration (i.e. we skip the loading test)
# * arg NON_FATAL: if present mark the test as non_fatal, i.e. it won't
# invalidate the build
# * arg ENVIRONMENT: sets the running environment for the generated test(s).
# * arg PUBLIC_LINK_LIBRARIES: the list of targets this macro is depending on.
# Required to be able to specify correctly the include and library paths to
# test the (compiled version of) the macro.
#
# ****************
#
# DEV NOTES:
#
# LIMITATION: the tests generated by this function currently only work fine
# under the proper environment.
#
# WHY: attempts to compute the environment of the root process (so that tests
# could be run without having to setup the env. beforehand) proved to be a bit
# difficult.
#
# While computing ROOT_INCLUDE_PATH is just a matter of using the proper
# generator expression on each of the dependencies : list(APPEND incdir
# $<TARGET_PROPERTY:${dep},INTERFACE_INCLUDE_DIRECTORIES>) computing the list of
# directories to be used for LD_LIBRARY_PATH is a lot more complex. There is
# currently no $<TARGET_PROPERTY:${t},INTERFACE_LINK_DIRECTORIES> that would
# give us, _transitively_, all the libraries directories. And computing them
# ourselves (recursively) is quite time consuming...
#
function(o2_add_test_root_macro macro)
if(NOT BUILD_TESTING)
return()
endif()
if(NOT BUILD_TEST_ROOT_MACROS)
return()
endif()
cmake_parse_arguments(
PARSE_ARGV
1
A
"NON_FATAL;LOAD_ONLY;COMPILE_ONLY"
""
"ENVIRONMENT;PUBLIC_LINK_LIBRARIES;PUBLIC_INCLUDE_DIRECTORIES;LABELS")
if(A_UNPARSED_ARGUMENTS)
message(
FATAL_ERROR "Unexpected unparsed arguments: ${A_UNPARSED_ARGUMENTS}")
endif()
get_filename_component(macroFileName ${macro} ABSOLUTE)
if(NOT EXISTS ${macroFileName})
message(
FATAL_ERROR
"Requested a test macro for non existing macro ${macroFileName}")
return()
endif()
file(RELATIVE_PATH testName ${CMAKE_SOURCE_DIR} ${macroFileName})
if(${A_IS_NON_FATAL})
set(nonFatal "NON_FATAL")
endif()
list(APPEND incdir $ENV{ROOT_INCLUDE_PATH})
list(APPEND incdir ${A_PUBLIC_INCLUDE_DIRECTORIES})
# Get all the include dir dependencies
foreach(t IN LISTS A_PUBLIC_LINK_LIBRARIES)
string(FIND ${t} "::" NS)
if(${NS} EQUAL -1)
message(
WARNING
"Trying to use a non-namespaced target ${t} for ${testName} test so I won't be able to generate that test."
)
return()
endif()
list(APPEND dependencies ${t})
endforeach()
list(LENGTH dependencies nofDeps)
if(${nofDeps} GREATER 0)
list(REMOVE_DUPLICATES dependencies)
foreach(t IN LISTS dependencies)
list(APPEND incdir $<TARGET_PROPERTY:${t},INTERFACE_INCLUDE_DIRECTORIES>)
endforeach()
# FIXME: once CMake 3.15 is out, use $<REMOVE_DUPLICATES:list> to dedupe the
# includePath list
set(includePath $<JOIN:${incdir},:>)
endif()
list(APPEND testEnv "ROOT_HIST=0")
list(APPEND testEnv "${A_ENVIRONMENT}")
if(NOT A_COMPILE_ONLY)
o2_add_test_wrapper(COMMAND ${CMAKE_BINARY_DIR}/test-root-macro.sh
NAME ${testName}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ${nonFatal}
COMMAND_LINE_ARGS ${macroFileName} 0 "${includePath}"
LABELS "macro;${A_LABELS}")
set_property(TEST ${testName} PROPERTY ENVIRONMENT "${testEnv}")
set(LIST_OF_ROOT_MACRO_TESTS
"${LIST_OF_ROOT_MACRO_TESTS};${testName}"
CACHE INTERNAL "")
endif()
if(NOT A_LOAD_ONLY)
o2_add_test_wrapper(COMMAND ${CMAKE_BINARY_DIR}/test-root-macro.sh
NAME ${testName}_compiled
WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ${nonFatal}
COMMAND_LINE_ARGS ${macroFileName} 1 "${includePath}"
LABELS "macro;macro_compiled;${A_LABELS}")
set_property(TEST ${testName}_compiled PROPERTY ENVIRONMENT "${testEnv}")
set(LIST_OF_ROOT_MACRO_TESTS_COMPILED
"${LIST_OF_ROOT_MACRO_TESTS_COMPILED};${testName}"
CACHE INTERNAL "")
endif()
endfunction()