Find (optional) Expat library for linking with static APR-Util.

* CMakeLists.txt: Add option EXPAT.
* build/APRCommon.cmake (_apru_version): Also return the minor version.
* build/FindAPR.cmake: Adjust call to _apru_version.
* build/FindAPRUtil.cmake: Try to find the Expat library appropriate to
   the discovered version of APR-Util.

git-svn-id: https://svn.apache.org/repos/asf/serf/trunk@1834663 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a971169..758a393 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -43,6 +43,7 @@
 option(DEBUG "Enable debugging info and strict compile warnings" OFF)
 option(DISABLE_LOGGING "Disable the logging framework at compile time" OFF)
 option(ENABLE_SLOW_TESTS "Enable long-running unit tests" OFF)
+option(EXPAT "Windows: optional path to Expat's install area for APR_STATIC" OFF)
 option(APR_STATIC "Windows: Link with static APR/-Util libraries" OFF)
 option(OPENSSL_STATIC "Windows: Link with static OpenSSL libraries" OFF)
 
@@ -143,6 +144,10 @@
   message(WARNING "option BROTLI is not implemented yet")
 endif()
 
+if(EXPAT)
+  set(PC_EXPAT_INCLUDE_DIRS "${EXPAT}/include")
+  set(PC_EXPAT_LIBRARY_DIRS "${EXPAT}/lib")
+endif()
 
 # Find dependencies
 find_package(OpenSSL)
diff --git a/build/APRCommon.cmake b/build/APRCommon.cmake
index ae7bf38..4dd7fc1 100644
--- a/build/APRCommon.cmake
+++ b/build/APRCommon.cmake
@@ -47,7 +47,7 @@
   endif()
 endfunction(_apru_config)
 
-function(_apru_version _version_varname _major_varname _header _prefix)
+function(_apru_version _version_varname _major_varname _minor_varname _header _prefix)
   file(STRINGS ${_header} _apru_major
        REGEX "^ *# *define +${_prefix}_MAJOR_VERSION +[0-9]+.*$")
   file(STRINGS ${_header} _apru_minor
@@ -59,6 +59,7 @@
   string(REGEX REPLACE "^[^0-9]+([0-9]+).*$" "\\1" _apru_patch ${_apru_patch})
   set(${_version_varname} "${_apru_major}.${_apru_minor}.${_apru_patch}" PARENT_SCOPE)
   set(${_major_varname} ${_apru_major} PARENT_SCOPE)
+  set(${_minor_varname} ${_apru_minor} PARENT_SCOPE)
 endfunction(_apru_version)
 
 function(_apru_find_dll _varname _dllname)
diff --git a/build/FindAPR.cmake b/build/FindAPR.cmake
index c37ed6c..66e513c 100644
--- a/build/FindAPR.cmake
+++ b/build/FindAPR.cmake
@@ -48,7 +48,7 @@
     message(FATAL_ERROR "apr_version.h was not found in ${APR_INCLUDES}")
   endif()
 
-  _apru_version(APR_VERSION _apr_major "${APR_INCLUDES}/apr_version.h" "APR")
+  _apru_version(APR_VERSION _apr_major _apr_minor "${APR_INCLUDES}/apr_version.h" "APR")
   set(_apr_name "apr-${_apr_major}")
 
   find_library(APR_LIBRARIES NAMES "lib${_apr_name}.lib"
diff --git a/build/FindAPRUtil.cmake b/build/FindAPRUtil.cmake
index 0431e8d..2be1a39 100644
--- a/build/FindAPRUtil.cmake
+++ b/build/FindAPRUtil.cmake
@@ -62,15 +62,36 @@
       message(FATAL_ERROR "apu_version.h was not found in ${APRUTIL_INCLUDES}")
     endif()
 
-    _apru_version(APRUTIL_VERSION _apu_major "${APRUTIL_INCLUDES}/apu_version.h" "APU")
+    _apru_version(APRUTIL_VERSION _apu_major _apu_minor "${APRUTIL_INCLUDES}/apu_version.h" "APU")
     set(_apu_name "aprutil-${_apu_major}")
+    
+    if(${_apu_major} GREATER 1 OR (${_apu_major} EQUAL 1 AND ${_apu_minor} GREATER 5))
+      set(_apu_expat_name "expat.lib")
+    else()
+      set(_apu_expat_name "xml.lib")
+    endif()
 
     find_library(APRUTIL_LIBRARIES NAMES "lib${_apu_name}.lib"
                  PATHS ${APRUTIL_ROOT} NO_DEFAULT_PATH PATH_SUFFIXES "lib")
-    find_library(APRUTIL_STATIC_LIBS NAMES "${_apu_name}.lib"
+    find_library(_apu_static NAMES "${_apu_name}.lib"
+                 PATHS ${APRUTIL_ROOT} NO_DEFAULT_PATH PATH_SUFFIXES "lib")
+    find_library(_apu_expat NAMES ${_apu_expat_name}
                  PATHS ${APRUTIL_ROOT} NO_DEFAULT_PATH PATH_SUFFIXES "lib")
     _apru_find_dll(APRUTIL_RUNTIME_LIBS "lib${_apu_name}.dll" ${APRUTIL_ROOT})
 
+    if(NOT _apu_expat AND (_apu_expat_name MATCHES "expat"))
+      find_package(EXPAT QUIET)
+      if(EXPAT_FOUND)
+        set(_apu_expat ${EXPAT_LIBRARIES})
+      endif()
+    endif()
+    if(NOT _apu_expat)
+      message(WARNING "Could not find ${_apu_expat_name}"
+                      " for APR-Util static linking.")
+    endif()
+    set(APRUTIL_STATIC_LIBS ${_apu_static} ${_apu_expat}
+        CACHE STRING "APR-Util static libraies.")
+
   else()    # NOT Windows
 
     if(DEFINED APRUTIL_ROOT)