FindXercesC.cmake 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. #
  7. # Find the Apache Xerces-C++ validating XML parser headers and libraries.
  8. #
  9. # Imported targets
  10. # ^^^^^^^^^^^^^^^^
  11. #
  12. # This module defines the following :prop_tgt:`IMPORTED` targets:
  13. #
  14. # ``XercesC::XercesC``
  15. # The Xerces-C++ ``xerces-c`` library, if found.
  16. #
  17. # Result variables
  18. # ^^^^^^^^^^^^^^^^
  19. #
  20. # This module will set the following variables in your project:
  21. #
  22. # ``XercesC_FOUND``
  23. # true if the Xerces headers and libraries were found
  24. # ``XercesC_VERSION``
  25. # Xerces release version
  26. # ``XercesC_INCLUDE_DIRS``
  27. # the directory containing the Xerces headers
  28. # ``XercesC_LIBRARIES``
  29. # Xerces libraries to be linked
  30. #
  31. # Cache variables
  32. # ^^^^^^^^^^^^^^^
  33. #
  34. # The following cache variables may also be set:
  35. #
  36. # ``XercesC_INCLUDE_DIR``
  37. # the directory containing the Xerces headers
  38. # ``XercesC_LIBRARY``
  39. # the Xerces library
  40. # Written by Roger Leigh <rleigh@codelibre.net>
  41. function(_XercesC_GET_VERSION version_hdr)
  42. file(STRINGS ${version_hdr} _contents REGEX "^[ \t]*#define XERCES_VERSION_.*")
  43. if(_contents)
  44. string(REGEX REPLACE ".*#define XERCES_VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" XercesC_MAJOR "${_contents}")
  45. string(REGEX REPLACE ".*#define XERCES_VERSION_MINOR[ \t]+([0-9]+).*" "\\1" XercesC_MINOR "${_contents}")
  46. string(REGEX REPLACE ".*#define XERCES_VERSION_REVISION[ \t]+([0-9]+).*" "\\1" XercesC_PATCH "${_contents}")
  47. if(NOT XercesC_MAJOR MATCHES "^[0-9]+$")
  48. message(FATAL_ERROR "Version parsing failed for XERCES_VERSION_MAJOR!")
  49. endif()
  50. if(NOT XercesC_MINOR MATCHES "^[0-9]+$")
  51. message(FATAL_ERROR "Version parsing failed for XERCES_VERSION_MINOR!")
  52. endif()
  53. if(NOT XercesC_PATCH MATCHES "^[0-9]+$")
  54. message(FATAL_ERROR "Version parsing failed for XERCES_VERSION_REVISION!")
  55. endif()
  56. set(XercesC_VERSION "${XercesC_MAJOR}.${XercesC_MINOR}.${XercesC_PATCH}" PARENT_SCOPE)
  57. else()
  58. message(FATAL_ERROR "Include file ${version_hdr} does not exist or does not contain expected version information")
  59. endif()
  60. endfunction()
  61. # Find include directory
  62. find_path(XercesC_INCLUDE_DIR
  63. NAMES "xercesc/util/PlatformUtils.hpp"
  64. DOC "Xerces-C++ include directory")
  65. mark_as_advanced(XercesC_INCLUDE_DIR)
  66. if(NOT XercesC_LIBRARY)
  67. # Find all XercesC libraries
  68. find_library(XercesC_LIBRARY_RELEASE
  69. NAMES "xerces-c" "xerces-c_3"
  70. DOC "Xerces-C++ libraries (release)")
  71. find_library(XercesC_LIBRARY_DEBUG
  72. NAMES "xerces-cd" "xerces-c_3D" "xerces-c_3_1D"
  73. DOC "Xerces-C++ libraries (debug)")
  74. include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
  75. select_library_configurations(XercesC)
  76. mark_as_advanced(XercesC_LIBRARY_RELEASE XercesC_LIBRARY_DEBUG)
  77. endif()
  78. if(XercesC_INCLUDE_DIR)
  79. _XercesC_GET_VERSION("${XercesC_INCLUDE_DIR}/xercesc/util/XercesVersion.hpp")
  80. endif()
  81. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  82. FIND_PACKAGE_HANDLE_STANDARD_ARGS(XercesC
  83. FOUND_VAR XercesC_FOUND
  84. REQUIRED_VARS XercesC_LIBRARY
  85. XercesC_INCLUDE_DIR
  86. XercesC_VERSION
  87. VERSION_VAR XercesC_VERSION
  88. FAIL_MESSAGE "Failed to find XercesC")
  89. if(XercesC_FOUND)
  90. set(XercesC_INCLUDE_DIRS "${XercesC_INCLUDE_DIR}")
  91. set(XercesC_LIBRARIES "${XercesC_LIBRARY}")
  92. # For header-only libraries
  93. if(NOT TARGET XercesC::XercesC)
  94. add_library(XercesC::XercesC UNKNOWN IMPORTED)
  95. if(XercesC_INCLUDE_DIRS)
  96. set_target_properties(XercesC::XercesC PROPERTIES
  97. INTERFACE_INCLUDE_DIRECTORIES "${XercesC_INCLUDE_DIRS}")
  98. endif()
  99. if(EXISTS "${XercesC_LIBRARY}")
  100. set_target_properties(XercesC::XercesC PROPERTIES
  101. IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
  102. IMPORTED_LOCATION "${XercesC_LIBRARY}")
  103. endif()
  104. if(EXISTS "${XercesC_LIBRARY_RELEASE}")
  105. set_property(TARGET XercesC::XercesC APPEND PROPERTY
  106. IMPORTED_CONFIGURATIONS RELEASE)
  107. set_target_properties(XercesC::XercesC PROPERTIES
  108. IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "CXX"
  109. IMPORTED_LOCATION_RELEASE "${XercesC_LIBRARY_RELEASE}")
  110. endif()
  111. if(EXISTS "${XercesC_LIBRARY_DEBUG}")
  112. set_property(TARGET XercesC::XercesC APPEND PROPERTY
  113. IMPORTED_CONFIGURATIONS DEBUG)
  114. set_target_properties(XercesC::XercesC PROPERTIES
  115. IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "CXX"
  116. IMPORTED_LOCATION_DEBUG "${XercesC_LIBRARY_DEBUG}")
  117. endif()
  118. endif()
  119. endif()