Index: cmake/Modules/CMakeUserUseBison.cmake
===================================================================
--- cmake/Modules/CMakeUserUseBison.cmake	(revision 304)
+++ cmake/Modules/CMakeUserUseBison.cmake	(revision 0)
@@ -26,5 +26,4 @@
    MESSAGE(STATUS "Looking for bison -- ${BISON_EXECUTABLE}")
  ENDIF(BISON_EXECUTABLE)
- MARK_AS_ADVANCED(BISON_EXECUTABLE)
 ENDIF(NOT BISON_EXECUTABLE)
 
Index: cmake/Modules/CMakeUserUseFlex.cmake
===================================================================
--- cmake/Modules/CMakeUserUseFlex.cmake	(revision 304)
+++ cmake/Modules/CMakeUserUseFlex.cmake	(revision 0)
@@ -16,5 +16,4 @@
     MESSAGE(STATUS "Looking for flex -- ${FLEX_EXECUTABLE}")
   ENDIF(FLEX_EXECUTABLE)
- MARK_AS_ADVANCED(FLEX_EXECUTABLE)
 ENDIF(NOT FLEX_EXECUTABLE) 
 
Index: cmake/Modules/FindGNUTLS.cmake
===================================================================
--- cmake/Modules/FindGNUTLS.cmake	(revision 0)
+++ cmake/Modules/FindGNUTLS.cmake	(revision 0)
@@ -0,0 +1,29 @@
+# - Try to find GNU TLS library and headers
+# Once done, this will define
+#
+#  GNUTLS_FOUND - system has GNU TLS
+#  GNUTLS_INCLUDE_DIRS - the GNU TLS include directories
+#  GNUTLS_LIBRARIES - link these to use GNU TLS
+
+include(LibFindMacros)
+
+# Use pkg-config to get hints about paths
+libfind_pkg_check_modules(GNUTLS_PKGCONF gnutls)
+
+# Include dir
+find_path(GNUTLS_INCLUDE_DIR
+  NAMES gnutls/gnutls.h
+  PATHS ${GNUTLS_PKGCONF_INCLUDE_DIRS}
+)
+
+# Finally the library itself
+find_library(GNUTLS_LIBRARY
+  NAMES gnutls
+  PATHS ${GNUTLS_PKGCONF_LIBRARY_DIRS}
+)
+
+# Set the include dir variables and the libraries and let libfind_process do the rest.
+# NOTE: Singular variables for this library, plural for libraries this this lib depends on.
+set(GNUTLS_PROCESS_INCLUDES GNUTLS_INCLUDE_DIR)
+set(GNUTLS_PROCESS_LIBS GNUTLS_LIBRARY)
+libfind_process(GNUTLS)
Index: cmake/Modules/FindGcrypt.cmake
===================================================================
--- cmake/Modules/FindGcrypt.cmake	(revision 823)
+++ 	(revision )
@@ -1,36 +1,0 @@
-# - Find gnutls
-# Find the native GCRYPT includes and library
-#
-#  GCRYPT_FOUND - True if gnutls found.
-#  GCRYPT_INCLUDE_DIR - where to find gnutls.h, etc.
-#  GCRYPT_LIBRARIES - List of libraries when using gnutls.
-
-if (GCRYPT_INCLUDE_DIR AND GCRYPT_LIBRARIES)
-  set(GCRYPT_FIND_QUIETLY TRUE)
-endif (GCRYPT_INCLUDE_DIR AND GCRYPT_LIBRARIES)
-
-# Include dir
-find_path(GCRYPT_INCLUDE_DIR
-	NAMES
-	  gcrypt.h
-)
-
-# Library
-find_library(GCRYPT_LIBRARY 
-  NAMES gcrypt
-)
-
-# handle the QUIETLY and REQUIRED arguments and set GCRYPT_FOUND to TRUE if 
-# all listed variables are TRUE
-INCLUDE(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(GCRYPT DEFAULT_MSG GCRYPT_LIBRARY GCRYPT_INCLUDE_DIR)
-
-IF(GCRYPT_FOUND)
-  SET( GCRYPT_LIBRARIES ${GCRYPT_LIBRARY} )
-ELSE(GCRYPT_FOUND)
-  SET( GCRYPT_LIBRARIES )
-ENDIF(GCRYPT_FOUND)
-
-# Lastly make it so that the GCRYPT_LIBRARY and GCRYPT_INCLUDE_DIR variables
-# only show up under the advanced options in the gui cmake applications.
-MARK_AS_ADVANCED( GCRYPT_LIBRARY GCRYPT_INCLUDE_DIR )
Index: cmake/Modules/FindGnuTLS.cmake
===================================================================
--- cmake/Modules/FindGnuTLS.cmake	(revision 1186)
+++ 	(revision )
@@ -1,64 +1,0 @@
-# - Find gnutls
-# Find the native GNUTLS includes and library
-#
-#  GNUTLS_FOUND - True if gnutls found.
-#  GNUTLS_INCLUDE_DIR - where to find gnutls.h, etc.
-#  GNUTLS_LIBRARIES - List of libraries when using gnutls.
-#  GNUTLS_VERSION_210 - true if GnuTLS version is >= 2.10.0 (does not require additional separate gcrypt initialization)
-#  GNUTLS_VERSION_212 - true if GnuTLS version is >= 2.12.0 (supports gnutls_transport_set_vec_push_function)
-#  GNUTLS_VERSION_300 - true if GnuTLS version is >= 3.00.0 (x509 verification functions changed)
-#  GNUTLS_VERSION_310 - true if GnuTLS version is >= 3.01.0 (stabilization branch with new APIs)
-
-if (GNUTLS_INCLUDE_DIR AND GNUTLS_LIBRARIES)
-  set(GNUTLS_FIND_QUIETLY TRUE)
-endif (GNUTLS_INCLUDE_DIR AND GNUTLS_LIBRARIES)
-
-# Include dir
-find_path(GNUTLS_INCLUDE_DIR
-	NAMES
-	  gnutls.h
-	  gnutls/gnutls.h
-)
-
-# Library
-find_library(GNUTLS_LIBRARY 
-  NAMES gnutls
-)
-
-# handle the QUIETLY and REQUIRED arguments and set GNUTLS_FOUND to TRUE if 
-# all listed variables are TRUE
-INCLUDE(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(GNUTLS DEFAULT_MSG GNUTLS_LIBRARY GNUTLS_INCLUDE_DIR)
-
-IF(GNUTLS_FOUND)
-  SET( GNUTLS_LIBRARIES ${GNUTLS_LIBRARY} )
-ELSE(GNUTLS_FOUND)
-  SET( GNUTLS_LIBRARIES )
-ENDIF(GNUTLS_FOUND)
-
-# Lastly make it so that the GNUTLS_LIBRARY and GNUTLS_INCLUDE_DIR variables
-# only show up under the advanced options in the gui cmake applications.
-MARK_AS_ADVANCED( GNUTLS_LIBRARY GNUTLS_INCLUDE_DIR )
-
-# Now check if the library is recent. gnutls_hash was added in 2.10.0.
-# Also test library is even more recent. gnutls_x509_trust_list_verify_crt was added in 3.00.0.
-IF(GNUTLS_FOUND)
-  IF( NOT( "${GNUTLS_VERSION_TEST_FOR}" STREQUAL "${GNUTLS_LIBRARY}" ))
-    INCLUDE (CheckLibraryExists) 
-    MESSAGE(STATUS "Checking GNUTLS version")
-    UNSET(GNUTLS_VERSION_210)
-    UNSET(GNUTLS_VERSION_210 CACHE)
-    UNSET(GNUTLS_VERSION_212)
-    UNSET(GNUTLS_VERSION_212 CACHE)
-    UNSET(GNUTLS_VERSION_300)
-    UNSET(GNUTLS_VERSION_300 CACHE)
-    UNSET(GNUTLS_VERSION_310)
-    UNSET(GNUTLS_VERSION_310 CACHE)
-    GET_FILENAME_COMPONENT(GNUTLS_PATH ${GNUTLS_LIBRARY} PATH)
-    CHECK_LIBRARY_EXISTS(gnutls gnutls_hash ${GNUTLS_PATH} GNUTLS_VERSION_210) 
-    CHECK_LIBRARY_EXISTS(gnutls gnutls_transport_set_vec_push_function ${GNUTLS_PATH} GNUTLS_VERSION_212) 
-    CHECK_LIBRARY_EXISTS(gnutls gnutls_x509_trust_list_verify_crt ${GNUTLS_PATH} GNUTLS_VERSION_300) 
-    CHECK_LIBRARY_EXISTS(gnutls gnutls_handshake_set_timeout ${GNUTLS_PATH} GNUTLS_VERSION_310) 
-    SET( GNUTLS_VERSION_TEST_FOR ${GNUTLS_LIBRARY} CACHE INTERNAL "Version the test was made against" )
-  ENDIF (NOT( "${GNUTLS_VERSION_TEST_FOR}" STREQUAL "${GNUTLS_LIBRARY}" ))
-ENDIF(GNUTLS_FOUND)
Index: cmake/Modules/FindLibXml2.cmake
===================================================================
--- cmake/Modules/FindLibXml2.cmake	(revision 766)
+++ 	(revision )
@@ -1,53 +1,0 @@
-# - Try to find the LibXml2 xml processing library
-# Once done this will define
-#
-#  LIBXML2_FOUND - System has LibXml2
-#  LIBXML2_INCLUDE_DIR - The LibXml2 include directory
-#  LIBXML2_LIBRARIES - The libraries needed to use LibXml2
-#  LIBXML2_DEFINITIONS - Compiler switches required for using LibXml2
-#  LIBXML2_XMLLINT_EXECUTABLE - The XML checking tool xmllint coming with LibXml2
-
-#=============================================================================
-# Copyright 2006-2009 Kitware, Inc.
-# Copyright 2006 Alexander Neundorf <neundorf@kde.org>
-#
-# 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 distributed this file outside of CMake, substitute the full
-#  License text for the above reference.)
-
-# use pkg-config to get the directories and then use these values
-# in the FIND_PATH() and FIND_LIBRARY() calls
-FIND_PACKAGE(PkgConfig)
-PKG_CHECK_MODULES(PC_LIBXML libxml-2.0)
-SET(LIBXML2_DEFINITIONS ${PC_LIBXML_CFLAGS_OTHER})
-
-FIND_PATH(LIBXML2_INCLUDE_DIR NAMES libxml/xpath.h
-   HINTS
-   ${PC_LIBXML_INCLUDEDIR}
-   ${PC_LIBXML_INCLUDE_DIRS}
-   PATH_SUFFIXES libxml2
-   )
-
-FIND_LIBRARY(LIBXML2_LIBRARIES NAMES xml2 libxml2
-   HINTS
-   ${PC_LIBXML_LIBDIR}
-   ${PC_LIBXML_LIBRARY_DIRS}
-   )
-
-FIND_PROGRAM(LIBXML2_XMLLINT_EXECUTABLE xmllint)
-# for backwards compat. with KDE 4.0.x:
-SET(XMLLINT_EXECUTABLE "${LIBXML2_XMLLINT_EXECUTABLE}")
-
-# handle the QUIETLY and REQUIRED arguments and set LIBXML2_FOUND to TRUE if 
-# all listed variables are TRUE
-INCLUDE(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibXml2 DEFAULT_MSG LIBXML2_LIBRARIES LIBXML2_INCLUDE_DIR)
-
-MARK_AS_ADVANCED(LIBXML2_INCLUDE_DIR LIBXML2_LIBRARIES LIBXML2_XMLLINT_EXECUTABLE)
-
Index: cmake/Modules/FindMySQL.cmake
===================================================================
--- cmake/Modules/FindMySQL.cmake	(revision 1312)
+++ 	(revision )
@@ -1,56 +1,0 @@
-# - Find mysqlclient
-#
-# -*- cmake -*-
-#
-# Find the native MySQL includes and library
-#
-#  MySQL_INCLUDE_DIR - where to find mysql.h, etc.
-#  MySQL_LIBRARIES   - List of libraries when using MySQL.
-#  MySQL_FOUND       - True if MySQL found.
-
-IF (MySQL_INCLUDE_DIR AND MySQL_LIBRARY)
-  # Already in cache, be silent
-  SET(MySQL_FIND_QUIETLY TRUE)
-ENDIF (MySQL_INCLUDE_DIR AND MySQL_LIBRARY)
-
-# Include dir
-FIND_PATH(MySQL_INCLUDE_DIR 
-  NAMES mysql.h
-  PATH_SUFFIXES mysql
-)
-
-# Library
-#SET(MySQL_NAMES mysqlclient mysqlclient_r)
-#SET(MySQL_NAMES mysqlclient_r)
-SET(MySQL_NAMES mysqlclient_r mysqlclient)
-FIND_LIBRARY(MySQL_LIBRARY
-  NAMES ${MySQL_NAMES}
-  PATHS /usr/lib /usr/local/lib
-  PATH_SUFFIXES mysql
-)
-
-IF (MySQL_INCLUDE_DIR AND MySQL_LIBRARY)
-  SET(MySQL_FOUND TRUE)
-  SET( MySQL_LIBRARIES ${MySQL_LIBRARY} )
-ELSE (MySQL_INCLUDE_DIR AND MySQL_LIBRARY)
-  SET(MySQL_FOUND FALSE)
-  SET( MySQL_LIBRARIES )
-ENDIF (MySQL_INCLUDE_DIR AND MySQL_LIBRARY)
-
-
-IF (MySQL_FOUND)
-  IF (NOT MySQL_FIND_QUIETLY)
-    MESSAGE(STATUS "Found MySQL: ${MySQL_LIBRARY}")
-  ENDIF (NOT MySQL_FIND_QUIETLY)
-ELSE (MySQL_FOUND)
-  IF (MySQL_FIND_REQUIRED)
-    MESSAGE(STATUS "Looked for MySQL libraries named ${MySQL_NAMES}.")
-    MESSAGE(FATAL_ERROR "Could NOT find MySQL library")
-  ENDIF (MySQL_FIND_REQUIRED)
-ENDIF (MySQL_FOUND)
-
-MARK_AS_ADVANCED(
-  MySQL_LIBRARY
-  MySQL_INCLUDE_DIR
-  )
-
Index: cmake/Modules/FindPostgreSQL.cmake
===================================================================
--- cmake/Modules/FindPostgreSQL.cmake	(revision 611)
+++ 	(revision )
@@ -1,36 +1,0 @@
-# - Find PostgreSQL library
-#
-# This module defines:
-#  POSTGRESQL_FOUND - True if the package is found
-#  POSTGRESQL_INCLUDE_DIR - containing libpq-fe.h
-#  POSTGRESQL_LIBRARIES - Libraries to link to use PQ functions.
-
-if (POSTGRESQL_INCLUDE_DIR AND POSTGRESQL_LIBRARIES)
-  set(POSTGRESQL_FIND_QUIETLY TRUE)
-endif (POSTGRESQL_INCLUDE_DIR AND POSTGRESQL_LIBRARIES)
-
-# Include dir
-find_path(POSTGRESQL_INCLUDE_DIR 
-	NAMES libpq-fe.h
-	PATH_SUFFIXES pgsql postgresql
-)
-
-# Library
-find_library(POSTGRESQL_LIBRARY 
-  NAMES pq
-)
-
-# handle the QUIETLY and REQUIRED arguments and set POSTGRESQL_FOUND to TRUE if 
-# all listed variables are TRUE
-INCLUDE(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(POSTGRESQL DEFAULT_MSG POSTGRESQL_LIBRARY POSTGRESQL_INCLUDE_DIR)
-
-IF(POSTGRESQL_FOUND)
-  SET( POSTGRESQL_LIBRARIES ${POSTGRESQL_LIBRARY} )
-ELSE(POSTGRESQL_FOUND)
-  SET( POSTGRESQL_LIBRARIES )
-ENDIF(POSTGRESQL_FOUND)
-
-# Lastly make it so that the POSTGRESQL_LIBRARY and POSTGRESQL_INCLUDE_DIR variables
-# only show up under the advanced options in the gui cmake applications.
-MARK_AS_ADVANCED( POSTGRESQL_LIBRARY POSTGRESQL_INCLUDE_DIR )
Index: cmake/Modules/FindSCTP.cmake
===================================================================
--- cmake/Modules/FindSCTP.cmake	(revision 493)
+++ cmake/Modules/FindSCTP.cmake	(revision 0)
@@ -3,44 +3,27 @@
 #
 #  SCTP_FOUND - system has SCTP
-#  SCTP_INCLUDE_DIR - the SCTP include directories
+#  SCTP_INCLUDE_DIRS - the SCTP include directories
 #  SCTP_LIBRARIES - link these to use SCTP
 
-if (SCTP_INCLUDE_DIR AND SCTP_LIBRARIES)
-  set(SCTP_FIND_QUIETLY TRUE)
-endif (SCTP_INCLUDE_DIR AND SCTP_LIBRARIES)
+include(LibFindMacros)
+
+# Use pkg-config to get hints about paths (Note: not yet supported?)
+# libfind_pkg_check_modules(SCTP_PKGCONF sctp)
 
 # Include dir
 find_path(SCTP_INCLUDE_DIR
   NAMES netinet/sctp.h
+  PATHS ${SCTP_PKGCONF_INCLUDE_DIRS}
 )
 
-# Library
+# Finally the library itself
 find_library(SCTP_LIBRARY
   NAMES sctp
+  PATHS ${SCTP_PKGCONF_LIBRARY_DIRS}
 )
 
 # Set the include dir variables and the libraries and let libfind_process do the rest.
 # NOTE: Singular variables for this library, plural for libraries this this lib depends on.
-#set(SCTP_PROCESS_INCLUDES SCTP_INCLUDE_DIR)
-#set(SCTP_PROCESS_LIBS SCTP_LIBRARY)
-#libfind_process(SCTP)
-
-
-# handle the QUIETLY and REQUIRED arguments and set SCTP_FOUND to TRUE if
-# all listed variables are TRUE
-INCLUDE(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(SCTP DEFAULT_MSG SCTP_LIBRARY SCTP_INCLUDE_DIR)
-
-# If we successfully found the sctp library then add the library to the
-# SCTP_LIBRARIES cmake variable otherwise set SCTP_LIBRARIES to nothing.
-IF(SCTP_FOUND)
-   SET( SCTP_LIBRARIES ${SCTP_LIBRARY} )
-ELSE(SCTP_FOUND)
-   SET( SCTP_LIBRARIES )
-ENDIF(SCTP_FOUND)
-
-
-# Lastly make it so that the SCTP_LIBRARY and SCTP_INCLUDE_DIR variables
-# only show up under the advanced options in the gui cmake applications.
-MARK_AS_ADVANCED( SCTP_LIBRARY SCTP_INCLUDE_DIR )
-
+set(SCTP_PROCESS_INCLUDES SCTP_INCLUDE_DIR)
+set(SCTP_PROCESS_LIBS SCTP_LIBRARY)
+libfind_process(SCTP)
Index: cmake/Modules/GetVersionWithHg.cmake
===================================================================
--- cmake/Modules/GetVersionWithHg.cmake	(revision 1170)
+++ 	(revision )
@@ -1,23 +1,0 @@
-# This file is called at build time. It regenerates the version.h file based on the hg version.
-
-EXECUTE_PROCESS(
-	COMMAND ${HGCOMMAND} id -i
-	WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
-	RESULT_VARIABLE reshash
-	OUTPUT_VARIABLE verhash
-	ERROR_QUIET
-	OUTPUT_STRIP_TRAILING_WHITESPACE)
-EXECUTE_PROCESS(
-	COMMAND ${HGCOMMAND} id -n
-	WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
-	RESULT_VARIABLE resval
-	OUTPUT_VARIABLE verval
-	ERROR_QUIET
-	OUTPUT_STRIP_TRAILING_WHITESPACE)
-	
-if (reshash EQUAL 0) 
-	SET(FD_PROJECT_VERSION_HG "${verval}(${verhash})")
- 	message(STATUS "Source version: ${FD_PROJECT_VERSION_HG}")
-endif (reshash EQUAL 0)
-
-CONFIGURE_FILE(${SRC} ${DST})
Index: cmake/Modules/LibFindMacros.cmake
===================================================================
--- cmake/Modules/LibFindMacros.cmake	(revision 0)
+++ cmake/Modules/LibFindMacros.cmake	(revision 0)
@@ -0,0 +1,99 @@
+# Works the same as find_package, but forwards the "REQUIRED" and "QUIET" arguments
+# used for the current package. For this to work, the first parameter must be the
+# prefix of the current package, then the prefix of the new package etc, which are
+# passed to find_package.
+macro (libfind_package PREFIX)
+  set (LIBFIND_PACKAGE_ARGS ${ARGN})
+  if (${PREFIX}_FIND_QUIETLY)
+    set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} QUIET)
+  endif (${PREFIX}_FIND_QUIETLY)
+  if (${PREFIX}_FIND_REQUIRED)
+    set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} REQUIRED)
+  endif (${PREFIX}_FIND_REQUIRED)
+  find_package(${LIBFIND_PACKAGE_ARGS})
+endmacro (libfind_package)
+
+# Damn CMake developers made the UsePkgConfig system deprecated in the same release (2.6)
+# where they added pkg_check_modules. Consequently I need to support both in my scripts
+# to avoid those deprecated warnings. Here's a helper that does just that.
+# Works identically to pkg_check_modules, except that no checks are needed prior to use.
+macro (libfind_pkg_check_modules PREFIX PKGNAME)
+  if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
+    include(UsePkgConfig)
+    pkgconfig(${PKGNAME} ${PREFIX}_INCLUDE_DIRS ${PREFIX}_LIBRARY_DIRS ${PREFIX}_LDFLAGS ${PREFIX}_CFLAGS)
+  else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
+    find_package(PkgConfig)
+    if (PKG_CONFIG_FOUND)
+      pkg_check_modules(${PREFIX} ${PKGNAME})
+    endif (PKG_CONFIG_FOUND)
+  endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
+endmacro (libfind_pkg_check_modules)
+
+# Do the final processing once the paths have been detected.
+# If include dirs are needed, ${PREFIX}_PROCESS_INCLUDES should be set to contain
+# all the variables, each of which contain one include directory.
+# Ditto for ${PREFIX}_PROCESS_LIBS and library files.
+# Will set ${PREFIX}_FOUND, ${PREFIX}_INCLUDE_DIRS and ${PREFIX}_LIBRARIES.
+# Also handles errors in case library detection was required, etc.
+macro (libfind_process PREFIX)
+  # Skip processing if already processed during this run
+  if (NOT ${PREFIX}_FOUND)
+    # Start with the assumption that the library was found
+    set (${PREFIX}_FOUND TRUE)
+
+    # Process all includes and set _FOUND to false if any are missing
+    foreach (i ${${PREFIX}_PROCESS_INCLUDES})
+      if (${i})
+        set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${i}})
+        mark_as_advanced(${i})
+      else (${i})
+        set (${PREFIX}_FOUND FALSE)
+      endif (${i})
+    endforeach (i)
+
+    # Process all libraries and set _FOUND to false if any are missing
+    foreach (i ${${PREFIX}_PROCESS_LIBS})
+      if (${i})
+        set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARIES} ${${i}})
+        mark_as_advanced(${i})
+      else (${i})
+        set (${PREFIX}_FOUND FALSE)
+      endif (${i})
+    endforeach (i)
+
+    # Print message and/or exit on fatal error
+    if (${PREFIX}_FOUND)
+      if (NOT ${PREFIX}_FIND_QUIETLY)
+        message (STATUS "Found ${PREFIX} ${${PREFIX}_VERSION}")
+      endif (NOT ${PREFIX}_FIND_QUIETLY)
+    else (${PREFIX}_FOUND)
+      if (${PREFIX}_FIND_REQUIRED)
+        foreach (i ${${PREFIX}_PROCESS_INCLUDES} ${${PREFIX}_PROCESS_LIBS})
+          message("${i}=${${i}}")
+        endforeach (i)
+        message (FATAL_ERROR "Required library ${PREFIX} NOT FOUND.\nInstall the library (dev version) and try again. If the library is already installed, use ccmake to set the missing variables manually.")
+      endif (${PREFIX}_FIND_REQUIRED)
+    endif (${PREFIX}_FOUND)
+  endif (NOT ${PREFIX}_FOUND)
+endmacro (libfind_process)
+
+macro(libfind_library PREFIX basename)
+  set(TMP "")
+  if(MSVC80)
+    set(TMP -vc80)
+  endif(MSVC80)
+  if(MSVC90)
+    set(TMP -vc90)
+  endif(MSVC90)
+  set(${PREFIX}_LIBNAMES ${basename}${TMP})
+  if(${ARGC} GREATER 2)
+    set(${PREFIX}_LIBNAMES ${basename}${TMP}-${ARGV2})
+    string(REGEX REPLACE "\\." "_" TMP ${${PREFIX}_LIBNAMES})
+    set(${PREFIX}_LIBNAMES ${${PREFIX}_LIBNAMES} ${TMP})
+  endif(${ARGC} GREATER 2)
+  find_library(${PREFIX}_LIBRARY
+    NAMES ${${PREFIX}_LIBNAMES}
+    PATHS ${${PREFIX}_PKGCONF_LIBRARY_DIRS}
+  )
+endmacro(libfind_library)
+
