FindSquish.cmake 10.3 KB
Newer Older
1 2 3
#.rst:
# FindSquish
# ----------
4
#
5
# -- Typical Use
6 7 8
#
#
#
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
# This module can be used to find Squish.  Currently Squish versions 3
# and 4 are supported.
#
# ::
#
#   SQUISH_FOUND                    If false, don't try to use Squish
#   SQUISH_VERSION                  The full version of Squish found
#   SQUISH_VERSION_MAJOR            The major version of Squish found
#   SQUISH_VERSION_MINOR            The minor version of Squish found
#   SQUISH_VERSION_PATCH            The patch version of Squish found
#
#
#
# ::
#
#   SQUISH_INSTALL_DIR              The Squish installation directory (containing bin, lib, etc)
#   SQUISH_SERVER_EXECUTABLE        The squishserver executable
#   SQUISH_CLIENT_EXECUTABLE        The squishrunner executable
#
#
#
# ::
#
#   SQUISH_INSTALL_DIR_FOUND        Was the install directory found?
#   SQUISH_SERVER_EXECUTABLE_FOUND  Was the server executable found?
#   SQUISH_CLIENT_EXECUTABLE_FOUND  Was the client executable found?
#
#
#
# It provides the function squish_v4_add_test() for adding a squish test
# to cmake using Squish 4.x:
#
# ::
#
#    squish_v4_add_test(cmakeTestName AUT targetName SUITE suiteName TEST squishTestName
#                    [SETTINGSGROUP group] [PRE_COMMAND command] [POST_COMMAND command] )
45
#
46 47 48
#
#
# The arguments have the following meaning:
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
#
# ::
#
#    cmakeTestName: this will be used as the first argument for add_test()
#    AUT targetName: the name of the cmake target which will be used as AUT, i.e. the
#                    executable which will be tested.
#    SUITE suiteName: this is either the full path to the squish suite, or just the
#                     last directory of the suite, i.e. the suite name. In this case
#                     the CMakeLists.txt which calls squish_add_test() must be located
#                     in the parent directory of the suite directory.
#    TEST squishTestName: the name of the squish test, i.e. the name of the subdirectory
#                         of the test inside the suite directory.
#    SETTINGSGROUP group: if specified, the given settings group will be used for executing the test.
#                         If not specified, the groupname will be "CTest_<username>"
#    PRE_COMMAND command:  if specified, the given command will be executed before starting the squish test.
#    POST_COMMAND command: same as PRE_COMMAND, but after the squish test has been executed.
#
#
#
# ::
#
#    enable_testing()
#    find_package(Squish 4.0)
#    if (SQUISH_FOUND)
#       squish_v4_add_test(myTestName AUT myApp SUITE ${CMAKE_SOURCE_DIR}/tests/mySuite TEST someSquishTest SETTINGSGROUP myGroup )
#    endif ()
#
#
#
#
#
# For users of Squish version 3.x the macro squish_v3_add_test() is
# provided:
#
# ::
#
#    squish_v3_add_test(testName applicationUnderTest testCase envVars testWrapper)
#    Use this macro to add a test using Squish 3.x.
#
#
#
# ::
#
92
#   enable_testing()
93
#   find_package(Squish)
94
#   if (SQUISH_FOUND)
95
#     squish_v3_add_test(myTestName myApplication testCase envVars testWrapper)
96 97 98
#   endif ()
#
#
99
#
100 101 102 103
# macro SQUISH_ADD_TEST(testName applicationUnderTest testCase envVars
# testWrapper)
#
# ::
104
#
105
#    This is deprecated. Use SQUISH_V3_ADD_TEST() if you are using Squish 3.x instead.
106

107

108 109
#=============================================================================
# Copyright 2008-2009 Kitware, Inc.
110
# Copyright 2012 Alexander Neundorf
111 112 113 114 115 116 117 118
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
119
# (To distribute this file outside of CMake, substitute the full
120 121
#  License text for the above reference.)

122 123 124

include(CMakeParseArguments)

125 126 127
set(SQUISH_INSTALL_DIR_STRING "Directory containing the bin, doc, and lib directories for Squish; this should be the root of the installation directory.")
set(SQUISH_SERVER_EXECUTABLE_STRING "The squishserver executable program.")
set(SQUISH_CLIENT_EXECUTABLE_STRING "The squishclient executable program.")
128 129

# Search only if the location is not already known.
130
if(NOT SQUISH_INSTALL_DIR)
131
  # Get the system search path as a list.
132
  file(TO_CMAKE_PATH "$ENV{PATH}" SQUISH_INSTALL_DIR_SEARCH2)
133 134

  # Construct a set of paths relative to the system search path.
135 136 137
  set(SQUISH_INSTALL_DIR_SEARCH "")
  foreach(dir ${SQUISH_INSTALL_DIR_SEARCH2})
    set(SQUISH_INSTALL_DIR_SEARCH ${SQUISH_INSTALL_DIR_SEARCH} "${dir}/../lib/fltk")
