ctkMacroSimpleTestWithData.cmake 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #! Usage:
  2. #! \code
  3. #! SIMPLE_TEST_WITH_DATA(<testname> <baseline_relative_location> [argument1 ...])
  4. #! \endcode
  5. #!
  6. #! This macro add a test using the complete add_test signature specifying target using
  7. #! $<TARGET_FILE:...> generator expression. Optionnal test argument(s) can be passed
  8. #! after specifying the <testname>.
  9. #!
  10. #! <baseline_relative_location> parameter should corresponds to a subfolder located in <CTKData_DIR>/Baseline
  11. #!
  12. #! Variables named KIT and CTKData_DIR are expected to be defined in the current scope.
  13. #!
  14. #! KIT variable usually matches the value of PROJECT_NAME.
  15. #!
  16. #! The macro also associates a label to the test based on the current value of KIT.
  17. #!
  18. #! By default, the name of the test to execute is expected to match <testname>, setting
  19. #! variable <testname>_TEST allows to change that.
  20. #!
  21. #! The following parameter will be passed to the test:
  22. #! <ul>
  23. #! <li>-D <CTKData_DIR>/Data</li>
  24. #! <li>-V <CTKData_DIR>/Baseline/<baseline_relative_location></li>
  25. #! <li>-T <PROJECT_BINARY_DIR>/Testing/Temporary</li>
  26. #! </ul>
  27. #!
  28. #! \sa http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:add_test
  29. #! \sa http://www.cmake.org/cmake/help/cmake-2-8-docs.html#variable:PROJECT_NAME
  30. #!
  31. #! \ingroup CMakeUtilities
  32. macro(SIMPLE_TEST_WITH_DATA testname baseline_relative_location)
  33. if("${KIT}" STREQUAL "")
  34. message(FATAL_ERROR "error: KIT variable is not set !")
  35. endif()
  36. if(NOT TARGET ${KIT}CppTests)
  37. message(FATAL_ERROR "error: ${KIT}CppTests target does NOT exist !")
  38. endif()
  39. if(NOT EXISTS "${CTKData_DIR}/Data")
  40. message(FATAL_ERROR "error: <CTKData_DIR>/Data corresponds to an non-existing directory. [<CTKData_DIR>/Data: ${CTKData_DIR}/Data]")
  41. endif()
  42. if(NOT EXISTS "${CTKData_DIR}/Baseline/${baseline_relative_location}")
  43. message(FATAL_ERROR "error: <CTKData_DIR>/Baseline/<baseline_relative_location> corresponds to an non-existing file or directory. [<CTKData_DIR>/Baseline/<baseline_relative_location>: ${CTKData_DIR}/Baseline/${baseline_relative_location}]")
  44. endif()
  45. if(NOT DEFINED ${testname}_TEST)
  46. set(${testname}_TEST ${testname})
  47. endif()
  48. add_test(NAME ${testname} COMMAND $<TARGET_FILE:${KIT}CppTests> ${${testname}_TEST}
  49. -D "${CTKData_DIR}/Data"
  50. -V "${CTKData_DIR}/Baseline/${baseline_relative_location}"
  51. -T "${PROJECT_BINARY_DIR}/Testing/Temporary"
  52. ${ARGN}
  53. )
  54. set_property(TEST ${testname} PROPERTY LABELS ${KIT})
  55. endmacro()