|
| 1 | +if ("MSVC" STREQUAL "${CMAKE_CXX_COMPILER_ID}") |
| 2 | + # There's a bug that prevents build-and-test from working on MSVC. |
| 3 | + # See NVIDIA/nvbench#43. |
| 4 | + return() |
| 5 | +endif() |
| 6 | + |
| 7 | +set(cmake_opts |
| 8 | + -D "CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}" |
| 9 | + -D "CMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}" |
| 10 | + -D "CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" |
| 11 | +) |
| 12 | + |
| 13 | +# Temporary installation prefix for tests against installed project: |
| 14 | +set(tmp_install_prefix "${CMAKE_CURRENT_BINARY_DIR}/test_install") |
| 15 | + |
| 16 | +# Add a build-and-test CTest. |
| 17 | +# - full_test_name_var will be set to the full name of the test. |
| 18 | +# - subdir is the relative path to the test project directory. |
| 19 | +# - test_id is used to generate a unique name for this test, allowing the |
| 20 | +# subdir to be reused. |
| 21 | +# - Any additional args will be passed to the project configure step. |
| 22 | +function(libcudacxx_add_compile_test full_test_name_var subdir test_id) |
| 23 | + set(test_name libcudacxx.test.cmake.${subdir}.${test_id}) |
| 24 | + set(src_dir "${CMAKE_CURRENT_SOURCE_DIR}/${subdir}") |
| 25 | + set(build_dir "${CMAKE_CURRENT_BINARY_DIR}/${subdir}/${test_id}") |
| 26 | + add_test(NAME ${test_name} |
| 27 | + COMMAND "${CMAKE_CTEST_COMMAND}" |
| 28 | + --build-and-test "${src_dir}" "${build_dir}" |
| 29 | + --build-generator "${CMAKE_GENERATOR}" |
| 30 | + --build-options |
| 31 | + ${cmake_opts} |
| 32 | + ${ARGN} |
| 33 | + --test-command "${CMAKE_CTEST_COMMAND}" --output-on-failure |
| 34 | + ) |
| 35 | + set(${full_test_name_var} ${test_name} PARENT_SCOPE) |
| 36 | +endfunction() |
| 37 | + |
| 38 | +################################################################################ |
| 39 | +# Test against source dir |
| 40 | + |
| 41 | +libcudacxx_add_compile_test(test_name |
| 42 | + test_export |
| 43 | + source_tree |
| 44 | + -D "libcudacxx_DIR=${libcudacxx_SOURCE_DIR}/lib/cmake/libcudacxx/" |
| 45 | + -D TEST_TYPE=SOURCE_TREE |
| 46 | +) |
| 47 | + |
| 48 | +################################################################################ |
| 49 | +# Test against install tree |
| 50 | + |
| 51 | +libcudacxx_add_compile_test(test_name |
| 52 | + test_export |
| 53 | + install_tree |
| 54 | + -D "libcudacxx_DIR=${tmp_install_prefix}/lib/cmake/libcudacxx/" |
| 55 | + -D TEST_TYPE=INSTALL_TREE |
| 56 | +) |
| 57 | +set_tests_properties(${test_name} PROPERTIES FIXTURES_REQUIRED install_tree) |
| 58 | + |
| 59 | +################################################################################ |
| 60 | +# Install tree fixtures |
| 61 | +add_test(NAME libcudacxx.test.cmake.install_tree.install |
| 62 | + COMMAND "${CMAKE_COMMAND}" |
| 63 | + --install "${libcudacxx_BINARY_DIR}" |
| 64 | + --prefix "${tmp_install_prefix}" |
| 65 | +) |
| 66 | +set_tests_properties(libcudacxx.test.cmake.install_tree.install PROPERTIES |
| 67 | + FIXTURES_SETUP install_tree |
| 68 | +) |
| 69 | + |
| 70 | +add_test(NAME libcudacxx.test.cmake.install_tree.cleanup |
| 71 | + COMMAND "${CMAKE_COMMAND}" -E rm -rf "${tmp_install_prefix}" |
| 72 | +) |
| 73 | +set_tests_properties(libcudacxx.test.cmake.install_tree.cleanup PROPERTIES |
| 74 | + FIXTURES_CLEANUP install_tree |
| 75 | +) |
0 commit comments