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