-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathAddRootBench.cmake
More file actions
231 lines (209 loc) · 10.7 KB
/
AddRootBench.cmake
File metadata and controls
231 lines (209 loc) · 10.7 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#----------------------------------------------------------------------------
# function RB_ADD_DOWNLOAD_FIXTURE(<benchmark> DOWNLOAD_DATAFILES filenames)
#----------------------------------------------------------------------------
function(RB_ADD_DOWNLOAD_FIXTURE benchmark)
cmake_parse_arguments(ARG "" "" "DOWNLOAD_DATAFILES" ${ARGN})
# Add fixture to download required dataset files from https://root.cern.ch/files/rootbench
add_test(NAME rootbench-fixture-download-${benchmark}
COMMAND ${PROJECT_BINARY_DIR}/tools/download_files.sh
${RB_DATASETDIR} ${ARG_DOWNLOAD_DATAFILES})
set_tests_properties(rootbench-fixture-download-${benchmark} PROPERTIES FIXTURES_SETUP download-${benchmark}-datafiles)
endfunction(RB_ADD_DOWNLOAD_FIXTURE)
#----------------------------------------------------------------------------
# function RB_ADD_SETUP_FIXTURE(<benchmark> SETUP commands)
#----------------------------------------------------------------------------
function(RB_ADD_SETUP_FIXTURE benchmark)
cmake_parse_arguments(ARG "" "" "SETUP" ${ARGN})
set(COUNTER 0)
foreach(CMD ${ARG_SETUP})
separate_arguments(CMD UNIX_COMMAND ${CMD})
add_test(NAME rootbench-fixture-setup-${benchmark}-${COUNTER} COMMAND ${CMD})
set_tests_properties(rootbench-fixture-setup-${benchmark}-${COUNTER} PROPERTIES
FIXTURES_SETUP setup-${benchmark}
FIXTURES_REQUIRED download-${benchmark}-datafiles)
MATH(EXPR COUNTER "${COUNTER}+1")
endforeach()
unset(COUNTER)
endfunction(RB_ADD_SETUP_FIXTURE)
#----------------------------------------------------------------------------
# function RB_ADD_GBENCHMARK(<benchmark> source1 source2... LIBRARIES libs)
#----------------------------------------------------------------------------
function(RB_ADD_GBENCHMARK benchmark)
cmake_parse_arguments(ARG "" "LABEL" "SETUP;DOWNLOAD_DATAFILES;DEPENDS;LIBRARIES" ${ARGN})
set(source_files ${ARG_UNPARSED_ARGUMENTS})
add_executable(${benchmark} ${source_files})
target_include_directories(${benchmark} PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${GBENCHMARK_INCLUDE_DIR})
set_property(TARGET ${benchmark} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
# Note we cannot use ROOT_EXECUTABLE without user-specified set of LIBRARIES to link with.
# The test suites should choose this in their specific CMakeLists.txt file.
# FIXME: For better coherence we could restrict the libraries the test suite could link
# against. For example, tests in Core should link only against libCore. This could be tricky
# to implement because some ROOT components create more than one library.
target_link_libraries(${benchmark} PUBLIC ${ARG_LIBRARIES} gbenchmark RBSupport)
if (NOT APPLE)
target_link_libraries(${benchmark} PUBLIC rt)
endif()
#ROOT_PATH_TO_STRING(mangled_name ${benchmark} PATH_SEPARATOR_REPLACEMENT "-")
#ROOT_ADD_TEST(gbench${mangled_name}
# COMMAND ${benchmark}
# WORKING_DIR ${CMAKE_CURRENT_BINARY_DIR}
# LABELS "benchmark")
if(${ARG_LABEL} STREQUAL "long")
set(${TIMEOUT_VALUE} 1200)
elseif($ARG_LABEL STREQUAL "short")
set(${TIMEOUT_VALUE} 3600)
endif()
# Add dependencies to benchmark
if(ARG_DEPENDS)
add_dependencies(${benchmark} ${ARG_DEPENDS})
endif()
if(ARG_DOWNLOAD_DATAFILES)
RB_ADD_DOWNLOAD_FIXTURE(${benchmark} DOWNLOAD_DATAFILES ${ARG_DOWNLOAD_DATAFILES})
endif()
if(ARG_SETUP)
RB_ADD_SETUP_FIXTURE(${benchmark} SETUP ${ARG_SETUP})
endif()
# Add benchmark as a CTest
add_test(NAME rootbench-${benchmark}
COMMAND ${benchmark} --benchmark_out_format=csv --benchmark_out=rootbench-gbenchmark-${benchmark}.csv --benchmark_color=false)
set_tests_properties(rootbench-${benchmark} PROPERTIES
ENVIRONMENT LD_LIBRARY_PATH=${ROOT_LIBRARY_DIR}:$ENV{LD_LIBRARY_PATH}
TIMEOUT "${TIMEOUT_VALUE}" LABELS "${ARG_LABEL}" RUN_SERIAL TRUE
FIXTURES_REQUIRED "setup-${benchmark};download-${benchmark}-datafiles")
endfunction(RB_ADD_GBENCHMARK)
#----------------------------------------------------------------------------
# function RB_ADD_GBENCHMARK(<benchmark> source1 source2... LIBRARIES libs)
#----------------------------------------------------------------------------
function(RB_ADD_MEM_GBENCHMARK benchmark)
RB_ADD_GBENCHMARK(${benchmark} ${ARGN})
set (benchmark_env)
if(APPLE)
target_link_libraries(${benchmark} PUBLIC
-Wl,-bind_at_load -Wl,-undefined -Wl,dynamic_lookup
)
set (benchmark_env "DYLD_FORCE_FLAT_NAMESPACE=1" "DYLD_INSERT_LIBRARIES=$<TARGET_FILE:RBInstrumentation>")
elseif(NOT MSVC)
target_link_libraries(${benchmark} PUBLIC
-Wl,--unresolved-symbols=ignore-in-object-files
)
set (benchmark_env "LD_PRELOAD=$<TARGET_FILE:RBInstrumentation>")
endif()
if (benchmark_env)
set_property(TEST rootbench-${benchmark} APPEND PROPERTY ENVIRONMENT ${benchmark_env})
endif(benchmark_env)
endfunction(RB_ADD_MEM_GBENCHMARK)
#----------------------------------------------------------------------------
# function RB_ADD_PYTESTBENCHMARK(<benchmark> filename)
#
# Dependency: pytest with pytest-benchmark and PyROOT modules
#
#----------------------------------------------------------------------------
function(RB_ADD_PYTESTBENCHMARK benchmark)
cmake_parse_arguments(ARG "" "LABEL" "SETUP;DOWNLOAD_DATAFILES" ${ARGN})
if(ROOT_pyroot_experimental_FOUND OR ROOT_pyroot_FOUND)
if(${ARG_LABEL} STREQUAL "long")
set(${TIMEOUT_VALUE} 1200)
elseif($ARG_LABEL STREQUAL "short")
set(${TIMEOUT_VALUE} 3600)
endif()
set(filename ${ARG_UNPARSED_ARGUMENTS})
if(PYTEST_FOUND)
if(ARG_DOWNLOAD_DATAFILES)
RB_ADD_DOWNLOAD_FIXTURE(${benchmark} DOWNLOAD_DATAFILES ${ARG_DOWNLOAD_DATAFILES})
endif()
if(ARG_SETUP)
RB_ADD_SETUP_FIXTURE(${benchmark} SETUP ${ARG_SETUP})
endif()
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/${filename} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${benchmark} USE_SOURCE_PERMISSIONS)
add_test(NAME rootbench-${benchmark}
COMMAND ${PYTHON_EXECUTABLE} -B -m pytest ${CMAKE_CURRENT_SOURCE_DIR}/${filename} -v --csv rootbench-pytest-${benchmark}.csv)
set_tests_properties(rootbench-${benchmark} PROPERTIES
ENVIRONMENT "LD_LIBRARY_PATH=${ROOT_LIBRARY_DIR}:$ENV{LD_LIBRARY_PATH};PYTHONPATH=${ROOTSYS}/lib:$ENV{PYTHONPATH};RB_DATASETDIR=${RB_DATASETDIR}"
TIMEOUT "${TIMEOUT_VALUE}" LABELS "${ARG_LABEL}" RUN_SERIAL TRUE
FIXTURES_REQUIRED "setup-${benchmark};download-${benchmark}-datafiles")
else()
message(STATUS "pytest was not found, benchmark " ${benchmark} " will be ignored")
endif()
else()
message(STATUS "ROOT was configured without PyROOT support. Python benchmarks will be disabled!")
endif()
endfunction()
#----------------------------------------------------------------------------
# function RB_ADD_LIBRARY(<library> source1 source2... LIBRARIES libs)
#----------------------------------------------------------------------------
function(RB_ADD_LIBRARY library)
cmake_parse_arguments(ARG "" "" "LIBRARIES;DEPENDENCIES" ${ARGN})
set(sources ${ARG_UNPARSED_ARGUMENTS})
add_library(${library} STATIC ${sources})
target_include_directories(${library} BEFORE PUBLIC ${ROOTBENCH_SOURCE_DIR}/include)
target_link_libraries(${library} PUBLIC ${ARG_LIBRARIES} ${ARG_DEPENDENCIES} gbenchmark)
endfunction(RB_ADD_LIBRARY)
#----------------------------------------------------------------------------
# function RB_ADD_C_LIBRARY(<library> source1 source2... LIBRARIES libs)
#----------------------------------------------------------------------------
function(RB_ADD_C_LIBRARY library)
RB_ADD_LIBRARY(${library} ${ARGN})
set_target_properties(${library} PROPERTIES LINKER_LANGUAGE C)
endfunction(RB_ADD_C_LIBRARY)
#----------------------------------------------------------------------------
# function RB_ADD_TOOL(<binary> source1 source2... LIBRARIES libs)
#----------------------------------------------------------------------------
function(RB_ADD_TOOL binary)
cmake_parse_arguments(ARG "" "" "LIBRARIES;DEPENDS" ${ARGN})
set(sources ${ARG_UNPARSED_ARGUMENTS})
include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/include)
add_executable(${binary} ${sources})
# Add dependencies to binary
if(ARG_DEPENDS)
add_dependencies(${binary} ${ARG_DEPENDS})
endif()
if (ARG_LIBRARIES)
target_link_libraries(${binary} ${ARG_LIBRARIES})
endif()
endfunction(RB_ADD_TOOL)
#-------------------------------------------------------------------------------
#
# macro RB_GENERATE_DICTIONARY(<dictname>
# [LINKDEF linkdef]
# [DEPENDS deps]
# [OPTIONS opts]
# [files ...] )
#
# It is a trimmed version of ROOTTEST_GENERATE_DICTIONARY() from roottest.git.
# This macro generates a dictionary <dictname> from the provided <files>.
# A test that performs the dictionary generation is created. The target name of
# the created test is stored in the variable GENERATE_DICTIONARY_TEST which can
# be accessed by the calling CMakeLists.txt in order to manage dependencies.
#
# IMPORTANT: it works only for mixed mode: ROOT pcms and here it is still old non-module style.
# [something to be fixed on ROOT CMake side]
#
# Requires: ROOT_GENERATE_DICTIONARY()
#-------------------------------------------------------------------------------
function(RB_GENERATE_DICTIONARY dictname)
CMAKE_PARSE_ARGUMENTS(ARG "" "" "LINKDEF;DEPENDS;OPTIONS" ${ARGN})
set(ROOT_LIBRARIES Core RIO Net Hist Gpad Tree Rint Matrix MathCore)
set(FULL_PATH_HEADERS )
foreach(hdr ${ARG_UNPARSED_ARGUMENTS})
if(IS_ABSOLUTE ${hdr})
list(APPEND FULL_PATH_HEADERS ${hdr})
else()
list(APPEND FULL_PATH_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/${hdr})
endif()
endforeach()
ROOT_GENERATE_DICTIONARY(${dictname} ${FULL_PATH_HEADERS}
MODULE ${dictname}
LINKDEF ${ARG_LINKDEF}
OPTIONS ${ARG_OPTIONS}
DEPENDENCIES ${ARG_DEPENDS})
set(targetname_libgen lib${dictname})
add_library(${targetname_libgen} EXCLUDE_FROM_ALL SHARED ${dictname}.cxx)
set_target_properties(${targetname_libgen} PROPERTIES ${ROOT_LIBRARY_PROPERTIES} )
target_link_libraries(${targetname_libgen} ${ROOT_LIBRARIES})
set_target_properties(${targetname_libgen} PROPERTIES PREFIX "")
set_property(TARGET ${targetname_libgen}
PROPERTY OUTPUT_NAME lib${dictname})
set_property(TARGET ${targetname_libgen}
APPEND PROPERTY INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR})
add_dependencies(${targetname_libgen} ${dictname})
endfunction(RB_GENERATE_DICTIONARY)