1 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
4 #[=======================================================================[.rst:
10 Find the Apache Xerces-C++ validating XML parser headers and libraries.
17 This module defines the following :prop_tgt:`IMPORTED` targets:
20 The Xerces-C++ ``xerces-c`` library, if found.
25 This module will set the following variables in your project:
28 true if the Xerces headers and libraries were found
30 Xerces release version
31 ``XercesC_INCLUDE_DIRS``
32 the directory containing the Xerces headers
34 Xerces libraries to be linked
39 The following cache variables may also be set:
41 ``XercesC_INCLUDE_DIR``
42 the directory containing the Xerces headers
47 Debug and Release variants are found separately.
48 #]=======================================================================]
51 cmake_policy(SET CMP0159 NEW) # file(STRINGS) with REGEX updates CMAKE_MATCH_<n>
53 # Written by Roger Leigh <rleigh@codelibre.net>
55 function(_XercesC_GET_VERSION version_hdr)
56 file(STRINGS ${version_hdr} _contents REGEX "^[ \t]*#define XERCES_VERSION_.*")
58 string(REGEX REPLACE ".*#define XERCES_VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" XercesC_MAJOR "${_contents}")
59 string(REGEX REPLACE ".*#define XERCES_VERSION_MINOR[ \t]+([0-9]+).*" "\\1" XercesC_MINOR "${_contents}")
60 string(REGEX REPLACE ".*#define XERCES_VERSION_REVISION[ \t]+([0-9]+).*" "\\1" XercesC_PATCH "${_contents}")
62 if(NOT XercesC_MAJOR MATCHES "^[0-9]+$")
63 message(FATAL_ERROR "Version parsing failed for XERCES_VERSION_MAJOR!")
65 if(NOT XercesC_MINOR MATCHES "^[0-9]+$")
66 message(FATAL_ERROR "Version parsing failed for XERCES_VERSION_MINOR!")
68 if(NOT XercesC_PATCH MATCHES "^[0-9]+$")
69 message(FATAL_ERROR "Version parsing failed for XERCES_VERSION_REVISION!")
72 set(XercesC_VERSION "${XercesC_MAJOR}.${XercesC_MINOR}.${XercesC_PATCH}" PARENT_SCOPE)
73 set(XercesC_VERSION_MAJOR "${XercesC_MAJOR}" PARENT_SCOPE)
74 set(XercesC_VERSION_MINOR "${XercesC_MINOR}" PARENT_SCOPE)
75 set(XercesC_VERSION_PATCH "${XercesC_PATCH}" PARENT_SCOPE)
77 message(FATAL_ERROR "Include file ${version_hdr} does not exist or does not contain expected version information")
81 # Find include directory
82 find_path(XercesC_INCLUDE_DIR
83 NAMES "xercesc/util/PlatformUtils.hpp"
84 DOC "Xerces-C++ include directory")
85 mark_as_advanced(XercesC_INCLUDE_DIR)
87 if(XercesC_INCLUDE_DIR AND EXISTS "${XercesC_INCLUDE_DIR}/xercesc/util/XercesVersion.hpp")
88 _XercesC_GET_VERSION("${XercesC_INCLUDE_DIR}/xercesc/util/XercesVersion.hpp")
91 if(NOT XercesC_LIBRARY)
92 # Find all XercesC libraries
93 find_library(XercesC_LIBRARY_RELEASE
95 "xerces-c_${XercesC_VERSION_MAJOR}"
96 "xerces-c-${XercesC_VERSION_MAJOR}.${XercesC_VERSION_MINOR}"
98 DOC "Xerces-C++ libraries (release)")
99 find_library(XercesC_LIBRARY_DEBUG
101 "xerces-c_${XercesC_VERSION_MAJOR}D"
102 "xerces-c_${XercesC_VERSION_MAJOR}_${XercesC_VERSION_MINOR}D"
104 DOC "Xerces-C++ libraries (debug)")
105 include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
106 select_library_configurations(XercesC)
107 mark_as_advanced(XercesC_LIBRARY_RELEASE XercesC_LIBRARY_DEBUG)
110 unset(XercesC_VERSION_MAJOR)
111 unset(XercesC_VERSION_MINOR)
112 unset(XercesC_VERSION_PATCH)
114 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
115 FIND_PACKAGE_HANDLE_STANDARD_ARGS(XercesC
116 FOUND_VAR XercesC_FOUND
117 REQUIRED_VARS XercesC_LIBRARY
120 VERSION_VAR XercesC_VERSION
121 FAIL_MESSAGE "Failed to find XercesC")
124 set(XercesC_INCLUDE_DIRS "${XercesC_INCLUDE_DIR}")
125 set(XercesC_LIBRARIES "${XercesC_LIBRARY}")
127 # For header-only libraries
128 if(NOT TARGET XercesC::XercesC)
129 add_library(XercesC::XercesC UNKNOWN IMPORTED)
130 if(XercesC_INCLUDE_DIRS)
131 set_target_properties(XercesC::XercesC PROPERTIES
132 INTERFACE_INCLUDE_DIRECTORIES "${XercesC_INCLUDE_DIRS}")
134 if(EXISTS "${XercesC_LIBRARY}")
135 set_target_properties(XercesC::XercesC PROPERTIES
136 IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
137 IMPORTED_LOCATION "${XercesC_LIBRARY}")
139 if(EXISTS "${XercesC_LIBRARY_RELEASE}")
140 set_property(TARGET XercesC::XercesC APPEND PROPERTY
141 IMPORTED_CONFIGURATIONS RELEASE)
142 set_target_properties(XercesC::XercesC PROPERTIES
143 IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "CXX"
144 IMPORTED_LOCATION_RELEASE "${XercesC_LIBRARY_RELEASE}")
146 if(EXISTS "${XercesC_LIBRARY_DEBUG}")
147 set_property(TARGET XercesC::XercesC APPEND PROPERTY
148 IMPORTED_CONFIGURATIONS DEBUG)
149 set_target_properties(XercesC::XercesC PROPERTIES
150 IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "CXX"
151 IMPORTED_LOCATION_DEBUG "${XercesC_LIBRARY_DEBUG}")