FindSquish.cmake 10 KB

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