145919
diff -up cmake-2.8.10-rc3/Modules/FindPostgreSQL.cmake.findpostgresql cmake-2.8.10-rc3/Modules/FindPostgreSQL.cmake
145919
--- cmake-2.8.10-rc3/Modules/FindPostgreSQL.cmake.findpostgresql	2012-10-24 11:12:01.000000000 -0600
145919
+++ cmake-2.8.10-rc3/Modules/FindPostgreSQL.cmake	2012-10-24 19:49:54.189433358 -0600
145919
@@ -92,77 +92,99 @@ set( PostgreSQL_ROOT_DIRECTORIES
145919
 #
145919
 # Look for an installation.
145919
 #
145919
-find_path(PostgreSQL_INCLUDE_DIR
145919
-  NAMES libpq-fe.h
145919
+find_path(PostgreSQL_CONFIG_DIR
145919
+  NAMES pg_config
145919
   PATHS
145919
    # Look in other places.
145919
    ${PostgreSQL_ROOT_DIRECTORIES}
145919
   PATH_SUFFIXES
145919
-    pgsql
145919
-    postgresql
145919
-    include
145919
+    ""
145919
+    bin
145919
   # Help the user find it if we cannot.
145919
-  DOC "The ${PostgreSQL_INCLUDE_DIR_MESSAGE}"
145919
+  DOC "The ${PostgreSQL_ROOT_DIR_MESSAGE}"
145919
 )
145919
 
145919
-find_path(PostgreSQL_TYPE_INCLUDE_DIR
145919
-  NAMES catalog/pg_type.h
145919
-  PATHS
145919
-   # Look in other places.
145919
-   ${PostgreSQL_ROOT_DIRECTORIES}
145919
-  PATH_SUFFIXES
145919
-    postgresql
145919
-    pgsql/server
145919
-    postgresql/server
145919
-    include/server
145919
-  # Help the user find it if we cannot.
145919
-  DOC "The ${PostgreSQL_INCLUDE_DIR_MESSAGE}"
145919
-)
145919
-
145919
-# The PostgreSQL library.
145919
-set (PostgreSQL_LIBRARY_TO_FIND pq)
145919
-# Setting some more prefixes for the library
145919
-set (PostgreSQL_LIB_PREFIX "")
145919
-if ( WIN32 )
145919
-  set (PostgreSQL_LIB_PREFIX ${PostgreSQL_LIB_PREFIX} "lib")
145919
-  set ( PostgreSQL_LIBRARY_TO_FIND ${PostgreSQL_LIB_PREFIX}${PostgreSQL_LIBRARY_TO_FIND})
145919
-endif()
145919
+macro (fail_if)
145919
+  if (${ARGV})
145919
+    message (WARNING "Couldn't determine PostgreSQL configuration.")
145919
+    unset (PostgreSQL_CONFIG_DIR)
145919
+    break ()
145919
+  endif ()
145919
+endmacro ()
145919
+
145919
+macro (run_pg_config arg var)
145919
+  execute_process(COMMAND ${PostgreSQL_CONFIG_DIR}/pg_config ${arg}
145919
+                  RESULT_VARIABLE pgsql_config_result
145919
+                  OUTPUT_VARIABLE ${var}
145919
+                  OUTPUT_STRIP_TRAILING_WHITESPACE)
145919
+
145919
+  fail_if (NOT ${pgsql_config_result} EQUAL 0 OR NOT ${var})
145919
+endmacro ()
145919
+
145919
+foreach (once only)
145919
+  fail_if (NOT PostgreSQL_CONFIG_DIR)
145919
+
145919
+  run_pg_config (--version PostgreSQL_VERSION_STRING)
145919
+  string (REGEX REPLACE "^PostgreSQL (.*)$" "\\1"
145919
+          PostgreSQL_VERSION_STRING "${PostgreSQL_VERSION_STRING}")
145919
+  fail_if (NOT PostgreSQL_VERSION_STRING)
145919
+
145919
+  run_pg_config (--includedir PostgreSQL_INCLUDE_DIR)
145919
+  fail_if (NOT EXISTS "${PostgreSQL_INCLUDE_DIR}/libpq-fe.h")
145919
+
145919
+  find_path(PostgreSQL_TYPE_INCLUDE_DIR
145919
+    NAMES catalog/pg_type.h
145919
+    PATHS ${PostgreSQL_INCLUDE_DIR}
145919
+    PATH_SUFFIXES
145919
+      pgsql/server
145919
+      postgresql/server
145919
+      include/server
145919
+    # Help the user find it if we cannot.
145919
+    DOC "The ${PostgreSQL_INCLUDE_DIR_MESSAGE}"
145919
+  )
145919
+  fail_if (NOT PostgreSQL_TYPE_INCLUDE_DIR)
145919
+
145919
+  set (PostgreSQL_INCLUDE_DIRS
145919
+       ${PostgreSQL_INCLUDE_DIR} ${PostgreSQL_TYPE_INCLUDE_DIR})
145919
+
145919
+  run_pg_config (--libdir PostgreSQL_LIBRARY_DIRS)
145919
+
145919
+  # The PostgreSQL library.
145919
+  set (PostgreSQL_LIBRARY_TO_FIND pq)
145919
+  # Setting some more prefixes for the library
145919
+  set (PostgreSQL_LIB_PREFIX "")
145919
+  if (WIN32)
145919
+    set (PostgreSQL_LIB_PREFIX ${PostgreSQL_LIB_PREFIX} "lib")
145919
+    set (PostgreSQL_LIBRARY_TO_FIND ${PostgreSQL_LIB_PREFIX}${PostgreSQL_LIBRARY_TO_FIND})
145919
+  endif()
145919
+
145919
+  find_library (PostgreSQL_LIBRARY
145919
+    NAMES ${PostgreSQL_LIBRARY_TO_FIND}
145919
+    PATHS ${PostgreSQL_LIBRARY_DIRS}
145919
+    PATH_SUFFIXES lib
145919
+  )
145919
+  fail_if (NOT PostgreSQL_LIBRARY)
145919
+  set (PostgreSQL_LIBRARIES ${PostgreSQL_LIBRARY_TO_FIND})
145919
 
145919
-find_library( PostgreSQL_LIBRARY
145919
- NAMES ${PostgreSQL_LIBRARY_TO_FIND}
145919
- PATHS
145919
-   ${PostgreSQL_ROOT_DIRECTORIES}
145919
- PATH_SUFFIXES
145919
-   lib
145919
-)
145919
-get_filename_component(PostgreSQL_LIBRARY_DIR ${PostgreSQL_LIBRARY} PATH)
145919
-
145919
-if (PostgreSQL_INCLUDE_DIR AND EXISTS "${PostgreSQL_INCLUDE_DIR}/pg_config.h")
145919
-  file(STRINGS "${PostgreSQL_INCLUDE_DIR}/pg_config.h" pgsql_version_str
145919
-       REGEX "^#define[\t ]+PG_VERSION[\t ]+\".*\"")
145919
-
145919
-  string(REGEX REPLACE "^#define[\t ]+PG_VERSION[\t ]+\"([^\"]*)\".*" "\\1"
145919
-         PostgreSQL_VERSION_STRING "${pgsql_version_str}")
145919
-  unset(pgsql_version_str)
145919
-endif()
145919
+endforeach()
145919
 
145919
 # Did we find anything?
145919
-include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
145919
-find_package_handle_standard_args(PostgreSQL
145919
-                                  REQUIRED_VARS PostgreSQL_LIBRARY PostgreSQL_INCLUDE_DIR PostgreSQL_TYPE_INCLUDE_DIR
145919
-                                  VERSION_VAR PostgreSQL_VERSION_STRING)
145919
-set( PostgreSQL_FOUND  ${POSTGRESQL_FOUND})
145919
+include (FindPackageHandleStandardArgs)
145919
+find_package_handle_standard_args (PostgreSQL
145919
+  REQUIRED_VARS
145919
+    PostgreSQL_LIBRARY_DIRS
145919
+    PostgreSQL_CONFIG_DIR
145919
+    PostgreSQL_INCLUDE_DIRS
145919
+    PostgreSQL_LIBRARIES
145919
+  VERSION_VAR
145919
+    PostgreSQL_VERSION_STRING
145919
+)
145919
+set (PostgreSQL_FOUND ${POSTGRESQL_FOUND})
145919
 
145919
 # Now try to get the include and library path.
145919
-if(PostgreSQL_FOUND)
145919
-
145919
-  set(PostgreSQL_INCLUDE_DIRS ${PostgreSQL_INCLUDE_DIR} ${PostgreSQL_TYPE_INCLUDE_DIR} )
145919
-  set(PostgreSQL_LIBRARY_DIRS ${PostgreSQL_LIBRARY_DIR} )
145919
-  set(PostgreSQL_LIBRARIES ${PostgreSQL_LIBRARY_TO_FIND})
145919
-
145919
-  #message("Final PostgreSQL include dir: ${PostgreSQL_INCLUDE_DIRS}")
145919
-  #message("Final PostgreSQL library dir: ${PostgreSQL_LIBRARY_DIRS}")
145919
-  #message("Final PostgreSQL libraries:   ${PostgreSQL_LIBRARIES}")
145919
+if (PostgreSQL_FOUND)
145919
+  message (STATUS "PostgreSQL include dirs: ${PostgreSQL_INCLUDE_DIRS}")
145919
+  message (STATUS "PostgreSQL library dirs: ${PostgreSQL_LIBRARY_DIRS}")
145919
+  message (STATUS "PostgreSQL libraries:    ${PostgreSQL_LIBRARIES}")
145919
 endif()
145919
 
145919
-mark_as_advanced(PostgreSQL_INCLUDE_DIR PostgreSQL_TYPE_INCLUDE_DIR PostgreSQL_LIBRARY )