1
# - Macro approximating the CMake 2.8 ADD_TEST(NAME) signature.
2
# ADD_TEST_28(NAME <name> COMMAND <command> [arg1 [arg2 ...]])
3
# <name> - The name of the test
4
# <command> - The test executable
5
# [argN...] - Arguments to the test executable
6
# This macro approximates the ADD_TEST(NAME) signature provided in
7
# CMake 2.8 but works with CMake 2.6 too. See CMake 2.8 documentation
8
# of ADD_TEST()for details.
10
# This macro automatically replaces a <command> that names an
11
# executable target with the target location. A generator expression
12
# of the form "$<TARGET_FILE:tgt>" is supported in both the command
13
# and arguments of the test. Howerver, this macro only works for
14
# targets without per-config output name properties set.
17
# add_test(NAME mytest COMMAND testDriver --exe $<TARGET_FILE:myexe>)
18
# This creates a test "mytest" whose command runs a testDriver tool
19
# passing the full path to the executable file produced by target
22
#=============================================================================
23
# Copyright 2009 Kitware, Inc.
24
# All rights reserved.
26
# Redistribution and use in source and binary forms, with or without
27
# modification, are permitted provided that the following conditions
29
# 1. Redistributions of source code must retain the above copyright
30
# notice, this list of conditions and the following disclaimer
31
# in this position and unchanged.
32
# 2. Redistributions in binary form must reproduce the above copyright
33
# notice, this list of conditions and the following disclaimer in the
34
# documentation and/or other materials provided with the distribution.
36
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
37
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
39
# IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
40
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
45
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46
#=============================================================================
48
CMAKE_MINIMUM_REQUIRED(VERSION 2.6.3)
50
# CMake 2.8 supports ADD_TEST(NAME) natively.
51
IF(NOT "${CMAKE_VERSION}" VERSION_LESS "2.8")
58
# Simulate ADD_TEST(NAME) signature from CMake 2.8.
59
MACRO(ADD_TEST_28 NAME name COMMAND command)
60
# Enforce the signature.
61
IF(NOT "x${NAME}" STREQUAL "xNAME")
62
MESSAGE(FATAL_ERROR "First ADD_TEST_28 argument must be \"NAME\"")
64
IF(NOT "x${COMMAND}" STREQUAL "xCOMMAND")
65
MESSAGE(FATAL_ERROR "Third ADD_TEST_28 argument must be \"COMMAND\"")
68
# Perform "COMMAND myexe ..." substitution.
71
_ADD_TEST_28_GET_EXE(${cmd} cmd)
74
# Perform "COMMAND ... $<TARGET_FILE:myexe> ..." substitution.
75
SET(target_file "\\$<TARGET_FILE:(.+)>")
77
FOREACH(ARG ${cmd} ${ARGN})
79
IF("${arg}" MATCHES "${target_file}")
80
STRING(REGEX REPLACE "${target_file}" "\\1" tgt "${arg}")
82
_ADD_TEST_28_GET_EXE(${tgt} exe)
83
STRING(REGEX REPLACE "${target_file}" "${exe}" arg "${arg}")
86
LIST(APPEND args "${arg}")
89
# Invoke old ADD_TEST() signature with transformed arguments.
90
ADD_TEST(${name} ${args})
93
# Get the test-time location of an executable target.
94
MACRO(_ADD_TEST_28_GET_EXE tgt exe_var)
95
# The LOCATION property gives a build-time location.
96
GET_TARGET_PROPERTY(${exe_var} ${tgt} LOCATION)
98
# In single-configuration generatrs the build-time and test-time
99
# locations are the same because there is no per-config variable
100
# reference. In multi-configuration generators the following
101
# substitution converts the build-time configuration variable
102
# reference to a test-time configuration variable reference.
103
IF(CMAKE_CONFIGURATION_TYPES)
104
STRING(REPLACE "${CMAKE_CFG_INTDIR}" "\${CTEST_CONFIGURATION_TYPE}"
105
${exe_var} "${${exe_var}}")
106
ENDIF(CMAKE_CONFIGURATION_TYPES)