1 2 macro(ei_add_property prop value) 3 get_property(previous GLOBAL PROPERTY ${prop}) 4 if ((NOT previous) OR (previous STREQUAL "")) 5 set_property(GLOBAL PROPERTY ${prop} "${value}") 6 else() 7 set_property(GLOBAL PROPERTY ${prop} "${previous} ${value}") 8 endif() 9 endmacro(ei_add_property) 10 11 #internal. See documentation of ei_add_test for details. 12 macro(ei_add_test_internal testname testname_with_suffix) 13 set(targetname ${testname_with_suffix}) 14 15 set(filename ${testname}.cpp) 16 add_executable(${targetname} ${filename}) 17 if (targetname MATCHES "^eigen2_") 18 add_dependencies(eigen2_buildtests ${targetname}) 19 else() 20 add_dependencies(buildtests ${targetname}) 21 endif() 22 23 if(EIGEN_NO_ASSERTION_CHECKING) 24 ei_add_target_property(${targetname} COMPILE_FLAGS "-DEIGEN_NO_ASSERTION_CHECKING=1") 25 else(EIGEN_NO_ASSERTION_CHECKING) 26 if(EIGEN_DEBUG_ASSERTS) 27 ei_add_target_property(${targetname} COMPILE_FLAGS "-DEIGEN_DEBUG_ASSERTS=1") 28 endif(EIGEN_DEBUG_ASSERTS) 29 endif(EIGEN_NO_ASSERTION_CHECKING) 30 31 ei_add_target_property(${targetname} COMPILE_FLAGS "-DEIGEN_TEST_MAX_SIZE=${EIGEN_TEST_MAX_SIZE}") 32 33 ei_add_target_property(${targetname} COMPILE_FLAGS "-DEIGEN_TEST_FUNC=${testname}") 34 35 if(MSVC AND NOT EIGEN_SPLIT_LARGE_TESTS) 36 ei_add_target_property(${targetname} COMPILE_FLAGS "/bigobj") 37 endif() 38 39 # let the user pass flags. 40 if(${ARGC} GREATER 2) 41 ei_add_target_property(${targetname} COMPILE_FLAGS "${ARGV2}") 42 endif(${ARGC} GREATER 2) 43 44 if(EIGEN_TEST_CUSTOM_CXX_FLAGS) 45 ei_add_target_property(${targetname} COMPILE_FLAGS "${EIGEN_TEST_CUSTOM_CXX_FLAGS}") 46 endif() 47 48 if(EIGEN_STANDARD_LIBRARIES_TO_LINK_TO) 49 target_link_libraries(${targetname} ${EIGEN_STANDARD_LIBRARIES_TO_LINK_TO}) 50 endif() 51 if(EXTERNAL_LIBS) 52 target_link_libraries(${targetname} ${EXTERNAL_LIBS}) 53 endif() 54 if(EIGEN_TEST_CUSTOM_LINKER_FLAGS) 55 target_link_libraries(${targetname} ${EIGEN_TEST_CUSTOM_LINKER_FLAGS}) 56 endif() 57 58 if(${ARGC} GREATER 3) 59 set(libs_to_link ${ARGV3}) 60 # it could be that some cmake module provides a bad library string " " (just spaces), 61 # and that severely breaks target_link_libraries ("can't link to -l-lstdc++" errors). 62 # so we check for strings containing only spaces. 63 string(STRIP "${libs_to_link}" libs_to_link_stripped) 64 string(LENGTH "${libs_to_link_stripped}" libs_to_link_stripped_length) 65 if(${libs_to_link_stripped_length} GREATER 0) 66 # notice: no double quotes around ${libs_to_link} here. It may be a list. 67 target_link_libraries(${targetname} ${libs_to_link}) 68 endif() 69 endif() 70 71 if(EIGEN_BIN_BASH_EXISTS) 72 add_test(${testname_with_suffix} "${Eigen_SOURCE_DIR}/test/runtest.sh" "${testname_with_suffix}") 73 else() 74 add_test(${testname_with_suffix} "${targetname}") 75 endif() 76 77 endmacro(ei_add_test_internal) 78 79 # Macro to add a test 80 # 81 # the unique mandatory parameter testname must correspond to a file 82 # <testname>.cpp which follows this pattern: 83 # 84 # #include "main.h" 85 # void test_<testname>() { ... } 86 # 87 # Depending on the contents of that file, this macro can have 2 behaviors, 88 # see below. 89 # 90 # The optional 2nd parameter is libraries to link to. 91 # 92 # A. Default behavior 93 # 94 # this macro adds an executable <testname> as well as a ctest test 95 # named <testname> too. 96 # 97 # On platforms with bash simply run: 98 # "ctest -V" or "ctest -V -R <testname>" 99 # On other platform use ctest as usual 100 # 101 # B. Multi-part behavior 102 # 103 # If the source file matches the regexp 104 # CALL_SUBTEST_[0-9]+|EIGEN_TEST_PART_[0-9]+ 105 # then it is interpreted as a multi-part test. The behavior then depends on the 106 # CMake option EIGEN_SPLIT_LARGE_TESTS, which is ON by default. 107 # 108 # If EIGEN_SPLIT_LARGE_TESTS is OFF, the behavior is the same as in A (the multi-part 109 # aspect is ignored). 110 # 111 # If EIGEN_SPLIT_LARGE_TESTS is ON, the test is split into multiple executables 112 # test_<testname>_<N> 113 # where N runs from 1 to the greatest occurence found in the source file. Each of these 114 # executables is built passing -DEIGEN_TEST_PART_N. This allows to split large tests 115 # into smaller executables. 116 # 117 # Moreover, targets <testname> are still generated, they 118 # have the effect of building all the parts of the test. 119 # 120 # Again, ctest -R allows to run all matching tests. 121 macro(ei_add_test testname) 122 get_property(EIGEN_TESTS_LIST GLOBAL PROPERTY EIGEN_TESTS_LIST) 123 set(EIGEN_TESTS_LIST "${EIGEN_TESTS_LIST}${testname}\n") 124 set_property(GLOBAL PROPERTY EIGEN_TESTS_LIST "${EIGEN_TESTS_LIST}") 125 126 file(READ "${testname}.cpp" test_source) 127 set(parts 0) 128 string(REGEX MATCHALL "CALL_SUBTEST_[0-9]+|EIGEN_TEST_PART_[0-9]+|EIGEN_SUFFIXES(;[0-9]+)+" 129 occurences "${test_source}") 130 string(REGEX REPLACE "CALL_SUBTEST_|EIGEN_TEST_PART_|EIGEN_SUFFIXES" "" suffixes "${occurences}") 131 list(REMOVE_DUPLICATES suffixes) 132 if(EIGEN_SPLIT_LARGE_TESTS AND suffixes) 133 add_custom_target(${testname}) 134 foreach(suffix ${suffixes}) 135 ei_add_test_internal(${testname} ${testname}_${suffix} 136 "${ARGV1} -DEIGEN_TEST_PART_${suffix}=1" "${ARGV2}") 137 add_dependencies(${testname} ${testname}_${suffix}) 138 endforeach(suffix) 139 else(EIGEN_SPLIT_LARGE_TESTS AND suffixes) 140 set(symbols_to_enable_all_parts "") 141 foreach(suffix ${suffixes}) 142 set(symbols_to_enable_all_parts 143 "${symbols_to_enable_all_parts} -DEIGEN_TEST_PART_${suffix}=1") 144 endforeach(suffix) 145 ei_add_test_internal(${testname} ${testname} "${ARGV1} ${symbols_to_enable_all_parts}" "${ARGV2}") 146 endif(EIGEN_SPLIT_LARGE_TESTS AND suffixes) 147 endmacro(ei_add_test) 148 149 150 # adds a failtest, i.e. a test that succeed if the program fails to compile 151 # note that the test runner for these is CMake itself, when passed -DEIGEN_FAILTEST=ON 152 # so here we're just running CMake commands immediately, we're not adding any targets. 153 macro(ei_add_failtest testname) 154 get_property(EIGEN_FAILTEST_FAILURE_COUNT GLOBAL PROPERTY EIGEN_FAILTEST_FAILURE_COUNT) 155 get_property(EIGEN_FAILTEST_COUNT GLOBAL PROPERTY EIGEN_FAILTEST_COUNT) 156 157 message(STATUS "Checking failtest: ${testname}") 158 set(filename "${testname}.cpp") 159 file(READ "${filename}" test_source) 160 161 try_compile(succeeds_when_it_should_fail 162 "${CMAKE_CURRENT_BINARY_DIR}" 163 "${CMAKE_CURRENT_SOURCE_DIR}/${filename}" 164 COMPILE_DEFINITIONS "-DEIGEN_SHOULD_FAIL_TO_BUILD") 165 if (succeeds_when_it_should_fail) 166 message(STATUS "FAILED: ${testname} build succeeded when it should have failed") 167 endif() 168 169 try_compile(succeeds_when_it_should_succeed 170 "${CMAKE_CURRENT_BINARY_DIR}" 171 "${CMAKE_CURRENT_SOURCE_DIR}/${filename}" 172 COMPILE_DEFINITIONS) 173 if (NOT succeeds_when_it_should_succeed) 174 message(STATUS "FAILED: ${testname} build failed when it should have succeeded") 175 endif() 176 177 if (succeeds_when_it_should_fail OR NOT succeeds_when_it_should_succeed) 178 math(EXPR EIGEN_FAILTEST_FAILURE_COUNT ${EIGEN_FAILTEST_FAILURE_COUNT}+1) 179 endif() 180 181 math(EXPR EIGEN_FAILTEST_COUNT ${EIGEN_FAILTEST_COUNT}+1) 182 183 set_property(GLOBAL PROPERTY EIGEN_FAILTEST_FAILURE_COUNT ${EIGEN_FAILTEST_FAILURE_COUNT}) 184 set_property(GLOBAL PROPERTY EIGEN_FAILTEST_COUNT ${EIGEN_FAILTEST_COUNT}) 185 endmacro(ei_add_failtest) 186 187 # print a summary of the different options 188 macro(ei_testing_print_summary) 189 message(STATUS "************************************************************") 190 message(STATUS "*** Eigen's unit tests configuration summary ***") 191 message(STATUS "************************************************************") 192 message(STATUS "") 193 message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") 194 message(STATUS "Build site: ${SITE}") 195 message(STATUS "Build string: ${BUILDNAME}") 196 get_property(EIGEN_TESTING_SUMMARY GLOBAL PROPERTY EIGEN_TESTING_SUMMARY) 197 get_property(EIGEN_TESTED_BACKENDS GLOBAL PROPERTY EIGEN_TESTED_BACKENDS) 198 get_property(EIGEN_MISSING_BACKENDS GLOBAL PROPERTY EIGEN_MISSING_BACKENDS) 199 message(STATUS "Enabled backends: ${EIGEN_TESTED_BACKENDS}") 200 message(STATUS "Disabled backends: ${EIGEN_MISSING_BACKENDS}") 201 202 if(EIGEN_DEFAULT_TO_ROW_MAJOR) 203 message(STATUS "Default order: Row-major") 204 else() 205 message(STATUS "Default order: Column-major") 206 endif() 207 208 if(EIGEN_TEST_NO_EXPLICIT_ALIGNMENT) 209 message(STATUS "Explicit alignment (hence vectorization) disabled") 210 elseif(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION) 211 message(STATUS "Explicit vectorization disabled (alignment kept enabled)") 212 else() 213 214 message(STATUS "Maximal matrix/vector size: ${EIGEN_TEST_MAX_SIZE}") 215 216 if(EIGEN_TEST_SSE2) 217 message(STATUS "SSE2: ON") 218 else() 219 message(STATUS "SSE2: Using architecture defaults") 220 endif() 221 222 if(EIGEN_TEST_SSE3) 223 message(STATUS "SSE3: ON") 224 else() 225 message(STATUS "SSE3: Using architecture defaults") 226 endif() 227 228 if(EIGEN_TEST_SSSE3) 229 message(STATUS "SSSE3: ON") 230 else() 231 message(STATUS "SSSE3: Using architecture defaults") 232 endif() 233 234 if(EIGEN_TEST_SSE4_1) 235 message(STATUS "SSE4.1: ON") 236 else() 237 message(STATUS "SSE4.1: Using architecture defaults") 238 endif() 239 240 if(EIGEN_TEST_SSE4_2) 241 message(STATUS "SSE4.2: ON") 242 else() 243 message(STATUS "SSE4.2: Using architecture defaults") 244 endif() 245 246 if(EIGEN_TEST_ALTIVEC) 247 message(STATUS "Altivec: ON") 248 else() 249 message(STATUS "Altivec: Using architecture defaults") 250 endif() 251 252 if(EIGEN_TEST_NEON) 253 message(STATUS "ARM NEON: ON") 254 else() 255 message(STATUS "ARM NEON: Using architecture defaults") 256 endif() 257 258 endif() # vectorization / alignment options 259 260 message(STATUS "\n${EIGEN_TESTING_SUMMARY}") 261 262 message(STATUS "************************************************************") 263 endmacro(ei_testing_print_summary) 264 265 macro(ei_init_testing) 266 define_property(GLOBAL PROPERTY EIGEN_TESTED_BACKENDS BRIEF_DOCS " " FULL_DOCS " ") 267 define_property(GLOBAL PROPERTY EIGEN_MISSING_BACKENDS BRIEF_DOCS " " FULL_DOCS " ") 268 define_property(GLOBAL PROPERTY EIGEN_TESTING_SUMMARY BRIEF_DOCS " " FULL_DOCS " ") 269 define_property(GLOBAL PROPERTY EIGEN_TESTS_LIST BRIEF_DOCS " " FULL_DOCS " ") 270 271 set_property(GLOBAL PROPERTY EIGEN_TESTED_BACKENDS "") 272 set_property(GLOBAL PROPERTY EIGEN_MISSING_BACKENDS "") 273 set_property(GLOBAL PROPERTY EIGEN_TESTING_SUMMARY "") 274 set_property(GLOBAL PROPERTY EIGEN_TESTS_LIST "") 275 276 define_property(GLOBAL PROPERTY EIGEN_FAILTEST_FAILURE_COUNT BRIEF_DOCS " " FULL_DOCS " ") 277 define_property(GLOBAL PROPERTY EIGEN_FAILTEST_COUNT BRIEF_DOCS " " FULL_DOCS " ") 278 279 set_property(GLOBAL PROPERTY EIGEN_FAILTEST_FAILURE_COUNT "0") 280 set_property(GLOBAL PROPERTY EIGEN_FAILTEST_COUNT "0") 281 282 # uncomment anytime you change the ei_get_compilerver_from_cxx_version_string macro 283 # ei_test_get_compilerver_from_cxx_version_string() 284 endmacro(ei_init_testing) 285 286 macro(ei_set_sitename) 287 # if the sitename is not yet set, try to set it 288 if(NOT ${SITE} OR ${SITE} STREQUAL "") 289 set(eigen_computername $ENV{COMPUTERNAME}) 290 set(eigen_hostname $ENV{HOSTNAME}) 291 if(eigen_hostname) 292 set(SITE ${eigen_hostname}) 293 elseif(eigen_computername) 294 set(SITE ${eigen_computername}) 295 endif() 296 endif() 297 # in case it is already set, enforce lower case 298 if(SITE) 299 string(TOLOWER ${SITE} SITE) 300 endif() 301 endmacro(ei_set_sitename) 302 303 macro(ei_get_compilerver VAR) 304 if(MSVC) 305 # on windows system, we use a modified CMake script 306 include(CMakeDetermineVSServicePack) 307 DetermineVSServicePack( my_service_pack ) 308 309 if( my_service_pack ) 310 set(${VAR} ${my_service_pack}) 311 else() 312 set(${VAR} "na") 313 endif() 314 else() 315 # on all other system we rely on ${CMAKE_CXX_COMPILER} 316 # supporting a "--version" flag 317 execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version 318 COMMAND head -n 1 319 OUTPUT_VARIABLE eigen_cxx_compiler_version_string OUTPUT_STRIP_TRAILING_WHITESPACE) 320 321 ei_get_compilerver_from_cxx_version_string(${eigen_cxx_compiler_version_string} CNAME CVER) 322 323 set(${VAR} "${CNAME}-${CVER}") 324 endif() 325 endmacro(ei_get_compilerver) 326 327 # Extract compiler name and version from a raw version string 328 # WARNING: if you edit thid macro, then please test it by uncommenting 329 # the testing macro call in ei_init_testing() of the EigenTesting.cmake file. 330 # See also the ei_test_get_compilerver_from_cxx_version_string macro at the end of the file 331 macro(ei_get_compilerver_from_cxx_version_string VERSTRING CNAME CVER) 332 # extract possible compiler names 333 string(REGEX MATCH "g\\+\\+" ei_has_gpp ${VERSTRING}) 334 string(REGEX MATCH "llvm|LLVM" ei_has_llvm ${VERSTRING}) 335 string(REGEX MATCH "gcc|GCC" ei_has_gcc ${VERSTRING}) 336 string(REGEX MATCH "icpc|ICC" ei_has_icpc ${VERSTRING}) 337 string(REGEX MATCH "clang|CLANG" ei_has_clang ${VERSTRING}) 338 339 # combine them 340 if((ei_has_llvm) AND (ei_has_gpp OR ei_has_gcc)) 341 set(${CNAME} "llvm-g++") 342 elseif((ei_has_llvm) AND (ei_has_clang)) 343 set(${CNAME} "llvm-clang++") 344 elseif(ei_has_icpc) 345 set(${CNAME} "icpc") 346 elseif(ei_has_gpp OR ei_has_gcc) 347 set(${CNAME} "g++") 348 else() 349 set(${CNAME} "_") 350 endif() 351 352 # extract possible version numbers 353 # first try to extract 3 isolated numbers: 354 string(REGEX MATCH " [0-9]+\\.[0-9]+\\.[0-9]+" eicver ${VERSTRING}) 355 if(NOT eicver) 356 # try to extract 2 isolated ones: 357 string(REGEX MATCH " [0-9]+\\.[0-9]+" eicver ${VERSTRING}) 358 if(NOT eicver) 359 # try to extract 3: 360 string(REGEX MATCH "[^0-9][0-9]+\\.[0-9]+\\.[0-9]+" eicver ${VERSTRING}) 361 if(NOT eicver) 362 # try to extract 2: 363 string(REGEX MATCH "[^0-9][0-9]+\\.[0-9]+" eicver ${VERSTRING}) 364 else() 365 set(eicver " _") 366 endif() 367 endif() 368 endif() 369 370 string(REGEX REPLACE ".(.*)" "\\1" ${CVER} ${eicver}) 371 372 endmacro(ei_get_compilerver_from_cxx_version_string) 373 374 macro(ei_get_cxxflags VAR) 375 set(${VAR} "") 376 ei_is_64bit_env(IS_64BIT_ENV) 377 if(EIGEN_TEST_NEON) 378 set(${VAR} NEON) 379 elseif(EIGEN_TEST_ALTIVEC) 380 set(${VAR} ALVEC) 381 elseif(EIGEN_TEST_SSE4_2) 382 set(${VAR} SSE42) 383 elseif(EIGEN_TEST_SSE4_1) 384 set(${VAR} SSE41) 385 elseif(EIGEN_TEST_SSSE3) 386 set(${VAR} SSSE3) 387 elseif(EIGEN_TEST_SSE3) 388 set(${VAR} SSE3) 389 elseif(EIGEN_TEST_SSE2 OR IS_64BIT_ENV) 390 set(${VAR} SSE2) 391 endif() 392 393 if(EIGEN_TEST_OPENMP) 394 if (${VAR} STREQUAL "") 395 set(${VAR} OMP) 396 else() 397 set(${VAR} ${${VAR}}-OMP) 398 endif() 399 endif() 400 401 if(EIGEN_DEFAULT_TO_ROW_MAJOR) 402 if (${VAR} STREQUAL "") 403 set(${VAR} ROW) 404 else() 405 set(${VAR} ${${VAR}}-ROWMAJ) 406 endif() 407 endif() 408 endmacro(ei_get_cxxflags) 409 410 macro(ei_set_build_string) 411 ei_get_compilerver(LOCAL_COMPILER_VERSION) 412 ei_get_cxxflags(LOCAL_COMPILER_FLAGS) 413 414 include(EigenDetermineOSVersion) 415 DetermineOSVersion(OS_VERSION) 416 417 set(TMP_BUILD_STRING ${OS_VERSION}-${LOCAL_COMPILER_VERSION}) 418 419 if (NOT ${LOCAL_COMPILER_FLAGS} STREQUAL "") 420 set(TMP_BUILD_STRING ${TMP_BUILD_STRING}-${LOCAL_COMPILER_FLAGS}) 421 endif() 422 423 ei_is_64bit_env(IS_64BIT_ENV) 424 if(NOT IS_64BIT_ENV) 425 set(TMP_BUILD_STRING ${TMP_BUILD_STRING}-32bit) 426 else() 427 set(TMP_BUILD_STRING ${TMP_BUILD_STRING}-64bit) 428 endif() 429 430 string(TOLOWER ${TMP_BUILD_STRING} BUILDNAME) 431 endmacro(ei_set_build_string) 432 433 macro(ei_is_64bit_env VAR) 434 435 file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/is64.cpp" 436 "int main() { return (sizeof(int*) == 8 ? 1 : 0); } 437 ") 438 try_run(run_res compile_res 439 ${CMAKE_CURRENT_BINARY_DIR} "${CMAKE_CURRENT_BINARY_DIR}/is64.cpp" 440 RUN_OUTPUT_VARIABLE run_output) 441 442 if(compile_res AND run_res) 443 set(${VAR} ${run_res}) 444 elseif(CMAKE_CL_64) 445 set(${VAR} 1) 446 elseif("$ENV{Platform}" STREQUAL "X64") # nmake 64 bit 447 set(${VAR} 1) 448 endif() 449 endmacro(ei_is_64bit_env) 450 451 452 # helper macro for testing ei_get_compilerver_from_cxx_version_string 453 # STR: raw version string 454 # REFNAME: expected compiler name 455 # REFVER: expected compiler version 456 macro(ei_test1_get_compilerver_from_cxx_version_string STR REFNAME REFVER) 457 ei_get_compilerver_from_cxx_version_string(${STR} CNAME CVER) 458 if((NOT ${REFNAME} STREQUAL ${CNAME}) OR (NOT ${REFVER} STREQUAL ${CVER})) 459 message("STATUS ei_get_compilerver_from_cxx_version_string error:") 460 message("Expected \"${REFNAME}-${REFVER}\", got \"${CNAME}-${CVER}\"") 461 endif() 462 endmacro(ei_test1_get_compilerver_from_cxx_version_string) 463 464 # macro for testing ei_get_compilerver_from_cxx_version_string 465 # feel free to add more version strings 466 macro(ei_test_get_compilerver_from_cxx_version_string) 467 ei_test1_get_compilerver_from_cxx_version_string("g++ (SUSE Linux) 4.5.3 20110428 [gcc-4_5-branch revision 173117]" "g++" "4.5.3") 468 ei_test1_get_compilerver_from_cxx_version_string("c++ (GCC) 4.5.1 20100924 (Red Hat 4.5.1-4)" "g++" "4.5.1") 469 ei_test1_get_compilerver_from_cxx_version_string("icpc (ICC) 11.0 20081105" "icpc" "11.0") 470 ei_test1_get_compilerver_from_cxx_version_string("g++-3.4 (GCC) 3.4.6" "g++" "3.4.6") 471 ei_test1_get_compilerver_from_cxx_version_string("SUSE Linux clang version 3.0 (branches/release_30 145598) (based on LLVM 3.0)" "llvm-clang++" "3.0") 472 ei_test1_get_compilerver_from_cxx_version_string("icpc (ICC) 12.0.5 20110719" "icpc" "12.0.5") 473 ei_test1_get_compilerver_from_cxx_version_string("Apple clang version 2.1 (tags/Apple/clang-163.7.1) (based on LLVM 3.0svn)" "llvm-clang++" "2.1") 474 ei_test1_get_compilerver_from_cxx_version_string("i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)" "llvm-g++" "4.2.1") 475 ei_test1_get_compilerver_from_cxx_version_string("g++-mp-4.4 (GCC) 4.4.6" "g++" "4.4.6") 476 ei_test1_get_compilerver_from_cxx_version_string("g++-mp-4.4 (GCC) 2011" "g++" "4.4") 477 endmacro(ei_test_get_compilerver_from_cxx_version_string) 478