FindXercesC.cmake 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #.rst:
  2. # FindXercesC
  3. # -----------
  4. #
  5. # Find the Apache Xerces-C++ validating XML parser headers and libraries.
  6. #
  7. # This module reports information about the Xerces installation in
  8. # several variables. General variables::
  9. #
  10. # XercesC_FOUND - true if the Xerces headers and libraries were found
  11. # XercesC_VERSION - Xerces release version
  12. # XercesC_INCLUDE_DIRS - the directory containing the Xerces headers
  13. # XercesC_LIBRARIES - Xerces libraries to be linked
  14. #
  15. # The following cache variables may also be set::
  16. #
  17. # XercesC_INCLUDE_DIR - the directory containing the Xerces headers
  18. # XercesC_LIBRARY - the Xerces library
  19. # Written by Roger Leigh <rleigh@codelibre.net>
  20. #=============================================================================
  21. # Copyright 2014 University of Dundee
  22. #
  23. # Distributed under the OSI-approved BSD License (the "License");
  24. # see accompanying file Copyright.txt for details.
  25. #
  26. # This software is distributed WITHOUT ANY WARRANTY; without even the
  27. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  28. # See the License for more information.
  29. #=============================================================================
  30. # (To distribute this file outside of CMake, substitute the full
  31. # License text for the above reference.)
  32. function(_XercesC_GET_VERSION version_hdr)
  33. file(STRINGS ${version_hdr} _contents REGEX "^[ \t]*#define XERCES_VERSION_.*")
  34. if(_contents)
  35. string(REGEX REPLACE ".*#define XERCES_VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" XercesC_MAJOR "${_contents}")
  36. string(REGEX REPLACE ".*#define XERCES_VERSION_MINOR[ \t]+([0-9]+).*" "\\1" XercesC_MINOR "${_contents}")
  37. string(REGEX REPLACE ".*#define XERCES_VERSION_REVISION[ \t]+([0-9]+).*" "\\1" XercesC_PATCH "${_contents}")
  38. if(NOT XercesC_MAJOR MATCHES "^[0-9]+$")
  39. message(FATAL_ERROR "Version parsing failed for XERCES_VERSION_MAJOR!")
  40. endif()
  41. if(NOT XercesC_MINOR MATCHES "^[0-9]+$")
  42. message(FATAL_ERROR "Version parsing failed for XERCES_VERSION_MINOR!")
  43. endif()
  44. if(NOT XercesC_PATCH MATCHES "^[0-9]+$")
  45. message(FATAL_ERROR "Version parsing failed for XERCES_VERSION_REVISION!")
  46. endif()
  47. set(XercesC_VERSION "${XercesC_MAJOR}.${XercesC_MINOR}.${XercesC_PATCH}" PARENT_SCOPE)
  48. else()
  49. message(FATAL_ERROR "Include file ${version_hdr} does not exist or does not contain expected version information")
  50. endif()
  51. endfunction()
  52. # Find include directory
  53. find_path(XercesC_INCLUDE_DIR
  54. NAMES "xercesc/util/PlatformUtils.hpp"
  55. DOC "Xerces-C++ include directory")
  56. mark_as_advanced(XercesC_INCLUDE_DIR)
  57. # Find all XercesC libraries
  58. find_library(XercesC_LIBRARY "xerces-c"
  59. DOC "Xerces-C++ libraries")
  60. mark_as_advanced(XercesC_LIBRARY)
  61. if(XercesC_INCLUDE_DIR)
  62. _XercesC_GET_VERSION("${XercesC_INCLUDE_DIR}/xercesc/util/XercesVersion.hpp")
  63. endif()
  64. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  65. FIND_PACKAGE_HANDLE_STANDARD_ARGS(XercesC
  66. FOUND_VAR XercesC_FOUND
  67. REQUIRED_VARS XercesC_LIBRARY
  68. XercesC_INCLUDE_DIR
  69. XercesC_VERSION
  70. VERSION_VAR XercesC_VERSION
  71. FAIL_MESSAGE "Failed to find XercesC")
  72. if(XercesC_FOUND)
  73. set(XercesC_INCLUDE_DIRS "${XercesC_INCLUDE_DIR}")
  74. set(XercesC_LIBRARIES "${XercesC_LIBRARY}")
  75. endif()