FindSquish.cmake 9.5 KB

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