FindSquish.cmake 10 KB

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