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