FindSquish.cmake 10 KB

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