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