Index: code/branches/buildsystem2/cmake/DetermineVersion.cmake
===================================================================
--- code/branches/buildsystem2/cmake/DetermineVersion.cmake	(revision 2612)
+++ code/branches/buildsystem2/cmake/DetermineVersion.cmake	(revision 2613)
@@ -17,7 +17,7 @@
 #    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 
-MACRO(DETERMINE_VERSION _name _file)
-  FILE(READ ${_file} _file_content)
-  IF(_file_content)
+FUNCTION(DETERMINE_VERSION _name _file)
+  IF(EXISTS ${_file})
+    FILE(READ ${_file} _file_content)
     SET(_parts ${ARGN})
     LIST(LENGTH _parts _parts_length)
@@ -29,16 +29,17 @@
       STRING(REGEX MATCH "${_name}_VERSION_${_part} +([0-9]+)" _match ${_file_content})
       IF(_match)
-        SET(${_name}_VERSION_${_part} ${CMAKE_MATCH_1} CACHE STRING "")
+        SET(${_name}_VERSION_${_part} ${CMAKE_MATCH_1})
+        SET(${_name}_VERSION_${_part} ${CMAKE_MATCH_1} PARENT_SCOPE)
       ELSE(_match)
-        SET(${_name}_VERSION_${_part} "0" CACHE STRING "")
+        SET(${_name}_VERSION_${_part} "0")
+        SET(${_name}_VERSION_${_part} "0" PARENT_SCOPE)
       ENDIF(_match)
-      MARK_AS_ADVANCED(${_name}_VERSION_${_part})
       IF("${_parts}" MATCHES "^${_part}") # First?
-        SET(${_name}_VERSION "${${_name}_VERSION_${_part}}" CACHE STRING "" FORCE)
+        SET(${_name}_VERSION "${${_name}_VERSION_${_part}}")
       ELSE("${_parts}" MATCHES "^${_part}")
-        SET(${_name}_VERSION "${${_name}_VERSION}.${${_name}_VERSION_${_part}}" CACHE STRING "" FORCE)
+        SET(${_name}_VERSION "${${_name}_VERSION}.${${_name}_VERSION_${_part}}")
       ENDIF("${_parts}" MATCHES "^${_part}")
     ENDFOREACH(_part)
