FindSquish.cmake 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. #.rst:
  2. # FindSquish
  3. # ----------
  4. #
  5. # -- Typical Use
  6. #
  7. #
  8. #
  9. # This module can be used to find Squish. Currently Squish versions 3
  10. # and 4 are supported.
  11. #
  12. # ::
  13. #
  14. # SQUISH_FOUND If false, don't try to use Squish
  15. # SQUISH_VERSION The full version of Squish found
  16. # SQUISH_VERSION_MAJOR The major version of Squish found
  17. # SQUISH_VERSION_MINOR The minor version of Squish found
  18. # SQUISH_VERSION_PATCH The patch version of Squish found
  19. #
  20. #
  21. #
  22. # ::
  23. #
  24. # SQUISH_INSTALL_DIR The Squish installation directory
  25. # (containing bin, lib, etc)
  26. # SQUISH_SERVER_EXECUTABLE The squishserver executable
  27. # SQUISH_CLIENT_EXECUTABLE The squishrunner executable
  28. #
  29. #
  30. #
  31. # ::
  32. #
  33. # SQUISH_INSTALL_DIR_FOUND Was the install directory found?
  34. # SQUISH_SERVER_EXECUTABLE_FOUND Was the server executable found?
  35. # SQUISH_CLIENT_EXECUTABLE_FOUND Was the client executable found?
  36. #
  37. #
  38. #
  39. # It provides the function squish_v4_add_test() for adding a squish test
  40. # to cmake using Squish 4.x:
  41. #
  42. # ::
  43. #
  44. # squish_v4_add_test(cmakeTestName AUT targetName SUITE suiteName TEST squishTestName
  45. # [SETTINGSGROUP group] [PRE_COMMAND command] [POST_COMMAND command] )
  46. #
  47. #
  48. #
  49. # The arguments have the following meaning:
  50. #
  51. # ``cmakeTestName``
  52. # this will be used as the first argument for add_test()
  53. # ``AUT targetName``
  54. # the name of the cmake target which will be used as AUT, i.e. the
  55. # executable which will be tested.
  56. # ``SUITE suiteName``
  57. # this is either the full path to the squish suite, or just the
  58. # last directory of the suite, i.e. the suite name. In this case
  59. # the CMakeLists.txt which calls squish_add_test() must be located
  60. # in the parent directory of the suite directory.
  61. # ``TEST squishTestName``
  62. # the name of the squish test, i.e. the name of the subdirectory
  63. # of the test inside the suite directory.
  64. # ``SETTINGSGROUP group``
  65. # if specified, the given settings group will be used for executing the test.
  66. # If not specified, the groupname will be "CTest_<username>"
  67. # ``PRE_COMMAND command``
  68. # if specified, the given command will be executed before starting the squish test.
  69. # ``POST_COMMAND command``
  70. # same as PRE_COMMAND, but after the squish test has been executed.
  71. #
  72. #
  73. #
  74. # ::
  75. #
  76. # enable_testing()
  77. # find_package(Squish 4.0)
  78. # if (SQUISH_FOUND)
  79. # squish_v4_add_test(myTestName
  80. # AUT myApp
  81. # SUITE ${CMAKE_SOURCE_DIR}/tests/mySuite
  82. # TEST someSquishTest
  83. # SETTINGSGROUP myGroup
  84. # )
  85. # endif ()
  86. #
  87. #
  88. #
  89. #
  90. #
  91. # For users of Squish version 3.x the macro squish_v3_add_test() is
  92. # provided:
  93. #
  94. # ::
  95. #
  96. # squish_v3_add_test(testName applicationUnderTest testCase envVars testWrapper)
  97. # Use this macro to add a test using Squish 3.x.
  98. #
  99. #
  100. #
  101. # ::
  102. #
  103. # enable_testing()
  104. # find_package(Squish)
  105. # if (SQUISH_FOUND)
  106. # squish_v3_add_test(myTestName myApplication testCase envVars testWrapper)
  107. # endif ()
  108. #
  109. #
  110. #
  111. # macro SQUISH_ADD_TEST(testName applicationUnderTest testCase envVars
  112. # testWrapper)
  113. #
  114. # ::
  115. #
  116. # This is deprecated. Use SQUISH_V3_ADD_TEST() if you are using Squish 3.x instead.
  117. #=============================================================================
  118. # Copyright 2008-2009 Kitware, Inc.
  119. # Copyright 2012 Alexander Neundorf
  120. #
  121. # Distributed under the OSI-approved BSD License (the "License");
  122. # see accompanying file Copyright.txt for details.
  123. #
  124. # This software is distributed WITHOUT ANY WARRANTY; without even the
  125. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  126. # See the License for more information.
  127. #=============================================================================
  128. # (To distribute this file outside of CMake, substitute the full
  129. # License text for the above reference.)
  130. include(CMakeParseArguments)
  131. set(SQUISH_INSTALL_DIR_STRING "Directory containing the bin, doc, and lib directories for Squish; this should be the root of the installation directory.")
  132. set(SQUISH_SERVER_EXECUTABLE_STRING "The squishserver executable program.")
  133. set(SQUISH_CLIENT_EXECUTABLE_STRING "The squishclient executable program.")
  134. # Search only if the location is not already known.
  135. if(NOT SQUISH_INSTALL_DIR)
  136. # Get the system search path as a list.
  137. file(TO_CMAKE_PATH "$ENV{PATH}" SQUISH_INSTALL_DIR_SEARCH2)
  138. # Construct a set of paths relative to the system search path.
  139. set(SQUISH_INSTALL_DIR_SEARCH "")
  140. foreach(dir ${SQUISH_INSTALL_DIR_SEARCH2})
  141. set(SQUISH_INSTALL_DIR_SEARCH ${SQUISH_INSTALL_DIR_SEARCH} "${dir}/../lib/fltk")
  142. endforeach()
  143. string(REPLACE "//" "/" SQUISH_INSTALL_DIR_SEARCH "${SQUISH_INSTALL_DIR_SEARCH}")
  144. # Look for an installation
  145. find_path(SQUISH_INSTALL_DIR bin/squishrunner
  146. HINTS
  147. # Look for an environment variable SQUISH_INSTALL_DIR.
  148. ENV SQUISH_INSTALL_DIR
  149. # Look in places relative to the system executable search path.
  150. ${SQUISH_INSTALL_DIR_SEARCH}
  151. # Look in standard UNIX install locations.
  152. #/usr/local/squish
  153. DOC "The ${SQUISH_INSTALL_DIR_STRING}"
  154. )
  155. endif()
  156. # search for the executables
  157. if(SQUISH_INSTALL_DIR)
  158. set(SQUISH_INSTALL_DIR_FOUND 1)
  159. # find the client program
  160. if(NOT SQUISH_CLIENT_EXECUTABLE)
  161. find_program(SQUISH_CLIENT_EXECUTABLE ${SQUISH_INSTALL_DIR}/bin/squishrunner${CMAKE_EXECUTABLE_SUFFIX} DOC "The ${SQUISH_CLIENT_EXECUTABLE_STRING}")
  162. endif()
  163. # find the server program
  164. if(NOT SQUISH_SERVER_EXECUTABLE)
  165. find_program(SQUISH_SERVER_EXECUTABLE ${SQUISH_INSTALL_DIR}/bin/squishserver${CMAKE_EXECUTABLE_SUFFIX} DOC "The ${SQUISH_SERVER_EXECUTABLE_STRING}")
  166. endif()
  167. else()
  168. set(SQUISH_INSTALL_DIR_FOUND 0)
  169. endif()
  170. set(SQUISH_VERSION)
  171. set(SQUISH_VERSION_MAJOR )
  172. set(SQUISH_VERSION_MINOR )
  173. set(SQUISH_VERSION_PATCH )
  174. # record if executables are set
  175. if(SQUISH_CLIENT_EXECUTABLE)
  176. set(SQUISH_CLIENT_EXECUTABLE_FOUND 1)
  177. execute_process(COMMAND "${SQUISH_CLIENT_EXECUTABLE}" --version
  178. OUTPUT_VARIABLE _squishVersionOutput
  179. ERROR_QUIET )
  180. if("${_squishVersionOutput}" MATCHES "([0-9]+)\\.([0-9]+)\\.([0-9]+)")
  181. set(SQUISH_VERSION_MAJOR "${CMAKE_MATCH_1}")
  182. set(SQUISH_VERSION_MINOR "${CMAKE_MATCH_2}")
  183. set(SQUISH_VERSION_PATCH "${CMAKE_MATCH_3}")
  184. set(SQUISH_VERSION "${SQUISH_VERSION_MAJOR}.${SQUISH_VERSION_MINOR}.${SQUISH_VERSION_PATCH}" )
  185. endif()
  186. else()
  187. set(SQUISH_CLIENT_EXECUTABLE_FOUND 0)
  188. endif()
  189. if(SQUISH_SERVER_EXECUTABLE)
  190. set(SQUISH_SERVER_EXECUTABLE_FOUND 1)
  191. else()
  192. set(SQUISH_SERVER_EXECUTABLE_FOUND 0)
  193. endif()
  194. # record if Squish was found
  195. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  196. find_package_handle_standard_args(Squish REQUIRED_VARS SQUISH_INSTALL_DIR SQUISH_CLIENT_EXECUTABLE SQUISH_SERVER_EXECUTABLE
  197. VERSION_VAR SQUISH_VERSION )
  198. set(_SQUISH_MODULE_DIR "${CMAKE_CURRENT_LIST_DIR}")
  199. macro(SQUISH_V3_ADD_TEST testName testAUT testCase envVars testWraper)
  200. if("${SQUISH_VERSION_MAJOR}" STREQUAL "4")
  201. message(STATUS "Using squish_v3_add_test(), but SQUISH_VERSION_MAJOR is ${SQUISH_VERSION_MAJOR}.\nThis may not work.")
  202. endif()
  203. add_test(${testName}
  204. ${CMAKE_COMMAND} -V -VV
  205. "-Dsquish_version:STRING=3"
  206. "-Dsquish_aut:STRING=${testAUT}"
  207. "-Dsquish_server_executable:STRING=${SQUISH_SERVER_EXECUTABLE}"
  208. "-Dsquish_client_executable:STRING=${SQUISH_CLIENT_EXECUTABLE}"
  209. "-Dsquish_libqtdir:STRING=${QT_LIBRARY_DIR}"
  210. "-Dsquish_test_case:STRING=${testCase}"
  211. "-Dsquish_env_vars:STRING=${envVars}"
  212. "-Dsquish_wrapper:STRING=${testWraper}"
  213. "-Dsquish_module_dir:STRING=${_SQUISH_MODULE_DIR}"
  214. -P "${_SQUISH_MODULE_DIR}/SquishTestScript.cmake"
  215. )
  216. set_tests_properties(${testName}
  217. PROPERTIES FAIL_REGULAR_EXPRESSION "FAILED;ERROR;FATAL"
  218. )
  219. endmacro()
  220. macro(SQUISH_ADD_TEST)
  221. message(STATUS "Using squish_add_test() is deprecated, use squish_v3_add_test() instead.")
  222. squish_v3_add_test(${ARGV})
  223. endmacro()
  224. function(SQUISH_V4_ADD_TEST testName)
  225. if(NOT "${SQUISH_VERSION_MAJOR}" STREQUAL "4")
  226. message(STATUS "Using squish_v4_add_test(), but SQUISH_VERSION_MAJOR is ${SQUISH_VERSION_MAJOR}.\nThis may not work.")
  227. endif()
  228. set(oneValueArgs AUT SUITE TEST SETTINGSGROUP PRE_COMMAND POST_COMMAND)
  229. cmake_parse_arguments(_SQUISH "" "${oneValueArgs}" "" ${ARGN} )
  230. if(_SQUISH_UNPARSED_ARGUMENTS)
  231. message(FATAL_ERROR "Unknown keywords given to SQUISH_ADD_TEST(): \"${_SQUISH_UNPARSED_ARGUMENTS}\"")
  232. endif()
  233. if(NOT _SQUISH_AUT)
  234. message(FATAL_ERROR "Required argument AUT not given for SQUISH_ADD_TEST()")
  235. endif()
  236. if(NOT _SQUISH_SUITE)
  237. message(FATAL_ERROR "Required argument SUITE not given for SQUISH_ADD_TEST()")
  238. endif()
  239. if(NOT _SQUISH_TEST)
  240. message(FATAL_ERROR "Required argument TEST not given for SQUISH_ADD_TEST()")
  241. endif()
  242. get_target_property(testAUTLocation ${_SQUISH_AUT} LOCATION)
  243. get_filename_component(testAUTDir ${testAUTLocation} PATH)
  244. get_filename_component(testAUTName ${testAUTLocation} NAME)
  245. get_filename_component(absTestSuite "${_SQUISH_SUITE}" ABSOLUTE)
  246. if(NOT EXISTS "${absTestSuite}")
  247. message(FATAL_ERROR "Could not find squish test suite ${_SQUISH_SUITE} (checked ${absTestSuite})")
  248. endif()
  249. set(absTestCase "${absTestSuite}/${_SQUISH_TEST}")
  250. if(NOT EXISTS "${absTestCase}")
  251. message(FATAL_ERROR "Could not find squish testcase ${_SQUISH_TEST} (checked ${absTestCase})")
  252. endif()
  253. if(NOT _SQUISH_SETTINGSGROUP)
  254. set(_SQUISH_SETTINGSGROUP "CTest_$ENV{LOGNAME}")
  255. endif()
  256. add_test(${testName}
  257. ${CMAKE_COMMAND} -V -VV
  258. "-Dsquish_version:STRING=4"
  259. "-Dsquish_aut:STRING=${testAUTName}"
  260. "-Dsquish_aut_dir:STRING=${testAUTDir}"
  261. "-Dsquish_server_executable:STRING=${SQUISH_SERVER_EXECUTABLE}"
  262. "-Dsquish_client_executable:STRING=${SQUISH_CLIENT_EXECUTABLE}"
  263. "-Dsquish_libqtdir:STRING=${QT_LIBRARY_DIR}"
  264. "-Dsquish_test_suite:STRING=${absTestSuite}"
  265. "-Dsquish_test_case:STRING=${_SQUISH_TEST}"
  266. "-Dsquish_env_vars:STRING=${envVars}"
  267. "-Dsquish_wrapper:STRING=${testWraper}"
  268. "-Dsquish_module_dir:STRING=${_SQUISH_MODULE_DIR}"
  269. "-Dsquish_settingsgroup:STRING=${_SQUISH_SETTINGSGROUP}"
  270. "-Dsquish_pre_command:STRING=${_SQUISH_PRE_COMMAND}"
  271. "-Dsquish_post_command:STRING=${_SQUISH_POST_COMMAND}"
  272. -P "${_SQUISH_MODULE_DIR}/SquishTestScript.cmake"
  273. )
  274. set_tests_properties(${testName}
  275. PROPERTIES FAIL_REGULAR_EXPRESSION "FAIL;FAILED;ERROR;FATAL"
  276. )
  277. endfunction()