1#
2#  Copyright (c) 2013, Kornel Benko, <kornel@lyx.org>
3#  Redistribution and use in source and binary forms, with or without
4#  modification, are permitted provided that the following conditions
5#  are met:
6#
7#  1. Redistributions of source code must retain the copyright
8#     notice, this list of conditions and the following disclaimer.
9#  2. Redistributions in binary form must reproduce the copyright
10#     notice, this list of conditions and the following disclaimer in the
11#     documentation and/or other materials provided with the distribution.
12#  3. The name of the author may not be used to endorse or promote products
13#     derived from this software without specific prior written permission.
14#
15#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16#  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17#  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18#  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19#  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20#  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21#  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22#  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23#  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24#  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25#
26# Try to find the gnu tar command
27# Once done this will define
28#
29#       GNUTAR_FOUND
30#       GNUTAR_EXECUTABLE
31#
32set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
33
34find_program(GNUTAR_EXECUTABLE NAMES "gtar" "tar")
35mark_as_advanced(GNUTAR_EXECUTABLE)
36
37if(GNUTAR_EXECUTABLE)
38  execute_process(COMMAND ${GNUTAR_EXECUTABLE} --version
39    OUTPUT_VARIABLE GNUTAR_output
40    ERROR_VARIABLE GNUTAR_error
41    RESULT_VARIABLE GNUTAR_result
42    OUTPUT_STRIP_TRAILING_WHITESPACE)
43  if(${GNUTAR_result} EQUAL 0)
44    string(REGEX REPLACE "[\n]+" ";" GNUTAR_version ${GNUTAR_output})
45    foreach(_l ${GNUTAR_version})
46      if(_l MATCHES "^tar +\\(GNU +tar\\) +[0-9]")
47        string(REGEX REPLACE "^tar +\\(GNU +tar\\) +([0-9]\\.[0-9]+)" "\\1" GNUTAR_VERSION_STRING ${_l})
48        break()
49      endif()
50    endforeach()
51  endif()
52endif()
53
54# handle the QUIETLY and REQUIRED arguments and set GNUTAR_FOUND to TRUE if
55# all listed variables are TRUE
56include(FindPackageHandleStandardArgs)
57find_package_handle_standard_args(GNUTAR DEFAULT_MSG GNUTAR_EXECUTABLE GNUTAR_VERSION_STRING)
58include(CMakeParseArguments)
59
60