FindEXPAT.cmake 2.3 KB

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