-    MARK_AS_ADVANCED(${_name}_VERSION)
-  ENDIF(_file_content)
-ENDMACRO(DETERMINE_VERSION)
+    SET(${_name}_VERSION "${${_name}_VERSION}" PARENT_SCOPE)
+  ENDIF(EXISTS ${_file})
+ENDFUNCTION(DETERMINE_VERSION)
Index: code/branches/buildsystem2/cmake/FindPackageHandleAdvancedArgs.cmake
===================================================================
--- code/branches/buildsystem2/cmake/FindPackageHandleAdvancedArgs.cmake	(revision 2613)
+++ code/branches/buildsystem2/cmake/FindPackageHandleAdvancedArgs.cmake	(revision 2613)
@@ -0,0 +1,39 @@
+INCLUDE(FindPackageHandleStandardArgs)
+INCLUDE(CompareVersionStrings)
+
+FUNCTION(FIND_PACKAGE_HANDLE_ADVANCED_ARGS _name _fail_msg _version)
+
+  # Modify the message to include version requirements
+  IF("${_fail_msg}" STREQUAL "DEFAULT_MSG")
+    SET(_fail_msg_adv "Could NOT find ${_name}")
+  ELSE("${_fail_msg}" STREQUAL "DEFAULT_MSG")
+    SET(_fail_msg_adv "${_fail_msg}")
+  ENDIF("${_fail_msg}" STREQUAL "DEFAULT_MSG")
+  IF(${_name}_FIND_VERSION_EXACT)
+    SET(_fail_msg_adv "${_fail_msg_adv} (version requirements: exactly ${${_name}_FIND_VERSION}")
+  ELSE(${_name}_FIND_VERSION_EXACT)
+    SET(_fail_msg_adv "${_fail_msg_adv} (version requirements: at least ${${_name}_FIND_VERSION}")
+  ENDIF(${_name}_FIND_VERSION_EXACT)
+  FIND_PACKAGE_HANDLE_STANDARD_ARGS("${_name}" "${_fail_msg_adv}" ${ARGN})
+  STRING(TOUPPER ${_name} _NAME_UPPER)
+
+  # Also check version requirements if given to FindPackage(...)
+  IF(${_name}_FIND_VERSION)
+    # Note: the last argument of the function tells it to cut the first
+    #       version string instead of padding it with zeros if necessary
+    COMPARE_VERSION_STRINGS("${_version}" "${${_name}_FIND_VERSION}" _compatible TRUE)
+    IF(${_name}_FIND_VERSION_EXACT AND NOT _compatible EQUAL 0)
+      MESSAGE(FATAL_ERROR "Exact ${_name} version required is ${${_name}_FIND_VERSION}\n"
+                          "Your version is ${_version}")
+      SET(${_NAME_UPPER}_FOUND FALSE)
+    ELSEIF(_compatible LESS 0)
+      MESSAGE(FATAL_ERROR "Minimum ${_name} version required is ${${_name}_FIND_VERSION}\n"
+                          "Your version is ${_version}")
+      SET(${_NAME_UPPER}_FOUND FALSE)
+    ENDIF(${_name}_FIND_VERSION_EXACT AND NOT _compatible EQUAL 0)
+  ENDIF(${_name}_FIND_VERSION)
+
+  # Raise scope (FindPackageHandleStandardArgs uses PARENT_SCOPE)
+  SET(${_NAME_UPPER}_FOUND ${${_NAME_UPPER}_FOUND} PARENT_SCOPE)
+
+ENDFUNCTION(FIND_PACKAGE_HANDLE_ADVANCED_ARGS)
Index: code/branches/buildsystem2/cmake/HandleLibraryTypes.cmake
===================================================================
--- code/branches/buildsystem2/cmake/HandleLibraryTypes.cmake	(revision 2612)
+++ code/branches/buildsystem2/cmake/HandleLibraryTypes.cmake	(revision 2613)
@@ -26,19 +26,17 @@
  #
 
-MACRO(HandleLibraryTypes _name)
+FUNCTION(HANDLE_LIBRARY_TYPES _name)
   # Additional libraries can be added as additional arguments
-  IF(${_name}_FOUND)
-    IF(${_name}_LIBRARY_DEBUG)
-      SET(${_name}_LIBRARY
-          optimized ${${_name}_LIBRARY_OPTIMIZED} ${ARGN}
-          debug     ${${_name}_LIBRARY_DEBUG}     ${ARGN}
-          CACHE STRING "${_name} library file(s)" FORCE
-      )
-    ELSE(${_name}_LIBRARY_DEBUG)
-      SET(${_name}_LIBRARY
-          ${${_name}_LIBRARY_OPTIMIZED} ${ARGN}
-          CACHE STRING "${_name} library file(s)" FORCE
-      )
-    ENDIF(${_name}_LIBRARY_DEBUG)
-  ENDIF(${_name}_FOUND)
-ENDMACRO(HandleLibraryTypes)
+  IF(${_name}_LIBRARY_DEBUG AND ${_name}_LIBRARY_OPTIMIZED)
+    SET(${_name}_LIBRARY
+      optimized ${${_name}_LIBRARY_OPTIMIZED} ${ARGN}
+      debug     ${${_name}_LIBRARY_DEBUG}     ${ARGN}
+      PARENT_SCOPE
+    )
+  ELSE(${_name}_LIBRARY_DEBUG AND ${_name}_LIBRARY_OPTIMIZED)
+    SET(${_name}_LIBRARY
+      ${${_name}_LIBRARY_OPTIMIZED} ${ARGN}
+      PARENT_SCOPE
+     )
+  ENDIF(${_name}_LIBRARY_DEBUG AND ${_name}_LIBRARY_OPTIMIZED)
+ENDFUNCTION(HANDLE_LIBRARY_TYPES)
