1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
#######################################################################
#
# FindPg.cmake - A CMake module for locating PostgreSQL
#
# Dave Page, EnterpriseDB UK Ltd.
# This code is released under the PostgreSQL Licence
#
#######################################################################
# To use this module, simply include it in your CMake project.
# If set, PostgreSQL will be assumed to be in the location specified
# by the PGDIR environment variable. Otherwise, it will be searched
# for in a number of standard locations.
#
# For statically linked builds, the PG_STATIC variable can be set to
# true.
#
# The following CMake variable will be set:
#
# PG_FOUND - Set to TRUE if PostgreSQL is located
# PG_CONFIG_PATH - The pg_config executable path
# PG_ROOT_DIR - The base install directory for PostgreSQL
# PG_INCLUDE_DIRS - The directory containing the PostgreSQL headers.
# PG_LIBRARIES - The PostgreSQL client libraries.
# PG_LIBRARY_DIRS - The directory containing the PostgreSQL client libraries.
# PG_PKG_LIBRARY_DIRS - The directory containing the PostgreSQL package libraries.
# PG_SHARE_DIR - The directory containing architecture-independent PostgreSQL support files.
# PG_VERSION_STRING - The PostgreSQL version number.
# PG_MAJOR_VERSION - The PostgreSQL major version (x in x.y.z).
# PG_MINOR_VERSION - The PostgreSQL minor version (y in x.y.z).
# PG_EXTENSION - Set to TRUE if PostgreSQL supports extensions.
IF(NOT PG_STATIC OR PG_STATIC STREQUAL "")
SET(_static "no")
ELSE(NOT PG_STATIC OR PG_STATIC STREQUAL "")
IF(PG_STATIC)
SET(_static "yes")
ELSE(PG_STATIC)
SET(_static "no")
ENDIF(PG_STATIC)
ENDIF(NOT PG_STATIC OR PG_STATIC STREQUAL "")
IF(NOT $ENV{PGDIR} STREQUAL "")
FIND_PROGRAM(PG_CONFIG_PATH pg_config
PATH $ENV{PGDIR}/bin
DOC "Path to the pg_config executable"
NO_DEFAULT_PATH)
ELSE(NOT $ENV{PGDIR} STREQUAL "")
FIND_PROGRAM(PG_CONFIG_PATH pg_config
PATH /usr/local/pgsql/bin
/opt/PostgreSQL/*/bin
/Library/PostgreSQL/*/bin
$ENV{ProgramFiles}/PostgreSQL/*/bin
$ENV{SystemDrive}/PostgreSQL/*/bin
DOC "Path to the pg_config executable")
ENDIF(NOT $ENV{PGDIR} STREQUAL "")
EXEC_PROGRAM(${PG_CONFIG_PATH} ARGS --version OUTPUT_VARIABLE PG_VERSION_STRING RETURN_VALUE _retval)
IF(NOT _retval)
SET(PG_FOUND TRUE)
# Strip the bin and pg_config from the path
GET_FILENAME_COMPONENT(PG_ROOT_DIR ${PG_CONFIG_PATH} PATH)
GET_FILENAME_COMPONENT(PG_ROOT_DIR ${PG_ROOT_DIR} PATH)
# Split the version into its component parts.
STRING(REGEX MATCHALL "[0-9]+" PG_VERSION_PARTS "${PG_VERSION_STRING}")
LIST(GET PG_VERSION_PARTS 0 PG_MAJOR_VERSION)
IF((PG_MAJOR_VERSION LESS 10))
LIST(GET PG_VERSION_PARTS 1 PG_MINOR_VERSION)
ENDIF((PG_MAJOR_VERSION LESS 10))
# Are extensions supported?
IF((PG_MAJOR_VERSION GREATER 9) OR ((PG_MAJOR_VERSION EQUAL 9) AND (PG_MINOR_VERSION GREATER 0)))
SET(PG_EXTENSION TRUE)
ENDIF((PG_MAJOR_VERSION GREATER 9) OR ((PG_MAJOR_VERSION EQUAL 9) AND (PG_MINOR_VERSION GREATER 0)))
IF(WIN32 AND NOT CYGWIN AND NOT MSYS)
SET(PG_INCLUDE_DIRS "${PG_ROOT_DIR}/include")
SET(PG_LIBRARY_DIRS "${PG_ROOT_DIR}/lib")
SET(PG_PKG_LIBRARY_DIRS "${PG_ROOT_DIR}/lib")
SET(PG_SHARE_DIR "${PG_ROOT_DIR}/share")
# There iare no static libraries on VC++ builds of PG.
LIST(APPEND PG_LIBRARIES libpq.lib)
ELSE(WIN32 AND NOT CYGWIN AND NOT MSYS)
EXEC_PROGRAM(${PG_CONFIG_PATH} ARGS --includedir OUTPUT_VARIABLE PG_INCLUDE_DIRS)
EXEC_PROGRAM(${PG_CONFIG_PATH} ARGS --libdir OUTPUT_VARIABLE PG_LIBRARY_DIRS)
EXEC_PROGRAM(${PG_CONFIG_PATH} ARGS --pkglibdir OUTPUT_VARIABLE PG_PKG_LIBRARY_DIRS)
EXEC_PROGRAM(${PG_CONFIG_PATH} ARGS --sharedir OUTPUT_VARIABLE PG_SHARE_DIR)
IF(_static)
LIST(APPEND PG_LIBRARIES ${PG_LIBRARY_DIRS}/libpq.a)
# Check for SSL and Kerberos
EXEC_PROGRAM("nm" ARGS ${PG_LIBRARY_DIRS}/libpq.a OUTPUT_VARIABLE _op)
IF(_op MATCHES "SSL_connect")
LIST(APPEND PG_LIBRARIES "ssl")
ENDIF(_op MATCHES "SSL_connect")
IF(_op MATCHES "krb5_free_principal")
LIST(APPEND PG_LIBRARIES "krb5")
ENDIF(_op MATCHES "krb5_free_principal")
IF(_op MATCHES "ldap_init")
LIST(APPEND PG_LIBRARIES "ldap")
ENDIF(_op MATCHES "ldap_init")
LIST(APPEND PG_LIBRARIES "crypto")
IF(NOT APPLE)
LIST(APPEND PG_LIBRARIES "crypt")
ENDIF(NOT APPLE)
ELSE(_static)
LIST(APPEND PG_LIBRARIES pq)
ENDIF(_static)
ENDIF(WIN32 AND NOT CYGWIN AND NOT MSYS)
ELSE(NOT _retval)
SET(PG_FOUND FALSE)
SET(PG_ROOT_DIR PG_ROOT_DIR-NO_FOUND)
IF(PG_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "No PostgreSQL installation could be found.")
ELSE(PG_FIND_REQUIRED)
MESSAGE(STATUS "No PostgreSQL installation could be found.")
ENDIF(PG_FIND_REQUIRED)
ENDIF(NOT _retval)
|