Blame SOURCES/cmake-FindPostgreSQL.patch

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