1# Distributed under the OSI-approved BSD 3-Clause License. See accompanying 2# file Copyright.txt or https://cmake.org/licensing for details. 3 4#[=======================================================================[.rst: 5FindXercesC 6----------- 7 8.. versionadded:: 3.1 9 10Find the Apache Xerces-C++ validating XML parser headers and libraries. 11 12Imported targets 13^^^^^^^^^^^^^^^^ 14 15.. versionadded:: 3.5 16 17This module defines the following :prop_tgt:`IMPORTED` targets: 18 19``XercesC::XercesC`` 20 The Xerces-C++ ``xerces-c`` library, if found. 21 22Result variables 23^^^^^^^^^^^^^^^^ 24 25This module will set the following variables in your project: 26 27``XercesC_FOUND`` 28 true if the Xerces headers and libraries were found 29``XercesC_VERSION`` 30 Xerces release version 31``XercesC_INCLUDE_DIRS`` 32 the directory containing the Xerces headers 33``XercesC_LIBRARIES`` 34 Xerces libraries to be linked 35 36Cache variables 37^^^^^^^^^^^^^^^ 38 39The following cache variables may also be set: 40 41``XercesC_INCLUDE_DIR`` 42 the directory containing the Xerces headers 43``XercesC_LIBRARY`` 44 the Xerces library 45 46.. versionadded:: 3.4 47 Debug and Release variants are found separately. 48#]=======================================================================] 49 50# Written by Roger Leigh <[email protected]> 51 52function(_XercesC_GET_VERSION version_hdr) 53 file(STRINGS ${version_hdr} _contents REGEX "^[ \t]*#define XERCES_VERSION_.*") 54 if(_contents) 55 string(REGEX REPLACE ".*#define XERCES_VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" XercesC_MAJOR "${_contents}") 56 string(REGEX REPLACE ".*#define XERCES_VERSION_MINOR[ \t]+([0-9]+).*" "\\1" XercesC_MINOR "${_contents}") 57 string(REGEX REPLACE ".*#define XERCES_VERSION_REVISION[ \t]+([0-9]+).*" "\\1" XercesC_PATCH "${_contents}") 58 59 if(NOT XercesC_MAJOR MATCHES "^[0-9]+$") 60 message(FATAL_ERROR "Version parsing failed for XERCES_VERSION_MAJOR!") 61 endif() 62 if(NOT XercesC_MINOR MATCHES "^[0-9]+$") 63 message(FATAL_ERROR "Version parsing failed for XERCES_VERSION_MINOR!") 64 endif() 65 if(NOT XercesC_PATCH MATCHES "^[0-9]+$") 66 message(FATAL_ERROR "Version parsing failed for XERCES_VERSION_REVISION!") 67 endif() 68 69 set(XercesC_VERSION "${XercesC_MAJOR}.${XercesC_MINOR}.${XercesC_PATCH}" PARENT_SCOPE) 70 set(XercesC_VERSION_MAJOR "${XercesC_MAJOR}" PARENT_SCOPE) 71 set(XercesC_VERSION_MINOR "${XercesC_MINOR}" PARENT_SCOPE) 72 set(XercesC_VERSION_PATCH "${XercesC_PATCH}" PARENT_SCOPE) 73 else() 74 message(FATAL_ERROR "Include file ${version_hdr} does not exist or does not contain expected version information") 75 endif() 76endfunction() 77 78# Find include directory 79find_path(XercesC_INCLUDE_DIR 80 NAMES "xercesc/util/PlatformUtils.hpp" 81 DOC "Xerces-C++ include directory") 82mark_as_advanced(XercesC_INCLUDE_DIR) 83 84if(XercesC_INCLUDE_DIR AND EXISTS "${XercesC_INCLUDE_DIR}/xercesc/util/XercesVersion.hpp") 85 _XercesC_GET_VERSION("${XercesC_INCLUDE_DIR}/xercesc/util/XercesVersion.hpp") 86endif() 87 88if(NOT XercesC_LIBRARY) 89 # Find all XercesC libraries 90 find_library(XercesC_LIBRARY_RELEASE 91 NAMES "xerces-c" 92 "xerces-c_${XercesC_VERSION_MAJOR}" 93 "xerces-c-${XercesC_VERSION_MAJOR}.${XercesC_VERSION_MINOR}" 94 DOC "Xerces-C++ libraries (release)") 95 find_library(XercesC_LIBRARY_DEBUG 96 NAMES "xerces-cd" 97 "xerces-c_${XercesC_VERSION_MAJOR}D" 98 "xerces-c_${XercesC_VERSION_MAJOR}_${XercesC_VERSION_MINOR}D" 99 DOC "Xerces-C++ libraries (debug)") 100 include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake) 101 select_library_configurations(XercesC) 102 mark_as_advanced(XercesC_LIBRARY_RELEASE XercesC_LIBRARY_DEBUG) 103endif() 104 105unset(XercesC_VERSION_MAJOR) 106unset(XercesC_VERSION_MINOR) 107unset(XercesC_VERSION_PATCH) 108 109include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) 110FIND_PACKAGE_HANDLE_STANDARD_ARGS(XercesC 111 FOUND_VAR XercesC_FOUND 112 REQUIRED_VARS XercesC_LIBRARY 113 XercesC_INCLUDE_DIR 114 XercesC_VERSION 115 VERSION_VAR XercesC_VERSION 116 FAIL_MESSAGE "Failed to find XercesC") 117 118if(XercesC_FOUND) 119 set(XercesC_INCLUDE_DIRS "${XercesC_INCLUDE_DIR}") 120 set(XercesC_LIBRARIES "${XercesC_LIBRARY}") 121 122 # For header-only libraries 123 if(NOT TARGET XercesC::XercesC) 124 add_library(XercesC::XercesC UNKNOWN IMPORTED) 125 if(XercesC_INCLUDE_DIRS) 126 set_target_properties(XercesC::XercesC PROPERTIES 127 INTERFACE_INCLUDE_DIRECTORIES "${XercesC_INCLUDE_DIRS}") 128 endif() 129 if(EXISTS "${XercesC_LIBRARY}") 130 set_target_properties(XercesC::XercesC PROPERTIES 131 IMPORTED_LINK_INTERFACE_LANGUAGES "CXX" 132 IMPORTED_LOCATION "${XercesC_LIBRARY}") 133 endif() 134 if(EXISTS "${XercesC_LIBRARY_RELEASE}") 135 set_property(TARGET XercesC::XercesC APPEND PROPERTY 136 IMPORTED_CONFIGURATIONS RELEASE) 137 set_target_properties(XercesC::XercesC PROPERTIES 138 IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "CXX" 139 IMPORTED_LOCATION_RELEASE "${XercesC_LIBRARY_RELEASE}") 140 endif() 141 if(EXISTS "${XercesC_LIBRARY_DEBUG}") 142 set_property(TARGET XercesC::XercesC APPEND PROPERTY 143 IMPORTED_CONFIGURATIONS DEBUG) 144 set_target_properties(XercesC::XercesC PROPERTIES 145 IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "CXX" 146 IMPORTED_LOCATION_DEBUG "${XercesC_LIBRARY_DEBUG}") 147 endif() 148 endif() 149endif() 150