On Sun, Aug 17, 2014 at 02:57:36PM +0200, Rolf Eike Beer wrote:
> Roger Leigh wrote:
> > Dear Chuck,
> > 
> > Thanks for looking at this.  Please find attached a new copy of the
> > patch which should address all your points.  If you would like any
> > further changes making, please just let me know.
> 
> I don't think you need the functions for anything, especially not 
> _Xerces_FIND. From what I can tell they only serve the purpose of not leaking 
> variables. The only thin protected in _Xerces_FIND are the version 
> components, 
> that could easily be fixed by just returning the concatenated version string 
> from the inner function. What I would find more useful is actually checking 
> that Xerces_INCLUDE_DIR is set before calling _Xerces_GET_VERSION(), 
> otherwise 
> you would try to open "/xercesc/util/XercesVersion.hpp", which is definitely 
> wrong.

You're right about the function, it was to prevent leaking variables, but
this isn't an issue any longer so I've removed it as suggested.  I've
attached a new version; the docs for find_package said it was OK to set
package_VERSION_(MAJOR|MINOR|PATCH) so I've kept these in.  I've also
wrapped the _Xerces_GET_VERSION() call with a check that the include dir is
valid.


Thanks,
Roger

-- 
  .''`.  Roger Leigh
 : :' :  Debian GNU/Linux    http://people.debian.org/~rleigh/
 `. `'   schroot and sbuild  http://alioth.debian.org/projects/buildd-tools
   `-    GPG Public Key      F33D 281D 470A B443 6756 147C 07B3 C8BC 4083 E800
>From 5e863ec6f184d10dd1a2178034602945f56ff253 Mon Sep 17 00:00:00 2001
From: Roger Leigh <rle...@codelibre.net>
Date: Sun, 17 Aug 2014 12:58:16 +0100
Subject: [PATCH] FindXerces: New module to find Apache Xerces-C++

---
 Help/manual/cmake-modules.7.rst |  1 +
 Help/module/FindXerces.rst      |  1 +
 Modules/FindXerces.cmake        | 98 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 100 insertions(+)
 create mode 100644 Help/module/FindXerces.rst
 create mode 100644 Modules/FindXerces.cmake

diff --git a/Help/manual/cmake-modules.7.rst b/Help/manual/cmake-modules.7.rst
index 91fffe9..d7a3288 100644
--- a/Help/manual/cmake-modules.7.rst
+++ b/Help/manual/cmake-modules.7.rst
@@ -206,6 +206,7 @@ All Modules
    /module/FindWish
    /module/FindwxWidgets
    /module/FindwxWindows
+   /module/FindXerces
    /module/FindX11
    /module/FindXMLRPC
    /module/FindZLIB
