-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
285 lines (265 loc) · 11.3 KB
/
CMakeLists.txt
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
cmake_minimum_required(VERSION 3.4.3)
project(TSAR_TEST VERSION 0.0.1 LANGUAGES C CXX)
set(TSAR_TEST_DESCRIPTION "Main test set for TSAR")
set(TSAR_TEST_HOMEPAGE_URL "https://github.com/dvm-system/tsar-test")
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/sys/cmake)
set(TEST_FOLDER "Testing" CACHE STRING "Specify IDE folder for tests.")
if (TEST_FOLDER)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(TS_TEST_FOLDER ${TEST_FOLDER})
endif()
find_package(Perl)
if (NOT PERL_FOUND)
message(SEND_ERROR "Could NOT find Perl which is required to run tests. ")
else()
message(STATUS "Perl version: ${PERL_VERSION_STRING}")
endif()
set(PTS_EXECUTABLE "" CACHE FILEPATH "Path to PTS which runs tests.")
if (NOT EXISTS "${PTS_EXECUTABLE}")
message(WARNING "Unable to create targets to run tests (use PTS to run tests manually)."
" Could NOT find PTS which is required to run tests."
" Set PTS_EXECUTABLE variable.")
get_filename_component(TS_PTS_PATH "${PTS_EXECUTABLE}" ABSOLUTE)
else()
message(STATUS "Perl executable: ${PERL_EXECUTABLE}")
endif()
find_package(TSAR 3.0.0)
if (TSAR_FOUND)
message(STATUS "TSAR version: ${TSAR_VERSION}")
message(STATUS "TSAR based on LLVM version: ${TSAR_LLVM_VERSION}")
if (TSAR_LLVM_TOOLS)
set(TS_CLANG_TOOL)
if ("clang" IN_LIST TSAR_LLVM_TOOLS)
set(TS_CLANG_TOOL clang)
endif()
if (TS_CLANG_TOOL)
message(STATUS "Use Clang from TSAR package.")
endif()
set(TS_LLVM_LINK_TOOL)
if ("llvm-link" IN_LIST TSAR_LLVM_TOOLS)
set(TS_LLVM_LINK_TOOL llvm-link)
endif()
if (TS_LLVM_LINK_TOOL)
message(STATUS "Use llvm-link from TSAR package.")
endif()
set(TS_LLVM_PROFDATA_TOOL)
if ("llvm-profdata" IN_LIST TSAR_LLVM_TOOLS)
set(TS_LLVM_PROFDATA_TOOL llvm-profdata)
endif()
if (TS_LLVM_PROFDATA_TOOL)
message(STATUS "Use llvm-profdata from TSAR package.")
endif()
endif()
if (TSAR_EXECUTABLE)
set(TC_SUFFIX "")
if (TSAR_CONFIGURATION)
set(TC_DEFAULT_CONFIGURATION ${TSAR_CONFIGURATION})
else()
set(TC_DEFAULT_CONFIGURATION UNKNOWN)
endif()
elseif (TSAR_EXECUTABLE_RELEASE)
set(TC_SUFFIX _RELEASE)
set(TC_DEFAULT_CONFIGURATION RELEASE)
elseif (TSAR_EXECUTABLE_RELWITHDEBINFO)
set(TC_SUFFIX _RELWITHDEBINFO)
set(TC_DEFAULT_CONFIGURATION RELWITHDEBINFO)
else()
list(GET TSAR_CONFIGURATIONS 0 TSAR_CONFIGURATION)
string(TOUPPER ${TSAR_CONFIGURATION} TC_SUFFIX)
set(TC_SUFFIX "_${TS_SUFFIX}")
set(TC_DEFAULT_CONFIGURATION ${TC_SUFFIX})
endif()
message(STATUS "TSAR default configuration: ${TC_DEFAULT_CONFIGURATION}")
set(TS_TSAR_DEFAULT_PATH "${TSAR_EXECUTABLE${TC_SUFFIX}}")
set(TS_INCLUDE_DEFAULT_PATH "${TSAR_INCLUDE_PATH${TC_SUFFIX}}")
set(TS_BINARY_DEFAULT_DIR "${TSAR_BINARY_DIR${TC_SUFFIX}}")
if (NOT CMAKE_CONFIGURATION_TYPES)
set(TS_TSAR_PATH "${TS_TSAR_DEFAULT_PATH}")
set(TS_INCLUDE_PATH "${TS_INCLUDE_DEFAULT_PATH}")
set(TS_LIBRARY_PATH "'$<SHELL_PATH:${TS_BINARY_DEFAULT_DIR}/../lib>'")
file(GLOB TS_OMP_LIBRARIES LIST_DIRECTORIES false
RELATIVE ${TS_LIBRARY_PATH} ${TS_LIBRARY_PATH}/*omp.*)
if (TS_CLANG_TOOL)
set(TS_CLANG_PATH "${TS_BINARY_DEFAULT_DIR}/${TS_CLANG_TOOL}${CMAKE_EXECUTABLE_SUFFIX}")
endif()
if (TS_LLVM_LINK_TOOL)
set(TS_LLVM_LINK_PATH "${TS_BINARY_DEFAULT_DIR}/${TS_LLVM_LINK_TOOL}${CMAKE_EXECUTABLE_SUFFIX}")
endif()
if (TS_LLVM_PROFDATA_TOOL)
set(TS_LLVM_PROFDATA_PATH "${TS_BINARY_DEFAULT_DIR}/${TS_LLVM_PROFDATA_TOOL}${CMAKE_EXECUTABLE_SUFFIX}")
endif()
else()
set(TS_TSAR_PATH)
set(TS_INCLUDE_PATH)
set(TS_CLANG_PATH)
set(TS_LLVM_LINK_PATH)
set(TS_LLVM_PROFDATA_PATH)
foreach(CONFIG_NAME ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${CONFIG_NAME} C)
list(FIND TSAR_CONFIGURATIONS ${C} TSAR_ENABLE_${C})
if (TSAR_ENABLE_${C} EQUAL -1)
message(WARNING "${CONFIG_NAME} configuration of TSAR package is not available, use default TSAR configuration.")
set(TSAR_EXECUTABLE_${C} "${TS_TSAR_DEFAULT_PATH}")
set(TSAR_INCLUDE_PATH_${C} "${TS_INCLUDE_DEFAULT_PATH}")
set(TSAR_BINARY_DIR_${C} "${TS_BINARY_DEFAULT_DIR}")
endif()
set(TS_TSAR_PATH "${TS_TSAR_PATH}$<$<CONFIG:${C}>:${TSAR_EXECUTABLE_${C}}>")
if (TSAR_INCLUDE_PATH_${C})
set(TS_INCLUDE_PATH "${TS_INCLUDE_PATH}$<$<CONFIG:${C}>:${TSAR_INCLUDE_PATH_${C}}>")
endif()
if (TS_CLANG_TOOL)
set(TS_CLANG_PATH "${TS_CLANG_PATH}$<$<CONFIG:${C}>:${TSAR_BINARY_DIR_${C}}/${TS_CLANG_TOOL}${CMAKE_EXECUTABLE_SUFFIX}>")
endif()
if (TS_LLVM_LINK_TOOL)
set(TS_LLVM_LINK_PATH "${TS_LLVM_LINK_PATH}$<$<CONFIG:${C}>:${TSAR_BINARY_DIR_${C}}/${TS_LLVM_LINK_TOOL}${CMAKE_EXECUTABLE_SUFFIX}>")
endif()
if (TS_LLVM_PROFDATA_TOOL)
set(TS_LLVM_PROFDATA_PATH "${TS_LLVM_PROFDATA_PATH}$<$<CONFIG:${C}>:${TSAR_BINARY_DIR_${C}}/${TS_LLVM_PROFDATA_TOOL}${CMAKE_EXECUTABLE_SUFFIX}>")
endif()
set(TS_LIBRARY_PATH "'$<SHELL_PATH:${TSAR_BINARY_DIR_${C}}/../lib>'")
file(GLOB TS_OMP_LIBRARIES LIST_DIRECTORIES false
RELATIVE ${TS_LIBRARY_PATH} ${TS_LIBRARY_PATH}/*omp.*)
endforeach()
endif()
set(TS_TSAR_PATH "$<SHELL_PATH:${TS_TSAR_PATH}>")
if (TS_INCLUDE_PATH)
set(TS_INCLUDE_PATH "'$<SHELL_PATH:${TS_INCLUDE_PATH}>'")
endif()
if (TS_CLANG_TOOL)
set(TS_CLANG_PATH "$<SHELL_PATH:${TS_CLANG_PATH}>")
endif()
if (TS_LLVM_LINK_TOOL)
set(TS_LLVM_LINK_PATH "$<SHELL_PATH:${TS_LLVM_LINK_PATH}>")
endif()
if (TS_LLVM_PROFDATA_TOOL)
set(TS_LLVM_PROFDATA_PATH "$<SHELL_PATH:${TS_LLVM_PROFDATA_PATH}>")
endif()
endif()
if (NOT TS_CLANG_PATH OR NOT TS_LLVM_LINK_PATH OR NOT TS_LLVM_PROFDATA_PATH)
string(REGEX REPLACE "[A-Za-z].*" "" LLVM_VERSION_TO_SEARCH ${TSAR_LLVM_VERSION})
find_package(LLVM ${LLVM_VERSION_TO_SEARCH})
if (LLVM_FOUND)
set(TS_LIBRARY_PATH "${TS_LIBRARY_PATH} '$<SHELL_PATH:${LLVM_BINARY_DIR}/lib>'")
file(GLOB TS_OMP_LIBRARIES LIST_DIRECTORIES false
RELATIVE ${LLVM_BINARY_DIR}/lib ${LLVM_BINARY_DIR}/lib/*omp.*)
message(STATUS "LLVM version: ${LLVM_VERSION}")
if (NOT TS_LLVM_LINK_PATH)
if (TARGET llvm-link)
get_property(LLVM_LINK_CONFIGURATIONS TARGET llvm-link PROPERTY IMPORTED_CONFIGURATIONS)
if (LLVM_LINK_CONFIGURATIONS)
list(GET LLVM_LINK_CONFIGURATIONS 0 LLVM_LINK_CONFIG)
get_property(TS_LLVM_LINK_PATH TARGET llvm-link PROPERTY IMPORTED_LOCATION_${LLVM_LINK_CONFIG})
message(STATUS "Find llvm-link configuration: ${LLVM_LINK_CONFIG}")
else()
get_property(TS_LLVM_LINK_PATH TARGET llvm-link PROPERTY IMPORTED_LOCATION)
endif()
endif()
if (NOT TS_LLVM_LINK_PATH)
message(WARNING "Could NOT find suitable llvm-link executable, be sure it is installed.")
else()
message(STATUS "llvm-link executable: ${TS_LLVM_LINK_PATH}")
endif()
endif()
if (NOT TS_LLVM_PROFDATA_PATH)
if (TARGET llvm-profdata)
get_property(LLVM_PROFDATA_CONFIGURATIONS TARGET llvm-profdata PROPERTY IMPORTED_CONFIGURATIONS)
if (LLVM_PROFDATA_CONFIGURATIONS)
list(GET LLVM_PROFDATA_CONFIGURATIONS 0 LLVM_PROFDATA_CONFIG)
get_property(TS_LLVM_PROFDATA_PATH TARGET llvm-profdata PROPERTY IMPORTED_LOCATION_${LLVM_PROFDATA_CONFIG})
message(STATUS "Find llvm-profdata configuration: ${LLVM_PROFDATA_CONFIG}")
else()
get_property(TS_LLVM_PROFDATA_PATH TARGET llvm-profdata PROPERTY IMPORTED_LOCATION)
endif()
endif()
if (NOT TS_LLVM_PROFDATA_PATH)
message(WARNING "Could NOT find suitable llvm-profdata executable, be sure it is installed.")
else()
message(STATUS "llvm-profdata executable: ${TS_LLVM_PROFDATA_PATH}")
endif()
endif()
if (NOT TS_CLANG_PATH)
message(STATUS "Lookup for Clang in ${LLVM_BINARY_DIR}/lib/cmake/clang")
find_package(Clang HINTS "${LLVM_BINARY_DIR}/lib/cmake/clang" NO_DEFAULT_PATH)
if (TARGET clang)
get_property(CLANG_CONFIGURATIONS TARGET clang PROPERTY IMPORTED_CONFIGURATIONS)
if (CLANG_CONFIGURATIONS)
list(GET CLANG_CONFIGURATIONS 0 CLANG_CONFIG)
get_property(TS_CLANG_PATH TARGET clang PROPERTY IMPORTED_LOCATION_${CLANG_CONFIG})
message(STATUS "Find Clang configuration: ${CLANG_CONFIG}")
else()
get_property(TS_CLANG_PATH TARGET clang PROPERTY IMPORTED_LOCATION)
endif()
if (TSAR_LLVM_VERSION)
set(TS_INCLUDE_PATH "${TS_INCLUDE_PATH} '$<SHELL_PATH:${LLVM_BINARY_DIR}/lib/clang/${TSAR_LLVM_VERSION}/include>'")
endif()
endif()
if (NOT TS_CLANG_PATH)
message(WARNING "Could NOT find suitable Clang executable, be sure it is installed.")
else()
message(STATUS "Clang executable: ${TS_CLANG_PATH}")
endif()
endif()
endif()
endif()
if (NOT TS_OMP_LIBRARIES)
message(WARNING "Colud NOT find OpenMP libraries, disable OpenMP-based tests")
else()
string(REPLACE ";" " " TS_OMP_LIBRARIES "${TS_OMP_LIBRARIES}")
endif()
add_custom_target(tsar-test-resources ALL)
set_target_properties(tsar-test-resources PROPERTIES FOLDER Misc)
set(DVM_DIR "" CACHE PATH "Path to DVM System")
if (WIN32)
set(DVM_SCRIPT_NAME dvm.bat)
else()
set(DVM_SCRIPT_NAME dvm)
endif()
if (EXISTS "${DVM_DIR}")
get_filename_component(DVM_EXECUTABLE "${DVM_DIR}/user/${DVM_SCRIPT_NAME}" ABSOLUTE)
endif()
if (NOT EXISTS "${DVM_EXECUTABLE}")
message(WARNING "Could NOT find DVM executable."
" Set DVM_DIR to run DVMH-based tests.")
else()
set(TS_DVM_PATH ${CMAKE_CURRENT_SOURCE_DIR}/sys/${DVM_SCRIPT_NAME})
if (WIN32)
add_custom_command(TARGET tsar-test-resources POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "${DVM_EXECUTABLE}" "${TS_DVM_PATH}"
COMMAND ${PERL_EXECUTABLE} "-pi.orig -e\"s/^(?=\\h+set \\\"DVMH_)/rem/\"" "${TS_DVM_PATH}"
COMMAND ${CMAKE_COMMAND} -E rm "${TS_DVM_PATH}.orig"
COMMENT "Copy DVM executable to ${TS_DVM_PATH}"
)
else()
add_custom_command(TARGET tsar-test-resources POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "${DVM_EXECUTABLE}" "${TS_DVM_PATH}"
COMMAND ${PERL_EXECUTABLE} "-pi -e\"s/^(?=export DVMH_)/#/\"" "${TS_DVM_PATH}"
COMMENT "Copy DVM executable to ${TS_DVM_PATH}"
)
endif()
endif()
set(PTS_OPTIONS "--total-time --failed f -s" CACHE STRING "Default PTS options.")
set(TS_PTS_OPTIONS "${PTS_OPTIONS}")
string(REPLACE " " ";" TS_PTS_OPTION_LIST "${PTS_OPTIONS}")
get_filename_component(PTS_PLUGIN_PATH sys ABSOLUTE)
get_filename_component(PTS_TASK_PATH sys ABSOLUTE)
configure_file(.ptsconfig.in ${CMAKE_CURRENT_SOURCE_DIR}/.ptsconfig @ONLY)
macro(quote_path P)
if (${P})
set(${P} "'\"${${P}}\"'")
endif()
endmacro()
quote_path(TS_TSAR_PATH)
quote_path(TS_CLANG_PATH)
quote_path(TS_LLVM_LINK_PATH)
quote_path(TS_LLVM_PROFDATA_PATH)
quote_path(TS_DVM_PATH)
configure_file(sys/config.in sys/config.gen @ONLY)
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/sys/config"
INPUT "${CMAKE_CURRENT_BINARY_DIR}/sys/config.gen")
add_custom_command(TARGET tsar-test-resources POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/sys/config"
"${CMAKE_CURRENT_SOURCE_DIR}/sys/config"
COMMENT "Configure ${CMAKE_CURRENT_SOURCE_DIR}/sys/config"
)
enable_testing()
add_subdirectory(tests)