138
  endforeach()
139
  string(REPLACE "//" "/" SQUISH_INSTALL_DIR_SEARCH "${SQUISH_INSTALL_DIR_SEARCH}")
140 141

  # Look for an installation
142
  find_path(SQUISH_INSTALL_DIR bin/squishrunner
143
    HINTS
144
    # Look for an environment variable SQUISH_INSTALL_DIR.
145
      ENV SQUISH_INSTALL_DIR
146 147 148 149 150 151 152 153 154

    # Look in places relative to the system executable search path.
    ${SQUISH_INSTALL_DIR_SEARCH}

    # Look in standard UNIX install locations.
    #/usr/local/squish

    DOC "The ${SQUISH_INSTALL_DIR_STRING}"
    )
155
endif()
156 157

# search for the executables
158 159
if(SQUISH_INSTALL_DIR)
  set(SQUISH_INSTALL_DIR_FOUND 1)
160 161

  # find the client program
162
  if(NOT SQUISH_CLIENT_EXECUTABLE)
163
    find_program(SQUISH_CLIENT_EXECUTABLE ${SQUISH_INSTALL_DIR}/bin/squishrunner${CMAKE_EXECUTABLE_SUFFIX} DOC "The ${SQUISH_CLIENT_EXECUTABLE_STRING}")
164
  endif()
165 166

  # find the server program
167
  if(NOT SQUISH_SERVER_EXECUTABLE)
168
    find_program(SQUISH_SERVER_EXECUTABLE ${SQUISH_INSTALL_DIR}/bin/squishserver${CMAKE_EXECUTABLE_SUFFIX} DOC "The ${SQUISH_SERVER_EXECUTABLE_STRING}")
169
  endif()
170

171
else()
172
  set(SQUISH_INSTALL_DIR_FOUND 0)
173
endif()
174

Alexander Neundorf's avatar
Alexander Neundorf committed
175 176 177 178 179 180

set(SQUISH_VERSION)
set(SQUISH_VERSION_MAJOR )
set(SQUISH_VERSION_MINOR )
set(SQUISH_VERSION_PATCH )

181
# record if executables are set
182 183
if(SQUISH_CLIENT_EXECUTABLE)
  set(SQUISH_CLIENT_EXECUTABLE_FOUND 1)
Alexander Neundorf's avatar
Alexander Neundorf committed
184 185 186
  execute_process(COMMAND "${SQUISH_CLIENT_EXECUTABLE}" --version
                  OUTPUT_VARIABLE _squishVersionOutput
                  ERROR_QUIET )
187
  if("${_squishVersionOutput}" MATCHES "([0-9]+)\\.([0-9]+)\\.([0-9]+)")
Alexander Neundorf's avatar
Alexander Neundorf committed
188 189 190 191 192
    set(SQUISH_VERSION_MAJOR "${CMAKE_MATCH_1}")
    set(SQUISH_VERSION_MINOR "${CMAKE_MATCH_2}")
    set(SQUISH_VERSION_PATCH "${CMAKE_MATCH_3}")
    set(SQUISH_VERSION "${SQUISH_VERSION_MAJOR}.${SQUISH_VERSION_MINOR}.${SQUISH_VERSION_PATCH}" )
  endif()
193
else()
194
  set(SQUISH_CLIENT_EXECUTABLE_FOUND 0)
195
endif()
196 197 198

if(SQUISH_SERVER_EXECUTABLE)
  set(SQUISH_SERVER_EXECUTABLE_FOUND 1)
199
else()
200
  set(SQUISH_SERVER_EXECUTABLE_FOUND 0)
201
endif()
202 203

# record if Squish was found
Alexander Neundorf's avatar
Alexander Neundorf committed
204 205 206 207
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Squish  REQUIRED_VARS  SQUISH_INSTALL_DIR SQUISH_CLIENT_EXECUTABLE SQUISH_SERVER_EXECUTABLE
                                          VERSION_VAR  SQUISH_VERSION )

208

209
set(_SQUISH_MODULE_DIR "${CMAKE_CURRENT_LIST_DIR}")
210 211

macro(SQUISH_V3_ADD_TEST testName testAUT testCase envVars testWraper)
212 213 214 215
  if("${SQUISH_VERSION_MAJOR}" STREQUAL "4")
    message(STATUS "Using squish_v3_add_test(), but SQUISH_VERSION_MAJOR is ${SQUISH_VERSION_MAJOR}.\nThis may not work.")
  endif()

