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