FindSquish.cmake 9.6 KB

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