1 cmake_minimum_required(VERSION 2.8.7) 2 3 project(GSLTests CXX) 4 5 # will make visual studio generated project group files 6 set_property(GLOBAL PROPERTY USE_FOLDERS ON) 7 8 list(APPEND CATCH_CMAKE_ARGS 9 "-DCMAKE_INSTALL_PREFIX=${CMAKE_SOURCE_DIR}" 10 "-DNO_SELFTEST=true" 11 ) 12 13 # add catch 14 ExternalProject_Add( 15 catch 16 PREFIX ${CMAKE_BINARY_DIR}/catch 17 GIT_REPOSITORY https://github.com/philsquared/Catch.git 18 GIT_TAG v1.9.6 19 CMAKE_ARGS ${CATCH_CMAKE_ARGS} 20 LOG_DOWNLOAD 1 21 UPDATE_DISCONNECTED 1 22 ) 23 24 # this interface adds compile options to how the tests are run 25 # please try to keep entries ordered =) 26 add_library(gsl_tests_config INTERFACE) 27 target_compile_options(gsl_tests_config INTERFACE 28 $<$<CXX_COMPILER_ID:MSVC>: 29 /EHsc 30 /W4 31 /WX 32 > 33 $<$<NOT:$<CXX_COMPILER_ID:MSVC>>: 34 -fno-strict-aliasing 35 -Wall 36 -Wcast-align 37 -Wconversion 38 -Wctor-dtor-privacy 39 -Werror 40 -Wextra 41 -Wno-missing-braces 42 -Wnon-virtual-dtor 43 -Wold-style-cast 44 -Woverloaded-virtual 45 -Wpedantic 46 -Wshadow 47 -Wsign-conversion 48 > 49 ) 50 51 # set definitions for tests 52 target_compile_definitions(gsl_tests_config INTERFACE 53 GSL_THROW_ON_CONTRACT_VIOLATION 54 ) 55 56 # create the main executable for each test. this reduces the compile time 57 # of each test by pre-compiling catch. 58 add_library(test_catch STATIC test.cpp) 59 target_link_libraries(test_catch 60 GSL 61 gsl_tests_config 62 ) 63 add_dependencies(test_catch catch) 64 set_property(TARGET test_catch PROPERTY FOLDER "GSL_tests") 65 66 function(add_gsl_test name) 67 add_executable(${name} ${name}.cpp) 68 target_link_libraries(${name} 69 GSL 70 test_catch 71 gsl_tests_config 72 ) 73 add_dependencies(${name} catch) 74 add_test( 75 ${name} 76 ${name} 77 ) 78 # group all tests under GSL_tests 79 set_property(TARGET ${name} PROPERTY FOLDER "GSL_tests") 80 endfunction() 81 82 add_gsl_test(span_tests) 83 add_gsl_test(multi_span_tests) 84 add_gsl_test(strided_span_tests) 85 add_gsl_test(string_span_tests) 86 add_gsl_test(at_tests) 87 add_gsl_test(bounds_tests) 88 add_gsl_test(notnull_tests) 89 add_gsl_test(assertion_tests) 90 add_gsl_test(utils_tests) 91 add_gsl_test(owner_tests) 92 add_gsl_test(byte_tests) 93 add_gsl_test(algorithm_tests) 94