FindXercesC.cmake 5.2 KB

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