FindSquish.cmake 9.7 KB

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