1
0

FindEXPAT.cmake 2.4 KB

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