CTK  0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
ctkMacroSimpleTestWithData.cmake
Go to the documentation of this file.
1 
2 
3 
4 #! Usage:
5 #! \code
6 #! SIMPLE_TEST_WITH_DATA(<testname> <baseline_relative_location> [argument1 ...])
7 #! \endcode
8 #!
9 #! This macro add a test using the complete add_test signature specifying target using
10 #! $<TARGET_FILE:...> generator expression. Optionnal test argument(s) can be passed
11 #! after specifying the <testname>.
12 #!
13 #! <baseline_relative_location> parameter should corresponds to a subfolder located in <CTKData_DIR>/Baseline
14 #!
15 #! Variables named KIT and CTKData_DIR are expected to be defined in the current scope.
16 #!
17 #! KIT variable usually matches the value of PROJECT_NAME.
18 #!
19 #! The macro also associates a label to the test based on the current value of KIT.
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 
37  if(NOT TARGET ${KIT}CppTests)
38  message(FATAL_ERROR "error: ${KIT}CppTests target does NOT exist !")
39  endif()
40 
41  if(NOT EXISTS "${CTKData_DIR}/Data")
42  message(FATAL_ERROR "error: <CTKData_DIR>/Data corresponds to an non-existing directory. [<CTKData_DIR>/Data: ${CTKData_DIR}/Data]")
43  endif()
44 
45  if(NOT EXISTS "${CTKData_DIR}/Baseline/${baseline_relative_location}")
46  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}]")
47  endif()
48 
49  add_test(NAME ${testname} COMMAND $<TARGET_FILE:${KIT}CppTests> ${testname}
50  -D "${CTKData_DIR}/Data"
51  -V "${CTKData_DIR}/Baseline/${baseline_relative_location}"
52  -T "${PROJECT_BINARY_DIR}/Testing/Temporary"
53  ${ARGN}
54  )
55  set_property(TEST ${testname} PROPERTY LABELS ${KIT})
56 endmacro()
57