Imported Upstream version 2.8.10.2
[platform/upstream/cmake.git] / Modules / FindEXPAT.cmake
1 # - Find expat
2 # Find the native EXPAT headers and libraries.
3 #
4 #  EXPAT_INCLUDE_DIRS - where to find expat.h, etc.
5 #  EXPAT_LIBRARIES    - List of libraries when using expat.
6 #  EXPAT_FOUND        - True if expat found.
7
8 #=============================================================================
9 # Copyright 2006-2009 Kitware, Inc.
10 #
11 # Distributed under the OSI-approved BSD License (the "License");
12 # see accompanying file Copyright.txt for details.
13 #
14 # This software is distributed WITHOUT ANY WARRANTY; without even the
15 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 # See the License for more information.
17 #=============================================================================
18 # (To distribute this file outside of CMake, substitute the full
19 #  License text for the above reference.)
20
21 # Look for the header file.
22 find_path(EXPAT_INCLUDE_DIR NAMES expat.h)
23
24 # Look for the library.
25 find_library(EXPAT_LIBRARY NAMES expat libexpat)
26
27 if (EXPAT_INCLUDE_DIR AND EXISTS "${EXPAT_INCLUDE_DIR}/expat.h")
28     file(STRINGS "${EXPAT_INCLUDE_DIR}/expat.h" expat_version_str
29          REGEX "^#[\t ]*define[\t ]+XML_(MAJOR|MINOR|MICRO)_VERSION[\t ]+[0-9]+$")
30
31     unset(EXPAT_VERSION_STRING)
32     foreach(VPART MAJOR MINOR MICRO)
33         foreach(VLINE ${expat_version_str})
34             if(VLINE MATCHES "^#[\t ]*define[\t ]+XML_${VPART}_VERSION")
35                 string(REGEX REPLACE "^#[\t ]*define[\t ]+XML_${VPART}_VERSION[\t ]+([0-9]+)$" "\\1"
36                        EXPAT_VERSION_PART "${VLINE}")
37                 if(EXPAT_VERSION_STRING)
38                     set(EXPAT_VERSION_STRING "${EXPAT_VERSION_STRING}.${EXPAT_VERSION_PART}")
39                 else()
40                     set(EXPAT_VERSION_STRING "${EXPAT_VERSION_PART}")
41                 endif()
42             endif()
43         endforeach()
44     endforeach()
45 endif ()
46
47 # handle the QUIETLY and REQUIRED arguments and set EXPAT_FOUND to TRUE if
48 # all listed variables are TRUE
49 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
50 FIND_PACKAGE_HANDLE_STANDARD_ARGS(EXPAT
51                                   REQUIRED_VARS EXPAT_LIBRARY EXPAT_INCLUDE_DIR
52                                   VERSION_VAR EXPAT_VERSION_STRING)
53
54 # Copy the results to the output variables.
55 if(EXPAT_FOUND)
56   set(EXPAT_LIBRARIES ${EXPAT_LIBRARY})
57   set(EXPAT_INCLUDE_DIRS ${EXPAT_INCLUDE_DIR})
58 endif()
59
60 mark_as_advanced(EXPAT_INCLUDE_DIR EXPAT_LIBRARY)