Computer Assisted Medical Intervention Tool Kit  version 5.2
CamiTKTestsRequirement.h
Go to the documentation of this file.
1 #
77  set(options "")
78  set(oneValueArgs REASON
79  REQUIRES)
80  set(multiValueArgs TESTS)
81  cmake_parse_arguments(CAMITK_TESTS_REQUIREMENT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
82 
83  # -- analyze requirements
84  # transform statement to list in order to access left/middle/right value if the requirement is a test
85  string(REPLACE " " "" REQUIRES_STATEMENT ${CAMITK_TESTS_REQUIREMENT_REQUIRES})
86  list(LENGTH REQUIRES_STATEMENT REQUIRES_STATEMENT_LENGTH)
87 
88  if(REQUIRES_STATEMENT_LENGTH EQUAL 3)
89  # Requirement is a test, separate into parts and evaluate the requirement
90  list(GET REQUIRES_STATEMENT 0 REQUIRES_STATEMENT_LEFT_VALUE)
91  list(GET REQUIRES_STATEMENT 1 REQUIRES_STATEMENT_TEST)
92  list(GET REQUIRES_STATEMENT 2 REQUIRES_STATEMENT_RIGHT_VALUE)
93  # check the test statement. Can be either VERSION_LESS, VERSION_EQUAL or VERSION_GREATER
94  if(REQUIRES_STATEMENT_TEST STREQUAL "VERSION_LESS")
95  if (${REQUIRES_STATEMENT_LEFT_VALUE} VERSION_LESS ${REQUIRES_STATEMENT_RIGHT_VALUE})
96  set(REQUIRES_EVAL TRUE)
97  else()
98  set(REQUIRES_EVAL FALSE)
99  endif()
100  elseif(REQUIRES_STATEMENT_TEST STREQUAL "VERSION_EQUAL")
101  if (${REQUIRES_STATEMENT_LEFT_VALUE} VERSION_EQUAL ${REQUIRES_STATEMENT_RIGHT_VALUE})
102  set(REQUIRES_EVAL TRUE)
103  else()
104  set(REQUIRES_EVAL FALSE)
105  endif()
106  elseif(REQUIRES_STATEMENT_TEST STREQUAL "VERSION_GREATER")
107  if (${REQUIRES_STATEMENT_LEFT_VALUE} VERSION_GREATER ${REQUIRES_STATEMENT_RIGHT_VALUE})
108  set(REQUIRES_EVAL TRUE)
109  else()
110  set(REQUIRES_EVAL FALSE)
111  endif()
112  else()
113  message(FATAL_ERROR "\n Unknown three-parts requirement test: \"${CAMITK_TESTS_REQUIREMENT_REQUIRES}\"\n Use one of VERSION_LESS, VERSION_EQUAL or VERSION_GREATER.\n Check call stack below to fix this error.")
114  endif()
115  else()
116  if(REQUIRES_STATEMENT_LENGTH EQUAL 2)
117  list(GET REQUIRES_STATEMENT 0 REQUIRES_STATEMENT_NOT)
118  list(GET REQUIRES_STATEMENT 1 REQUIRES_STATEMENT_TEST)
119  # REQUIRES_STATEMENT_NOT should be "NOT"
120  if(NOT REQUIRES_STATEMENT_NOT STREQUAL "NOT")
121  message(FATAL_ERROR "\n Unknown two-parts requirement test: \"${CAMITK_TESTS_REQUIREMENT_REQUIRES}\"\n Only NOT is supported.\n Check call stack below to fix this error.")
122  endif()
123  else()
124  list(GET REQUIRES_STATEMENT 0 REQUIRES_STATEMENT_TEST)
125  endif()
126 
127  # possible statement are WIN32, WIN64, MSVC, APPLE or UNIX
128  if(REQUIRES_STATEMENT_TEST STREQUAL "WIN32")
129  if(WIN32)
130  set(REQUIRES_EVAL TRUE)
131  else()
132  set(REQUIRES_EVAL FALSE)
133  endif()
134  elseif(REQUIRES_STATEMENT_TEST STREQUAL "WIN64")
135  if(WIN64)
136  set(REQUIRES_EVAL TRUE)
137  else()
138  set(REQUIRES_EVAL FALSE)
139  endif()
140  elseif(REQUIRES_STATEMENT_TEST STREQUAL "MSVC")
141  if(MSVC)
142  set(REQUIRES_EVAL TRUE)
143  else()
144  set(REQUIRES_EVAL FALSE)
145  endif()
146  elseif(REQUIRES_STATEMENT_TEST STREQUAL "APPLE")
147  if(APPLE)
148  set(REQUIRES_EVAL TRUE)
149  else()
150  set(REQUIRES_EVAL FALSE)
151  endif()
152  elseif(REQUIRES_STATEMENT_TEST STREQUAL "UNIX")
153  if(UNIX)
154  set(REQUIRES_EVAL TRUE)
155  else()
156  set(REQUIRES_EVAL FALSE)
157  endif()
158  endif()
159 
160  # negate if needed
161  if(REQUIRES_STATEMENT_NOT STREQUAL "NOT")
162  if(REQUIRES_EVAL STREQUAL "TRUE")
163  set(REQUIRES_EVAL FALSE)
164  else()
165  set(REQUIRES_EVAL TRUE)
166  endif()
167  endif()
168  endif()
169 
170  # -- disable tests if the requirement is not met
171  string(REPLACE "" " " CAMITK_TESTS_REQUIREMENT_TESTS_STRING "${CAMITK_TESTS_REQUIREMENT_TESTS}")
172  if(NOT ${REQUIRES_EVAL})
173  foreach(TEST_NAME ${CAMITK_TESTS_REQUIREMENT_TESTS})
174  # CMake < 3.9 did not have the DISABLED test property. Use WILL_FAIL instead
175  if(${CMAKE_VERSION} VERSION_LESS "3.9")
176  set_tests_properties(${TEST_NAME} PROPERTIES WILL_FAIL true)
177  else()
178  set_tests_properties(${TEST_NAME} PROPERTIES DISABLED true)
179  endif()
180  endforeach()
181  set(DISABLE_MESSAGE "Test requirement \"${CAMITK_TESTS_REQUIREMENT_REQUIRES}\": Failed\n Disabled tests: ${CAMITK_TESTS_REQUIREMENT_TESTS_STRING}\n")
182  if(${CMAKE_VERSION} VERSION_LESS "3.9")
183  set(DISABLE_MESSAGE ${DISABLE_MESSAGE} " (using WILL_FAIL property because CMake < 3.9)\n")
184  endif()
185  set(DISABLE_MESSAGE ${DISABLE_MESSAGE} " Reason: ${CAMITK_TESTS_REQUIREMENT_REASON}\n")
186  set(DISABLE_MESSAGE ${DISABLE_MESSAGE} " Requirement statement unmet: ${CAMITK_TESTS_REQUIREMENT_REQUIRES}")
187  message(STATUS ${DISABLE_MESSAGE})
188  else()
189  message(STATUS "Test requirement \"${CAMITK_TESTS_REQUIREMENT_REQUIRES}\": Passed\n Enabled tests: ${CAMITK_TESTS_REQUIREMENT_TESTS_STRING}")
190  endif()
191 end(){)
cmake modules macros camitk test endif() add_custom_target(camitk-ce-iwyu COMMAND $
Definition: CamiTKIncludeWhatYouUse.h:37
#define a
iwyu out CACHE PATH Output filename for include what you use set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${IWYU_EXECUTABLE}) if(NOT EXISTS $
Definition: CamiTKIncludeWhatYouUse.h:22
camitk_tests_requirement()
camitk_tests_requirement is a macro to disable one or more tests.
Definition: CamiTKTestsRequirement.h:76
vtkSmartPointer< vtkTransform > transform
Definition: RendererWidget.cpp:416