216
  add_test(${testName}
217
    ${CMAKE_COMMAND} -V -VV
218
    "-Dsquish_version:STRING=3"
219 220 221 222 223 224 225
    "-Dsquish_aut:STRING=${testAUT}"
    "-Dsquish_server_executable:STRING=${SQUISH_SERVER_EXECUTABLE}"
    "-Dsquish_client_executable:STRING=${SQUISH_CLIENT_EXECUTABLE}"
    "-Dsquish_libqtdir:STRING=${QT_LIBRARY_DIR}"
    "-Dsquish_test_case:STRING=${testCase}"
    "-Dsquish_env_vars:STRING=${envVars}"
    "-Dsquish_wrapper:STRING=${testWraper}"
226
    "-Dsquish_module_dir:STRING=${_SQUISH_MODULE_DIR}"
227
    -P "${_SQUISH_MODULE_DIR}/SquishTestScript.cmake"
228
    )
229
  set_tests_properties(${testName}
230 231
    PROPERTIES FAIL_REGULAR_EXPRESSION "FAILED;ERROR;FATAL"
    )
232
endmacro()
233

234 235 236 237 238

macro(SQUISH_ADD_TEST)
  message(STATUS "Using squish_add_test() is deprecated, use squish_v3_add_test() instead.")
  squish_v3_add_test(${ARGV})
endmacro()
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268


function(SQUISH_V4_ADD_TEST testName)

  if(NOT "${SQUISH_VERSION_MAJOR}" STREQUAL "4")
    message(STATUS "Using squish_v4_add_test(), but SQUISH_VERSION_MAJOR is ${SQUISH_VERSION_MAJOR}.\nThis may not work.")
  endif()

  set(oneValueArgs AUT SUITE TEST SETTINGSGROUP PRE_COMMAND POST_COMMAND)

  cmake_parse_arguments(_SQUISH "" "${oneValueArgs}" "" ${ARGN} )

  if(_SQUISH_UNPARSED_ARGUMENTS)
    message(FATAL_ERROR "Unknown keywords given to SQUISH_ADD_TEST(): \"${_SQUISH_UNPARSED_ARGUMENTS}\"")
  endif()

  if(NOT _SQUISH_AUT)
    message(FATAL_ERROR "Required argument AUT not given for SQUISH_ADD_TEST()")
  endif()

  if(NOT _SQUISH_SUITE)
    message(FATAL_ERROR "Required argument SUITE not given for SQUISH_ADD_TEST()")
  endif()

  if(NOT _SQUISH_TEST)
    message(FATAL_ERROR "Required argument TEST not given for SQUISH_ADD_TEST()")
  endif()

  get_target_property(testAUTLocation ${_SQUISH_AUT} LOCATION)
  get_filename_component(testAUTDir ${testAUTLocation} PATH)
269
  get_filename_component(testAUTName ${testAUTLocation} NAME)
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306

  get_filename_component(absTestSuite "${_SQUISH_SUITE}" ABSOLUTE)
  if(NOT EXISTS "${absTestSuite}")
    message(FATAL_ERROR "Could not find squish test suite ${_SQUISH_SUITE} (checked ${absTestSuite})")
  endif()

  set(absTestCase "${absTestSuite}/${_SQUISH_TEST}")
  if(NOT EXISTS "${absTestCase}")
    message(FATAL_ERROR "Could not find squish testcase ${_SQUISH_TEST} (checked ${absTestCase})")
  endif()

  if(NOT _SQUISH_SETTINGSGROUP)
    set(_SQUISH_SETTINGSGROUP "CTest_$ENV{LOGNAME}")
  endif()

  add_test(${testName}
    ${CMAKE_COMMAND} -V -VV
    "-Dsquish_version:STRING=4"
    "-Dsquish_aut:STRING=${testAUTName}"
    "-Dsquish_aut_dir:STRING=${testAUTDir}"
    "-Dsquish_server_executable:STRING=${SQUISH_SERVER_EXECUTABLE}"
    "-Dsquish_client_executable:STRING=${SQUISH_CLIENT_EXECUTABLE}"
    "-Dsquish_libqtdir:STRING=${QT_LIBRARY_DIR}"
    "-Dsquish_test_suite:STRING=${absTestSuite}"
    "-Dsquish_test_case:STRING=${_SQUISH_TEST}"
    "-Dsquish_env_vars:STRING=${envVars}"
    "-Dsquish_wrapper:STRING=${testWraper}"
    "-Dsquish_module_dir:STRING=${_SQUISH_MODULE_DIR}"
    "-Dsquish_settingsgroup:STRING=${_SQUISH_SETTINGSGROUP}"
    "-Dsquish_pre_command:STRING=${_SQUISH_PRE_COMMAND}"
    "-Dsquish_post_command:STRING=${_SQUISH_POST_COMMAND}"
    -P "${_SQUISH_MODULE_DIR}/SquishTestScript.cmake"
    )
  set_tests_properties(${testName}
    PROPERTIES FAIL_REGULAR_EXPRESSION "FAIL;FAILED;ERROR;FATAL"
    )
endfunction()