FindEXPAT.cmake 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. # XXX: Copied from CMake, but includes vtkDetectLibraryType.
  4. # See https://gitlab.kitware.com/cmake/cmake/issues/18564
  5. #[=======================================================================[.rst:
  6. FindEXPAT
  7. ---------
  8. Find the native Expat headers and library.
  9. Imported Targets
  10. ^^^^^^^^^^^^^^^^
  11. This module defines the following :prop_tgt:`IMPORTED` targets:
  12. ``EXPAT::EXPAT``
  13. The Expat ``expat`` library, if found.
  14. Result Variables
  15. ^^^^^^^^^^^^^^^^
  16. This module will set the following variables in your project:
  17. ``EXPAT_INCLUDE_DIRS``
  18. where to find expat.h, etc.
  19. ``EXPAT_LIBRARIES``
  20. the libraries to link against to use Expat.
  21. ``EXPAT_FOUND``
  22. true if the Expat headers and libraries were found.
  23. #]=======================================================================]
  24. find_package(PkgConfig QUIET)
  25. pkg_check_modules(PC_EXPAT QUIET expat)
  26. # Look for the header file.
  27. find_path(EXPAT_INCLUDE_DIR NAMES expat.h HINTS ${PC_EXPAT_INCLUDE_DIRS})
  28. # Look for the library.
  29. find_library(EXPAT_LIBRARY NAMES expat libexpat HINTS ${PC_EXPAT_LIBRARY_DIRS})
  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. string(APPEND 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. include(FindPackageHandleStandardArgs)
  48. FIND_PACKAGE_HANDLE_STANDARD_ARGS(EXPAT
  49. REQUIRED_VARS EXPAT_LIBRARY EXPAT_INCLUDE_DIR
  50. VERSION_VAR EXPAT_VERSION_STRING)
  51. # Copy the results to the output variables and target.
  52. if(EXPAT_FOUND)
  53. set(EXPAT_LIBRARIES ${EXPAT_LIBRARY})
  54. set(EXPAT_INCLUDE_DIRS ${EXPAT_INCLUDE_DIR})
  55. if(NOT TARGET EXPAT::EXPAT)
  56. include(vtkDetectLibraryType)
  57. vtk_detect_library_type(expat_library_type
  58. PATH "${EXPAT_LIBRARY}")
  59. add_library(EXPAT::EXPAT "${expat_library_type}" IMPORTED)
  60. unset(expat_library_type)
  61. set_target_properties(EXPAT::EXPAT PROPERTIES
  62. IMPORTED_LINK_INTERFACE_LANGUAGES "C"
  63. IMPORTED_LOCATION "${EXPAT_LIBRARY}"
  64. IMPORTED_IMPLIB "${EXPAT_LIBRARY}"
  65. INTERFACE_INCLUDE_DIRECTORIES "${EXPAT_INCLUDE_DIRS}")
  66. endif()
  67. endif()
  68. mark_as_advanced(EXPAT_INCLUDE_DIR EXPAT_LIBRARY)