TZIVI-254: IVI needs a newer version of cmake
[profile/ivi/cmake.git] / Modules / FindCups.cmake
1 # - Try to find the Cups printing system
2 # Once done this will define
3 #
4 #  CUPS_FOUND - system has Cups
5 #  CUPS_INCLUDE_DIR - the Cups include directory
6 #  CUPS_LIBRARIES - Libraries needed to use Cups
7 #  CUPS_VERSION_STRING - version of Cups found (since CMake 2.8.8)
8 #  Set CUPS_REQUIRE_IPP_DELETE_ATTRIBUTE to TRUE if you need a version which 
9 #  features this function (i.e. at least 1.1.19)
10
11 #=============================================================================
12 # Copyright 2006-2009 Kitware, Inc.
13 # Copyright 2006 Alexander Neundorf <neundorf@kde.org>
14 # Copyright 2012 Rolf Eike Beer <eike@sf-mail.de>
15 #
16 # Distributed under the OSI-approved BSD License (the "License");
17 # see accompanying file Copyright.txt for details.
18 #
19 # This software is distributed WITHOUT ANY WARRANTY; without even the
20 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 # See the License for more information.
22 #=============================================================================
23 # (To distribute this file outside of CMake, substitute the full
24 #  License text for the above reference.)
25
26 find_path(CUPS_INCLUDE_DIR cups/cups.h )
27
28 find_library(CUPS_LIBRARIES NAMES cups )
29
30 if (CUPS_INCLUDE_DIR AND CUPS_LIBRARIES AND CUPS_REQUIRE_IPP_DELETE_ATTRIBUTE)
31     include(CheckLibraryExists)
32
33     # ippDeleteAttribute is new in cups-1.1.19 (and used by kdeprint)
34     CHECK_LIBRARY_EXISTS(cups ippDeleteAttribute "" CUPS_HAS_IPP_DELETE_ATTRIBUTE)
35 endif (CUPS_INCLUDE_DIR AND CUPS_LIBRARIES AND CUPS_REQUIRE_IPP_DELETE_ATTRIBUTE)
36
37 if (CUPS_INCLUDE_DIR AND EXISTS "${CUPS_INCLUDE_DIR}/cups/cups.h")
38     file(STRINGS "${CUPS_INCLUDE_DIR}/cups/cups.h" cups_version_str
39          REGEX "^#[\t ]*define[\t ]+CUPS_VERSION_(MAJOR|MINOR|PATCH)[\t ]+[0-9]+$")
40
41     unset(CUPS_VERSION_STRING)
42     foreach(VPART MAJOR MINOR PATCH)
43         foreach(VLINE ${cups_version_str})
44             if(VLINE MATCHES "^#[\t ]*define[\t ]+CUPS_VERSION_${VPART}")
45                 string(REGEX REPLACE "^#[\t ]*define[\t ]+CUPS_VERSION_${VPART}[\t ]+([0-9]+)$" "\\1"
46                        CUPS_VERSION_PART "${VLINE}")
47                 if(CUPS_VERSION_STRING)
48                     set(CUPS_VERSION_STRING "${CUPS_VERSION_STRING}.${CUPS_VERSION_PART}")
49                 else(CUPS_VERSION_STRING)
50                     set(CUPS_VERSION_STRING "${CUPS_VERSION_PART}")
51                 endif(CUPS_VERSION_STRING)
52             endif()
53         endforeach(VLINE)
54     endforeach(VPART)
55 endif (CUPS_INCLUDE_DIR AND EXISTS "${CUPS_INCLUDE_DIR}/cups/cups.h")
56
57 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
58
59 if (CUPS_REQUIRE_IPP_DELETE_ATTRIBUTE)
60     FIND_PACKAGE_HANDLE_STANDARD_ARGS(Cups
61                                       REQUIRED_VARS CUPS_LIBRARIES CUPS_INCLUDE_DIR CUPS_HAS_IPP_DELETE_ATTRIBUTE
62                                       VERSION_VAR CUPS_VERSION_STRING)
63 else (CUPS_REQUIRE_IPP_DELETE_ATTRIBUTE)
64     FIND_PACKAGE_HANDLE_STANDARD_ARGS(Cups
65                                       REQUIRED_VARS CUPS_LIBRARIES CUPS_INCLUDE_DIR
66                                       VERSION_VAR CUPS_VERSION_STRING)
67 endif (CUPS_REQUIRE_IPP_DELETE_ATTRIBUTE)
68   
69 mark_as_advanced(CUPS_INCLUDE_DIR CUPS_LIBRARIES)