diff --git a/Help/module/FindXerces.rst b/Help/module/FindXerces.rst
new file mode 100644
index 0000000..166d8dd
--- /dev/null
+++ b/Help/module/FindXerces.rst
@@ -0,0 +1 @@
+.. cmake-module:: ../../Modules/FindXerces.cmake
diff --git a/Modules/FindXerces.cmake b/Modules/FindXerces.cmake
new file mode 100644
index 0000000..c80e1d8
--- /dev/null
+++ b/Modules/FindXerces.cmake
@@ -0,0 +1,98 @@
+#.rst:
+# FindXerces
+# -------
+#
+# Find the Apache Xerces-C++ validating XML parser headers and libraries.
+#
+# Use this module by invoking find_package with the form::
+#
+#   find_package(Xerces
+#     [version] [EXACT]       # Minimum or EXACT version e.g. 3.1.1
+#     [REQUIRED])             # Fail with error if Xerces is not found
+#
+# This module reports information about the Xerces installation in
+# several variables.  General variables::
+#
+#   Xerces_FOUND - true if the Xerces headers and libraries were found
+#   Xerces_VERSION - Xerces release version
+#   Xerces_MAJOR_VERSION - Xerces major version number
+#   Xerces_MINOR_VERSION - Xerces minor version number
+#   Xerces_PATCH_VERSION - Xerces patch (release) version number
+#   Xerces_INCLUDE_DIRS - the directory containing the Xerces headers
+#   Xerces_LIBRARIES - Xerces libraries to be linked
+#
+# The following cache variables may also be set::
+#
+#   Xerces_INCLUDE_DIR - the directory containing the Xerces headers
+#   Xerces_LIBRARY - the Xerces library
+
+# Written by Roger Leigh <rle...@codelibre.net>
+
+#=============================================================================
+# Copyright 2014 University of Dundee
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+#  License text for the above reference.)
+
+# Derived from FindGTK2 _GTK2_GET_VERSION, modified for Xerces.
+function(_Xerces_GET_VERSION _OUT_major _OUT_minor _OUT_revision _xercesversion_hdr)
+    file(STRINGS ${_xercesversion_hdr} _contents REGEX "^[ \t]*#define XERCES_VERSION_.*")
+    if(_contents)
+        string(REGEX REPLACE ".*#define XERCES_VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" ${_OUT_major} "${_contents}")
+        string(REGEX REPLACE ".*#define XERCES_VERSION_MINOR[ \t]+([0-9]+).*" "\\1" ${_OUT_minor} "${_contents}")
+        string(REGEX REPLACE ".*#define XERCES_VERSION_REVISION[ \t]+([0-9]+).*" "\\1" ${_OUT_revision} "${_contents}")
+
+        if(NOT ${_OUT_major} MATCHES "^[0-9]+$")
+            message(FATAL_ERROR "Version parsing failed for XERCES_VERSION_MAJOR!")
+        endif()
+        if(NOT ${_OUT_minor} MATCHES "^[0-9]+$")
+            message(FATAL_ERROR "Version parsing failed for XERCES_VERSION_MINOR!")
+        endif()
+        if(NOT ${_OUT_revision} MATCHES "^[0-9]+$")
+            message(FATAL_ERROR "Version parsing failed for XERCES_VERSION_REVISION!")
+        endif()
+
+        set("${_OUT_major}" "${${_OUT_major}}" PARENT_SCOPE)
+        set("${_OUT_minor}" "${${_OUT_minor}}" PARENT_SCOPE)
+        set("${_OUT_revision}" "${${_OUT_revision}}" PARENT_SCOPE)
+    else()
+        message(FATAL_ERROR "Include file ${_xercesversion_hdr} does not exist or does not contain expected version information")
+    endif()
+endfunction(_Xerces_GET_VERSION)
+
+# Find include directory
+find_path(Xerces_INCLUDE_DIR
+          NAMES "xercesc/util/PlatformUtils.hpp"
+          DOC "Xerces-C++ include directory")
+mark_as_advanced(Xerces_INCLUDE_DIR)
+
+# Find all Xerces libraries
+find_library(Xerces_LIBRARY "xerces-c"
+  DOC "Xerces-C++ libraries")
+mark_as_advanced(Xerces_LIBRARY)
+
+if(Xerces_INCLUDE_DIR)
+  _Xerces_GET_VERSION(Xerces_VERSION_MAJOR Xerces_VERSION_MINOR Xerces_VERSION_PATCH "${Xerces_INCLUDE_DIR}/xercesc/util/XercesVersion.hpp")
+  set(Xerces_VERSION "${Xerces_VERSION_MAJOR}.${Xerces_VERSION_MINOR}.${Xerces_VERSION_PATCH}")
+endif(Xerces_INCLUDE_DIR)
+
+include(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Xerces
+                                  FOUND_VAR Xerces_FOUND
+                                  REQUIRED_VARS Xerces_LIBRARY
+                                                Xerces_INCLUDE_DIR
+                                                Xerces_VERSION
+                                  VERSION_VAR Xerces_VERSION
+                                  FAIL_MESSAGE "Failed to find Xerces")
+
+if(Xerces_FOUND)
+  set(Xerces_INCLUDE_DIRS "${Xerces_INCLUDE_DIR}")
+  set(Xerces_LIBRARIES "${Xerces_LIBRARY}")
+endif(Xerces_FOUND)
-- 
2.1.0

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers

Reply via email to