~laurynas-biveinis/percona-xtrabackup/xtrabackup-page-filters

« back to all changes in this revision

Viewing changes to src/libarchive/build/cmake/AddTest28.cmake

merge parallel compression branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.
 
9
#
 
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.
 
15
#
 
16
# Example usage:
 
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
 
20
# "myexe".
 
21
 
 
22
#=============================================================================
 
23
# Copyright 2009 Kitware, Inc.
 
24
# All rights reserved.
 
25
#
 
26
# Redistribution and use in source and binary forms, with or without
 
27
# modification, are permitted provided that the following conditions
 
28
# are met:
 
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.
 
35
#
 
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
#=============================================================================
 
47
 
 
48
CMAKE_MINIMUM_REQUIRED(VERSION 2.6.3)
 
49
 
 
50
# CMake 2.8 supports ADD_TEST(NAME) natively.
 
51
IF(NOT "${CMAKE_VERSION}" VERSION_LESS "2.8")
 
52
  MACRO(ADD_TEST_28)
 
53
    ADD_TEST(${ARGV})
 
54
  ENDMACRO()
 
55
  RETURN()
 
56
ENDIF()
 
57
 
 
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\"")
 
63
  ENDIF()
 
64
  IF(NOT "x${COMMAND}" STREQUAL "xCOMMAND")
 
65
    MESSAGE(FATAL_ERROR "Third ADD_TEST_28 argument must be \"COMMAND\"")
 
66
  ENDIF()
 
67
 
 
68
  # Perform "COMMAND myexe ..." substitution.
 
69
  SET(cmd "${command}")
 
70
  IF(TARGET "${cmd}")
 
71
    _ADD_TEST_28_GET_EXE(${cmd} cmd)
 
72
  ENDIF()
 
73
 
 
74
  # Perform "COMMAND ... $<TARGET_FILE:myexe> ..." substitution.
 
75
  SET(target_file "\\$<TARGET_FILE:(.+)>")
 
76
  SET(args)
 
77
  FOREACH(ARG ${cmd} ${ARGN})
 
78
    SET(arg "${ARG}")
 
79
    IF("${arg}" MATCHES "${target_file}")
 
80
      STRING(REGEX REPLACE "${target_file}" "\\1" tgt "${arg}")
 
81
      IF(TARGET "${tgt}")
 
82
        _ADD_TEST_28_GET_EXE(${tgt} exe)
 
83
        STRING(REGEX REPLACE "${target_file}" "${exe}" arg "${arg}")
 
84
      ENDIF()
 
85
    ENDIF()
 
86
    LIST(APPEND args "${arg}")
 
87
  ENDFOREACH()
 
88
 
 
89
  # Invoke old ADD_TEST() signature with transformed arguments.
 
90
  ADD_TEST(${name} ${args})
 
91
ENDMACRO()
 
92
 
 
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)
 
97
 
 
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)
 
107
ENDMACRO()