FindXalanC.cmake 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. FindXalanC
  5. -----------
  6. Find the Apache Xalan-C++ XSL transform processor headers and libraries.
  7. Imported targets
  8. ^^^^^^^^^^^^^^^^
  9. This module defines the following :prop_tgt:`IMPORTED` targets:
  10. ``XalanC::XalanC``
  11. The Xalan-C++ ``xalan-c`` library, if found.
  12. Result variables
  13. ^^^^^^^^^^^^^^^^
  14. This module will set the following variables in your project:
  15. ``XalanC_FOUND``
  16. true if the Xalan headers and libraries were found
  17. ``XalanC_VERSION``
  18. Xalan release version
  19. ``XalanC_INCLUDE_DIRS``
  20. the directory containing the Xalan headers; note
  21. ``XercesC_INCLUDE_DIRS`` is also required
  22. ``XalanC_LIBRARIES``
  23. Xalan libraries to be linked; note ``XercesC_LIBRARIES`` is also
  24. required
  25. Cache variables
  26. ^^^^^^^^^^^^^^^
  27. The following cache variables may also be set:
  28. ``XalanC_INCLUDE_DIR``
  29. the directory containing the Xalan headers
  30. ``XalanC_LIBRARY``
  31. the Xalan library
  32. #]=======================================================================]
  33. # Written by Roger Leigh <rleigh@codelibre.net>
  34. function(_XalanC_GET_VERSION version_hdr)
  35. file(STRINGS ${version_hdr} _contents REGEX "^[ \t]*#define XALAN_VERSION_.*")
  36. if(_contents)
  37. string(REGEX REPLACE "[^*]*#define XALAN_VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" XalanC_MAJOR "${_contents}")
  38. string(REGEX REPLACE "[^*]*#define XALAN_VERSION_MINOR[ \t]+([0-9]+).*" "\\1" XalanC_MINOR "${_contents}")
  39. string(REGEX REPLACE "[^*]*#define XALAN_VERSION_REVISION[ \t]+([0-9]+).*" "\\1" XalanC_PATCH "${_contents}")
  40. if(NOT XalanC_MAJOR MATCHES "^[0-9]+$")
  41. message(FATAL_ERROR "Version parsing failed for XALAN_VERSION_MAJOR!")
  42. endif()
  43. if(NOT XalanC_MINOR MATCHES "^[0-9]+$")
  44. message(FATAL_ERROR "Version parsing failed for XALAN_VERSION_MINOR!")
  45. endif()
  46. if(NOT XalanC_PATCH MATCHES "^[0-9]+$")
  47. message(FATAL_ERROR "Version parsing failed for XALAN_VERSION_REVISION!")
  48. endif()
  49. set(XalanC_VERSION "${XalanC_MAJOR}.${XalanC_MINOR}.${XalanC_PATCH}" PARENT_SCOPE)
  50. set(XalanC_VERSION_MAJOR "${XalanC_MAJOR}" PARENT_SCOPE)
  51. set(XalanC_VERSION_MINOR "${XalanC_MINOR}" PARENT_SCOPE)
  52. set(XalanC_VERSION_PATCH "${XalanC_PATCH}" PARENT_SCOPE)
  53. else()
  54. message(FATAL_ERROR "Include file ${version_hdr} does not exist or does not contain expected version information")
  55. endif()
  56. endfunction()
  57. # Find include directory
  58. find_path(XalanC_INCLUDE_DIR
  59. NAMES "xalanc/XalanTransformer/XalanTransformer.hpp"
  60. DOC "Xalan-C++ include directory")
  61. mark_as_advanced(XalanC_INCLUDE_DIR)
  62. if(XalanC_INCLUDE_DIR AND EXISTS "${XalanC_INCLUDE_DIR}/xalanc/Include/XalanVersion.hpp")
  63. _XalanC_GET_VERSION("${XalanC_INCLUDE_DIR}/xalanc/Include/XalanVersion.hpp")
  64. endif()
  65. if(NOT XalanC_LIBRARY)
  66. # Find all XalanC libraries
  67. find_library(XalanC_LIBRARY_RELEASE
  68. NAMES "Xalan-C" "xalan-c"
  69. "Xalan-C_${XalanC_VERSION_MAJOR}"
  70. "Xalan-C_${XalanC_VERSION_MAJOR}_${XalanC_VERSION_MINOR}"
  71. DOC "Xalan-C++ libraries (release)")
  72. find_library(XalanC_LIBRARY_DEBUG
  73. NAMES "Xalan-CD" "xalan-cd"
  74. "Xalan-C_${XalanC_VERSION_MAJOR}D"
  75. "Xalan-C_${XalanC_VERSION_MAJOR}_${XalanC_VERSION_MINOR}D"
  76. DOC "Xalan-C++ libraries (debug)")
  77. include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
  78. select_library_configurations(XalanC)
  79. mark_as_advanced(XalanC_LIBRARY_RELEASE XalanC_LIBRARY_DEBUG)
  80. endif()
  81. unset(XalanC_VERSION_MAJOR)
  82. unset(XalanC_VERSION_MINOR)
  83. unset(XalanC_VERSION_PATCH)
  84. unset(XalanC_XERCESC_REQUIRED)
  85. if(XalanC_FIND_REQUIRED)
  86. set(XalanC_XERCESC_REQUIRED REQUIRED)
  87. endif()
  88. find_package(XercesC ${XalanC_XERCESC_REQUIRED})
  89. unset(XalanC_XERCESC_REQUIRED)
  90. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  91. FIND_PACKAGE_HANDLE_STANDARD_ARGS(XalanC
  92. FOUND_VAR XalanC_FOUND
  93. REQUIRED_VARS XalanC_LIBRARY
  94. XalanC_INCLUDE_DIR
  95. XalanC_VERSION
  96. XercesC_FOUND
  97. VERSION_VAR XalanC_VERSION
  98. FAIL_MESSAGE "Failed to find XalanC")
  99. if(XalanC_FOUND)
  100. set(XalanC_INCLUDE_DIRS "${XalanC_INCLUDE_DIR}" ${XercesC_INCLUDE_DIRS})
  101. set(XalanC_LIBRARIES "${XalanC_LIBRARY}" ${XercesC_LIBRARIES})
  102. # For header-only libraries
  103. if(NOT TARGET XalanC::XalanC)
  104. add_library(XalanC::XalanC UNKNOWN IMPORTED)
  105. if(XalanC_INCLUDE_DIRS)
  106. set_target_properties(XalanC::XalanC PROPERTIES
  107. INTERFACE_INCLUDE_DIRECTORIES "${XalanC_INCLUDE_DIRS}")
  108. endif()
  109. if(EXISTS "${XalanC_LIBRARY}")
  110. set_target_properties(XalanC::XalanC PROPERTIES
  111. IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
  112. IMPORTED_LOCATION "${XalanC_LIBRARY}")
  113. endif()
  114. if(EXISTS "${XalanC_LIBRARY_RELEASE}")
  115. set_property(TARGET XalanC::XalanC APPEND PROPERTY
  116. IMPORTED_CONFIGURATIONS RELEASE)
  117. set_target_properties(XalanC::XalanC PROPERTIES
  118. IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "CXX"
  119. IMPORTED_LOCATION_RELEASE "${XalanC_LIBRARY_RELEASE}")
  120. endif()
  121. if(EXISTS "${XalanC_LIBRARY_DEBUG}")
  122. set_property(TARGET XalanC::XalanC APPEND PROPERTY
  123. IMPORTED_CONFIGURATIONS DEBUG)
  124. set_target_properties(XalanC::XalanC PROPERTIES
  125. IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "CXX"
  126. IMPORTED_LOCATION_DEBUG "${XalanC_LIBRARY_DEBUG}")
  127. endif()
  128. set_target_properties(XalanC::XalanC PROPERTIES INTERFACE_LINK_LIBRARIES XercesC::XercesC)
  129. endif()
  130. endif()