FindEXPAT.cmake 2.33 KB
Newer Older
1 2 3 4 5 6
#.rst:
# FindEXPAT
# ---------
#
# Find expat
#
7 8
# Find the native EXPAT headers and libraries.
#
9 10 11 12 13
# ::
#
#   EXPAT_INCLUDE_DIRS - where to find expat.h, etc.
#   EXPAT_LIBRARIES    - List of libraries when using expat.
#   EXPAT_FOUND        - True if expat found.
14

15 16 17 18 19 20 21 22 23 24
#=============================================================================
# Copyright 2006-2009 Kitware, Inc.
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
25
# (To distribute this file outside of CMake, substitute the full
26 27
#  License text for the above reference.)

28
# Look for the header file.
29
find_path(EXPAT_INCLUDE_DIR NAMES expat.h)
30 31

# Look for the library.
32
find_library(EXPAT_LIBRARY NAMES expat libexpat)
33

34 35 36 37 38 39 40
if (EXPAT_INCLUDE_DIR AND EXISTS "${EXPAT_INCLUDE_DIR}/expat.h")
    file(STRINGS "${EXPAT_INCLUDE_DIR}/expat.h" expat_version_str
         REGEX "^#[\t ]*define[\t ]+XML_(MAJOR|MINOR|MICRO)_VERSION[\t ]+[0-9]+$")

    unset(EXPAT_VERSION_STRING)
    foreach(VPART MAJOR MINOR MICRO)
        foreach(VLINE ${expat_version_str})
41 42
            if(VLINE MATCHES "^#[\t ]*define[\t ]+XML_${VPART}_VERSION[\t ]+([0-9]+)$")
                set(EXPAT_VERSION_PART "${CMAKE_MATCH_1}")
43 44
                if(EXPAT_VERSION_STRING)
                    set(EXPAT_VERSION_STRING "${EXPAT_VERSION_STRING}.${EXPAT_VERSION_PART}")
45
                else()
46
                    set(EXPAT_VERSION_STRING "${EXPAT_VERSION_PART}")
47
                endif()
48
            endif()
49 50 51
        endforeach()
    endforeach()
endif ()
52

53
# handle the QUIETLY and REQUIRED arguments and set EXPAT_FOUND to TRUE if
54
# all listed variables are TRUE
55
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
56 57 58
FIND_PACKAGE_HANDLE_STANDARD_ARGS(EXPAT
                                  REQUIRED_VARS EXPAT_LIBRARY EXPAT_INCLUDE_DIR
                                  VERSION_VAR EXPAT_VERSION_STRING)
59 60

# Copy the results to the output variables.
61 62 63
if(EXPAT_FOUND)
  set(EXPAT_LIBRARIES ${EXPAT_LIBRARY})
  set(EXPAT_INCLUDE_DIRS ${EXPAT_INCLUDE_DIR})
64
endif()
65

66
mark_as_advanced(EXPAT_INCLUDE_DIR EXPAT_LIBRARY)