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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
|
macro(ei_add_property prop value)
get_property(previous GLOBAL PROPERTY ${prop})
if ((NOT previous) OR (previous STREQUAL ""))
set_property(GLOBAL PROPERTY ${prop} "${value}")
else()
set_property(GLOBAL PROPERTY ${prop} "${previous} ${value}")
endif()
endmacro(ei_add_property)
#internal. See documentation of ei_add_test for details.
macro(ei_add_test_internal testname testname_with_suffix)
set(targetname ${testname_with_suffix})
set(filename ${testname}.cpp)
add_executable(${targetname} ${filename})
if (targetname MATCHES "^eigen2_")
add_dependencies(eigen2_buildtests ${targetname})
else()
add_dependencies(buildtests ${targetname})
endif()
if(EIGEN_NO_ASSERTION_CHECKING)
ei_add_target_property(${targetname} COMPILE_FLAGS "-DEIGEN_NO_ASSERTION_CHECKING=1")
else(EIGEN_NO_ASSERTION_CHECKING)
if(EIGEN_DEBUG_ASSERTS)
ei_add_target_property(${targetname} COMPILE_FLAGS "-DEIGEN_DEBUG_ASSERTS=1")
endif(EIGEN_DEBUG_ASSERTS)
endif(EIGEN_NO_ASSERTION_CHECKING)
ei_add_target_property(${targetname} COMPILE_FLAGS "-DEIGEN_TEST_MAX_SIZE=${EIGEN_TEST_MAX_SIZE}")
ei_add_target_property(${targetname} COMPILE_FLAGS "-DEIGEN_TEST_FUNC=${testname}")
if(MSVC AND NOT EIGEN_SPLIT_LARGE_TESTS)
ei_add_target_property(${targetname} COMPILE_FLAGS "/bigobj")
endif()
# let the user pass flags.
if(${ARGC} GREATER 2)
ei_add_target_property(${targetname} COMPILE_FLAGS "${ARGV2}")
endif(${ARGC} GREATER 2)
if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO)
target_link_libraries(${targetname} ${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO})
endif()
if(EXTERNAL_LIBS)
target_link_libraries(${targetname} ${EXTERNAL_LIBS})
endif()
if(${ARGC} GREATER 3)
set(libs_to_link ${ARGV3})
# it could be that some cmake module provides a bad library string " " (just spaces),
# and that severely breaks target_link_libraries ("can't link to -l-lstdc++" errors).
# so we check for strings containing only spaces.
string(STRIP "${libs_to_link}" libs_to_link_stripped)
string(LENGTH "${libs_to_link_stripped}" libs_to_link_stripped_length)
if(${libs_to_link_stripped_length} GREATER 0)
# notice: no double quotes around ${libs_to_link} here. It may be a list.
target_link_libraries(${targetname} ${libs_to_link})
endif()
endif()
if(EIGEN_BIN_BASH_EXISTS)
add_test(${testname_with_suffix} "${Eigen_SOURCE_DIR}/test/runtest.sh" "${testname_with_suffix}")
else()
add_test(${testname_with_suffix} "${targetname}")
endif()
endmacro(ei_add_test_internal)
# Macro to add a test
#
# the unique mandatory parameter testname must correspond to a file
# <testname>.cpp which follows this pattern:
#
# #include "main.h"
# void test_<testname>() { ... }
#
# Depending on the contents of that file, this macro can have 2 behaviors,
# see below.
#
# The optional 2nd parameter is libraries to link to.
#
# A. Default behavior
#
# this macro adds an executable <testname> as well as a ctest test
# named <testname> too.
#
# On platforms with bash simply run:
# "ctest -V" or "ctest -V -R <testname>"
# On other platform use ctest as usual
#
# B. Multi-part behavior
#
# If the source file matches the regexp
# CALL_SUBTEST_[0-9]+|EIGEN_TEST_PART_[0-9]+
# then it is interpreted as a multi-part test. The behavior then depends on the
# CMake option EIGEN_SPLIT_LARGE_TESTS, which is ON by default.
#
# If EIGEN_SPLIT_LARGE_TESTS is OFF, the behavior is the same as in A (the multi-part
# aspect is ignored).
#
# If EIGEN_SPLIT_LARGE_TESTS is ON, the test is split into multiple executables
# test_<testname>_<N>
# where N runs from 1 to the greatest occurence found in the source file. Each of these
# executables is built passing -DEIGEN_TEST_PART_N. This allows to split large tests
# into smaller executables.
#
# Moreover, targets <testname> are still generated, they
# have the effect of building all the parts of the test.
#
# Again, ctest -R allows to run all matching tests.
macro(ei_add_test testname)
get_property(EIGEN_TESTS_LIST GLOBAL PROPERTY EIGEN_TESTS_LIST)
set(EIGEN_TESTS_LIST "${EIGEN_TESTS_LIST}${testname}\n")
set_property(GLOBAL PROPERTY EIGEN_TESTS_LIST "${EIGEN_TESTS_LIST}")
file(READ "${testname}.cpp" test_source)
set(parts 0)
string(REGEX MATCHALL "CALL_SUBTEST_[0-9]+|EIGEN_TEST_PART_[0-9]+|EIGEN_SUFFIXES(;[0-9]+)+"
occurences "${test_source}")
string(REGEX REPLACE "CALL_SUBTEST_|EIGEN_TEST_PART_|EIGEN_SUFFIXES" "" suffixes "${occurences}")
list(REMOVE_DUPLICATES suffixes)
if(EIGEN_SPLIT_LARGE_TESTS AND suffixes)
add_custom_target(${testname})
foreach(suffix ${suffixes})
ei_add_test_internal(${testname} ${testname}_${suffix}
"${ARGV1} -DEIGEN_TEST_PART_${suffix}=1" "${ARGV2}")
add_dependencies(${testname} ${testname}_${suffix})
endforeach(suffix)
else(EIGEN_SPLIT_LARGE_TESTS AND suffixes)
set(symbols_to_enable_all_parts "")
foreach(suffix ${suffixes})
set(symbols_to_enable_all_parts
"${symbols_to_enable_all_parts} -DEIGEN_TEST_PART_${suffix}=1")
endforeach(suffix)
ei_add_test_internal(${testname} ${testname} "${ARGV1} ${symbols_to_enable_all_parts}" "${ARGV2}")
endif(EIGEN_SPLIT_LARGE_TESTS AND suffixes)
endmacro(ei_add_test)
# adds a failtest, i.e. a test that succeed if the program fails to compile
# note that the test runner for these is CMake itself, when passed -DEIGEN_FAILTEST=ON
# so here we're just running CMake commands immediately, we're not adding any targets.
macro(ei_add_failtest testname)
get_property(EIGEN_FAILTEST_FAILURE_COUNT GLOBAL PROPERTY EIGEN_FAILTEST_FAILURE_COUNT)
get_property(EIGEN_FAILTEST_COUNT GLOBAL PROPERTY EIGEN_FAILTEST_COUNT)
message(STATUS "Checking failtest: ${testname}")
set(filename "${testname}.cpp")
file(READ "${filename}" test_source)
try_compile(succeeds_when_it_should_fail
"${CMAKE_CURRENT_BINARY_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/${filename}"
COMPILE_DEFINITIONS "-DEIGEN_SHOULD_FAIL_TO_BUILD")
if (succeeds_when_it_should_fail)
message(STATUS "FAILED: ${testname} build succeeded when it should have failed")
endif()
try_compile(succeeds_when_it_should_succeed
"${CMAKE_CURRENT_BINARY_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/${filename}"
COMPILE_DEFINITIONS)
if (NOT succeeds_when_it_should_succeed)
message(STATUS "FAILED: ${testname} build failed when it should have succeeded")
endif()
if (succeeds_when_it_should_fail OR NOT succeeds_when_it_should_succeed)
math(EXPR EIGEN_FAILTEST_FAILURE_COUNT ${EIGEN_FAILTEST_FAILURE_COUNT}+1)
endif()
math(EXPR EIGEN_FAILTEST_COUNT ${EIGEN_FAILTEST_COUNT}+1)
set_property(GLOBAL PROPERTY EIGEN_FAILTEST_FAILURE_COUNT ${EIGEN_FAILTEST_FAILURE_COUNT})
set_property(GLOBAL PROPERTY EIGEN_FAILTEST_COUNT ${EIGEN_FAILTEST_COUNT})
endmacro(ei_add_failtest)
# print a summary of the different options
macro(ei_testing_print_summary)
message(STATUS "************************************************************")
message(STATUS "*** Eigen's unit tests configuration summary ***")
message(STATUS "************************************************************")
message(STATUS "")
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "Build site: ${SITE}")
message(STATUS "Build string: ${BUILDNAME}")
get_property(EIGEN_TESTING_SUMMARY GLOBAL PROPERTY EIGEN_TESTING_SUMMARY)
get_property(EIGEN_TESTED_BACKENDS GLOBAL PROPERTY EIGEN_TESTED_BACKENDS)
get_property(EIGEN_MISSING_BACKENDS GLOBAL PROPERTY EIGEN_MISSING_BACKENDS)
message(STATUS "Enabled backends: ${EIGEN_TESTED_BACKENDS}")
message(STATUS "Disabled backends: ${EIGEN_MISSING_BACKENDS}")
if(EIGEN_DEFAULT_TO_ROW_MAJOR)
message(STATUS "Default order: Row-major")
else()
message(STATUS "Default order: Column-major")
endif()
if(EIGEN_TEST_NO_EXPLICIT_ALIGNMENT)
message(STATUS "Explicit alignment (hence vectorization) disabled")
elseif(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION)
message(STATUS "Explicit vectorization disabled (alignment kept enabled)")
else()
message(STATUS "Maximal matrix/vector size: ${EIGEN_TEST_MAX_SIZE}")
if(EIGEN_TEST_SSE2)
message(STATUS "SSE2: ON")
else()
message(STATUS "SSE2: Using architecture defaults")
endif()
if(EIGEN_TEST_SSE3)
message(STATUS "SSE3: ON")
else()
message(STATUS "SSE3: Using architecture defaults")
endif()
if(EIGEN_TEST_SSSE3)
message(STATUS "SSSE3: ON")
else()
message(STATUS "SSSE3: Using architecture defaults")
endif()
if(EIGEN_TEST_SSE4_1)
message(STATUS "SSE4.1: ON")
else()
message(STATUS "SSE4.1: Using architecture defaults")
endif()
if(EIGEN_TEST_SSE4_2)
message(STATUS "SSE4.2: ON")
else()
message(STATUS "SSE4.2: Using architecture defaults")
endif()
if(EIGEN_TEST_ALTIVEC)
message(STATUS "Altivec: ON")
else()
message(STATUS "Altivec: Using architecture defaults")
endif()
if(EIGEN_TEST_NEON)
message(STATUS "ARM NEON: ON")
else()
message(STATUS "ARM NEON: Using architecture defaults")
endif()
endif() # vectorization / alignment options
message(STATUS "\n${EIGEN_TESTING_SUMMARY}")
message(STATUS "************************************************************")
endmacro(ei_testing_print_summary)
macro(ei_init_testing)
define_property(GLOBAL PROPERTY EIGEN_TESTED_BACKENDS BRIEF_DOCS " " FULL_DOCS " ")
define_property(GLOBAL PROPERTY EIGEN_MISSING_BACKENDS BRIEF_DOCS " " FULL_DOCS " ")
define_property(GLOBAL PROPERTY EIGEN_TESTING_SUMMARY BRIEF_DOCS " " FULL_DOCS " ")
define_property(GLOBAL PROPERTY EIGEN_TESTS_LIST BRIEF_DOCS " " FULL_DOCS " ")
set_property(GLOBAL PROPERTY EIGEN_TESTED_BACKENDS "")
set_property(GLOBAL PROPERTY EIGEN_MISSING_BACKENDS "")
set_property(GLOBAL PROPERTY EIGEN_TESTING_SUMMARY "")
set_property(GLOBAL PROPERTY EIGEN_TESTS_LIST "")
define_property(GLOBAL PROPERTY EIGEN_FAILTEST_FAILURE_COUNT BRIEF_DOCS " " FULL_DOCS " ")
define_property(GLOBAL PROPERTY EIGEN_FAILTEST_COUNT BRIEF_DOCS " " FULL_DOCS " ")
set_property(GLOBAL PROPERTY EIGEN_FAILTEST_FAILURE_COUNT "0")
set_property(GLOBAL PROPERTY EIGEN_FAILTEST_COUNT "0")
endmacro(ei_init_testing)
macro(ei_set_sitename)
# if the sitename is not yet set, try to set it
if(NOT ${SITE} OR ${SITE} STREQUAL "")
set(eigen_computername $ENV{COMPUTERNAME})
set(eigen_hostname $ENV{HOSTNAME})
if(eigen_hostname)
set(SITE ${eigen_hostname})
elseif(eigen_computername)
set(SITE ${eigen_computername})
endif()
endif()
# in case it is already set, enforce lower case
if(SITE)
string(TOLOWER ${SITE} SITE)
endif()
endmacro(ei_set_sitename)
macro(ei_get_compilerver VAR)
if(MSVC)
# on windows system, we use a modified CMake script
include(CMakeDetermineVSServicePack)
DetermineVSServicePack( my_service_pack )
if( my_service_pack )
set(${VAR} ${my_service_pack})
else()
set(${VAR} "na")
endif()
else()
# on all other system we rely on ${CMAKE_CXX_COMPILER}
# supporting a "--version" flag
exec_program( ${CMAKE_CXX_COMPILER}
ARGS --version
OUTPUT_VARIABLE eigen_cxx_compiler_version_raw
)
# first extract the compiler name which is the first word
string( REGEX REPLACE ".*(llvm\\-g\\+\\+|g\\+\\+|icpc|clang).*" "\\1"
eigen_cxx_compiler_name ${eigen_cxx_compiler_version_raw})
if(eigen_cxx_compiler_name MATCHES ".*g\\+\\+.*")
string( REGEX REPLACE ".* ([0-9])\\.([0-9])\\.([0-9]).*" "\\1.\\2.\\3"
eigen_cxx_compiler_version ${eigen_cxx_compiler_version_raw})
elseif(eigen_cxx_compiler_name MATCHES "icpc|clang")
string( REGEX REPLACE ".* ([0-9]+\\.[0-9]+\\.[0-9]+|[0-9]+\\.[0-9]+).*" "\\1"
eigen_cxx_compiler_version ${eigen_cxx_compiler_version_raw})
else()
set(eigen_cxx_compiler_version "_")
endif()
set(${VAR} "${eigen_cxx_compiler_name}-${eigen_cxx_compiler_version}")
endif()
endmacro(ei_get_compilerver)
macro(ei_get_cxxflags VAR)
set(${VAR} "")
ei_is_64bit_env(IS_64BIT_ENV)
if(EIGEN_TEST_NEON)
set(${VAR} NEON)
elseif(EIGEN_TEST_ALTIVEC)
set(${VAR} ALVEC)
elseif(EIGEN_TEST_SSE4_2)
set(${VAR} SSE42)
elseif(EIGEN_TEST_SSE4_1)
set(${VAR} SSE41)
elseif(EIGEN_TEST_SSSE3)
set(${VAR} SSSE3)
elseif(EIGEN_TEST_SSE3)
set(${VAR} SSE3)
elseif(EIGEN_TEST_SSE2 OR IS_64BIT_ENV)
set(${VAR} SSE2)
endif()
if(EIGEN_TEST_OPENMP)
if (${VAR} STREQUAL "")
set(${VAR} OMP)
else()
set(${VAR} ${${VAR}}-OMP)
endif()
endif()
if(EIGEN_DEFAULT_TO_ROW_MAJOR)
if (${VAR} STREQUAL "")
set(${VAR} ROW)
else()
set(${VAR} ${${VAR}}-ROWMAJ)
endif()
endif()
endmacro(ei_get_cxxflags)
macro(ei_set_build_string)
ei_get_compilerver(LOCAL_COMPILER_VERSION)
ei_get_cxxflags(LOCAL_COMPILER_FLAGS)
include(EigenDetermineOSVersion)
DetermineOSVersion(OS_VERSION)
set(TMP_BUILD_STRING ${OS_VERSION}-${LOCAL_COMPILER_VERSION})
if (NOT ${LOCAL_COMPILER_FLAGS} STREQUAL "")
set(TMP_BUILD_STRING ${TMP_BUILD_STRING}-${LOCAL_COMPILER_FLAGS})
endif()
ei_is_64bit_env(IS_64BIT_ENV)
if(NOT IS_64BIT_ENV)
set(TMP_BUILD_STRING ${TMP_BUILD_STRING}-32bit)
else()
set(TMP_BUILD_STRING ${TMP_BUILD_STRING}-64bit)
endif()
string(TOLOWER ${TMP_BUILD_STRING} BUILDNAME)
endmacro(ei_set_build_string)
macro(ei_is_64bit_env VAR)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/is64.cpp"
"int main() { return (sizeof(int*) == 8 ? 1 : 0); }
")
try_run(run_res compile_res
${CMAKE_CURRENT_BINARY_DIR} "${CMAKE_CURRENT_BINARY_DIR}/is64.cpp"
RUN_OUTPUT_VARIABLE run_output)
if(compile_res AND run_res)
set(${VAR} ${run_res})
elseif(CMAKE_CL_64)
set(${VAR} 1)
elseif("$ENV{Platform}" STREQUAL "X64") # nmake 64 bit
set(${VAR} 1)
endif()
endmacro(ei_is_64bit_env)
|