FindXercesC.cmake 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindXercesC
  5. -----------
  6. Find the Apache Xerces-C++ validating XML parser headers and libraries.
  7. Imported targets
  8. ^^^^^^^^^^^^^^^^
  9. This module defines the following :prop_tgt:`IMPORTED` targets:
  10. ``XercesC::XercesC``
  11. The Xerces-C++ ``xerces-c`` library, if found.
  12. Result variables
  13. ^^^^^^^^^^^^^^^^
  14. This module will set the following variables in your project:
  15. ``XercesC_FOUND``
  16. true if the Xerces headers and libraries were found
  17. ``XercesC_VERSION``
  18. Xerces release version
  19. ``XercesC_INCLUDE_DIRS``
  20. the directory containing the Xerces headers
  21. ``XercesC_LIBRARIES``
  22. Xerces libraries to be linked
  23. Cache variables
  24. ^^^^^^^^^^^^^^^
  25. The following cache variables may also be set:
  26. ``XercesC_INCLUDE_DIR``
  27. the directory containing the Xerces headers
  28. ``XercesC_LIBRARY``
  29. the Xerces library
  30. #]=======================================================================]
  31. # Written by Roger Leigh <rleigh@codelibre.net>
  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. set(XercesC_VERSION_MAJOR "${XercesC_MAJOR}" PARENT_SCOPE)
  49. set(XercesC_VERSION_MINOR "${XercesC_MINOR}" PARENT_SCOPE)
  50. set(XercesC_VERSION_PATCH "${XercesC_PATCH}" PARENT_SCOPE)
  51. else()
  52. message(FATAL_ERROR "Include file ${version_hdr} does not exist or does not contain expected version information")
  53. endif()
  54. endfunction()
  55. # Find include directory
  56. find_path(XercesC_INCLUDE_DIR
  57. NAMES "xercesc/util/PlatformUtils.hpp"
  58. DOC "Xerces-C++ include directory")
  59. mark_as_advanced(XercesC_INCLUDE_DIR)
  60. if(XercesC_INCLUDE_DIR AND EXISTS "${XercesC_INCLUDE_DIR}/xercesc/util/XercesVersion.hpp")
  61. _XercesC_GET_VERSION("${XercesC_INCLUDE_DIR}/xercesc/util/XercesVersion.hpp")
  62. endif()
  63. if(NOT XercesC_LIBRARY)
  64. # Find all XercesC libraries
  65. find_library(XercesC_LIBRARY_RELEASE
  66. NAMES "xerces-c" "xerces-c_${XercesC_VERSION_MAJOR}"
  67. DOC "Xerces-C++ libraries (release)")
  68. find_library(XercesC_LIBRARY_DEBUG
  69. NAMES "xerces-cd" "xerces-c_${XercesC_VERSION_MAJOR}D" "xerces-c_${XercesC_VERSION_MAJOR}_${XercesC_VERSION_MINOR}D"
  70. DOC "Xerces-C++ libraries (debug)")
  71. include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
  72. select_library_configurations(XercesC)
  73. mark_as_advanced(XercesC_LIBRARY_RELEASE XercesC_LIBRARY_DEBUG)
  74. endif()
  75. unset(XercesC_VERSION_MAJOR)
  76. unset(XercesC_VERSION_MINOR)
  77. unset(XercesC_VERSION_PATCH)
  78. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  79. FIND_PACKAGE_HANDLE_STANDARD_ARGS(XercesC
  80. FOUND_VAR XercesC_FOUND
  81. REQUIRED_VARS XercesC_LIBRARY
  82. XercesC_INCLUDE_DIR
  83. XercesC_VERSION
  84. VERSION_VAR XercesC_VERSION
  85. FAIL_MESSAGE "Failed to find XercesC")
  86. if(XercesC_FOUND)
  87. set(XercesC_INCLUDE_DIRS "${XercesC_INCLUDE_DIR}")
  88. set(XercesC_LIBRARIES "${XercesC_LIBRARY}")
  89. # For header-only libraries
  90. if(NOT TARGET XercesC::XercesC)
  91. add_library(XercesC::XercesC UNKNOWN IMPORTED)
  92. if(XercesC_INCLUDE_DIRS)
  93. set_target_properties(XercesC::XercesC PROPERTIES
  94. INTERFACE_INCLUDE_DIRECTORIES "${XercesC_INCLUDE_DIRS}")
  95. endif()
  96. if(EXISTS "${XercesC_LIBRARY}")
  97. set_target_properties(XercesC::XercesC PROPERTIES
  98. IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
  99. IMPORTED_LOCATION "${XercesC_LIBRARY}")
  100. endif()
  101. if(EXISTS "${XercesC_LIBRARY_RELEASE}")
  102. set_property(TARGET XercesC::XercesC APPEND PROPERTY
  103. IMPORTED_CONFIGURATIONS RELEASE)
  104. set_target_properties(XercesC::XercesC PROPERTIES
  105. IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "CXX"
  106. IMPORTED_LOCATION_RELEASE "${XercesC_LIBRARY_RELEASE}")
  107. endif()
  108. if(EXISTS "${XercesC_LIBRARY_DEBUG}")
  109. set_property(TARGET XercesC::XercesC APPEND PROPERTY
  110. IMPORTED_CONFIGURATIONS DEBUG)
  111. set_target_properties(XercesC::XercesC PROPERTIES
  112. IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "CXX"
  113. IMPORTED_LOCATION_DEBUG "${XercesC_LIBRARY_DEBUG}")
  114. endif()
  115. endif()
  116. endif()