|
| 1 | +# - Find the PostgreSQL installation. |
| 2 | +# In Windows, we make the assumption that, if the PostgreSQL files are installed, the default directory |
| 3 | +# will be C:\Program Files\PostgreSQL. |
| 4 | +# |
| 5 | +# This module defines |
| 6 | +# PostgreSQL_LIBRARIES - the PostgreSQL libraries needed for linking |
| 7 | +# PostgreSQL_INCLUDE_DIRS - the directories of the PostgreSQL headers |
| 8 | +# PostgreSQL_VERSION_STRING - the version of PostgreSQL found (since CMake 2.8.8) |
| 9 | + |
| 10 | +#============================================================================= |
| 11 | +# Copyright 2004-2009 Kitware, Inc. |
| 12 | +# |
| 13 | +# Distributed under the OSI-approved BSD License (the "License"); |
| 14 | +# see accompanying file Copyright.txt for details. |
| 15 | +# |
| 16 | +# This software is distributed WITHOUT ANY WARRANTY; without even the |
| 17 | +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 18 | +# See the License for more information. |
| 19 | +#============================================================================= |
| 20 | +# (To distribute this file outside of CMake, substitute the full |
| 21 | +# License text for the above reference.) |
| 22 | + |
| 23 | +# ---------------------------------------------------------------------------- |
| 24 | +# History: |
| 25 | +# This module is derived from the module originally found in the VTK source tree. |
| 26 | +# |
| 27 | +# ---------------------------------------------------------------------------- |
| 28 | +# Note: |
| 29 | +# PostgreSQL_ADDITIONAL_VERSIONS is a variable that can be used to set the |
| 30 | +# version mumber of the implementation of PostgreSQL. |
| 31 | +# In Windows the default installation of PostgreSQL uses that as part of the path. |
| 32 | +# E.g C:\Program Files\PostgreSQL\8.4. |
| 33 | +# Currently, the following version numbers are known to this module: |
| 34 | +# "9.1" "9.0" "8.4" "8.3" "8.2" "8.1" "8.0" |
| 35 | +# |
| 36 | +# To use this variable just do something like this: |
| 37 | +# set(PostgreSQL_ADDITIONAL_VERSIONS "9.2" "8.4.4") |
| 38 | +# before calling find_package(PostgreSQL) in your CMakeLists.txt file. |
| 39 | +# This will mean that the versions you set here will be found first in the order |
| 40 | +# specified before the default ones are searched. |
| 41 | +# |
| 42 | +# ---------------------------------------------------------------------------- |
| 43 | +# You may need to manually set: |
| 44 | +# PostgreSQL_INCLUDE_DIR - the path to where the PostgreSQL include files are. |
| 45 | +# PostgreSQL_LIBRARY_DIR - The path to where the PostgreSQL library files are. |
| 46 | +# If FindPostgreSQL.cmake cannot find the include files or the library files. |
| 47 | +# |
| 48 | +# ---------------------------------------------------------------------------- |
| 49 | +# The following variables are set if PostgreSQL is found: |
| 50 | +# PostgreSQL_FOUND - Set to true when PostgreSQL is found. |
| 51 | +# PostgreSQL_INCLUDE_DIRS - Include directories for PostgreSQL |
| 52 | +# PostgreSQL_LIBRARY_DIRS - Link directories for PostgreSQL libraries |
| 53 | +# PostgreSQL_LIBRARIES - The PostgreSQL libraries. |
| 54 | +# |
| 55 | +# ---------------------------------------------------------------------------- |
| 56 | +# If you have installed PostgreSQL in a non-standard location. |
| 57 | +# (Please note that in the following comments, it is assumed that <Your Path> |
| 58 | +# points to the root directory of the include directory of PostgreSQL.) |
| 59 | +# Then you have three options. |
| 60 | +# 1) After CMake runs, set PostgreSQL_INCLUDE_DIR to <Your Path>/include and |
| 61 | +# PostgreSQL_LIBRARY_DIR to wherever the library pq (or libpq in windows) is |
| 62 | +# 2) Use CMAKE_INCLUDE_PATH to set a path to <Your Path>/PostgreSQL<-version>. This will allow find_path() |
| 63 | +# to locate PostgreSQL_INCLUDE_DIR by utilizing the PATH_SUFFIXES option. e.g. In your CMakeLists.txt file |
| 64 | +# set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "<Your Path>/include") |
| 65 | +# 3) Set an environment variable called ${PostgreSQL_ROOT} that points to the root of where you have |
| 66 | +# installed PostgreSQL, e.g. <Your Path>. |
| 67 | +# |
| 68 | +# ---------------------------------------------------------------------------- |
| 69 | + |
| 70 | +set(PostgreSQL_INCLUDE_PATH_DESCRIPTION "top-level directory containing the PostgreSQL include directories. E.g /usr/local/include/PostgreSQL/8.4 or C:/Program Files/PostgreSQL/8.4/include") |
| 71 | +set(PostgreSQL_INCLUDE_DIR_MESSAGE "Set the PostgreSQL_INCLUDE_DIR cmake cache entry to the ${PostgreSQL_INCLUDE_PATH_DESCRIPTION}") |
| 72 | +set(PostgreSQL_LIBRARY_PATH_DESCRIPTION "top-level directory containing the PostgreSQL libraries.") |
| 73 | +set(PostgreSQL_LIBRARY_DIR_MESSAGE "Set the PostgreSQL_LIBRARY_DIR cmake cache entry to the ${PostgreSQL_LIBRARY_PATH_DESCRIPTION}") |
| 74 | +set(PostgreSQL_ROOT_DIR_MESSAGE "Set the PostgreSQL_ROOT system variable to where PostgreSQL is found on the machine E.g C:/Program Files/PostgreSQL/8.4") |
| 75 | + |
| 76 | + |
| 77 | +set(PostgreSQL_KNOWN_VERSIONS ${PostgreSQL_ADDITIONAL_VERSIONS} |
| 78 | + "9.1" "9.0" "8.4" "8.3" "8.2" "8.1" "8.0") |
| 79 | + |
| 80 | +# Define additional search paths for root directories. |
| 81 | +if ( WIN32 ) |
| 82 | + foreach (suffix ${PostgreSQL_KNOWN_VERSIONS} ) |
| 83 | + set(PostgreSQL_ADDITIONAL_SEARCH_PATHS ${PostgreSQL_ADDITIONAL_SEARCH_PATHS} "C:/Program Files/PostgreSQL/${suffix}" ) |
| 84 | + endforeach() |
| 85 | +endif() |
| 86 | +set( PostgreSQL_ROOT_DIRECTORIES |
| 87 | + ENV PostgreSQL_ROOT |
| 88 | + ${PostgreSQL_ROOT} |
| 89 | + ${PostgreSQL_ADDITIONAL_SEARCH_PATHS} |
| 90 | +) |
| 91 | + |
| 92 | +# |
| 93 | +# Look for an installation. |
| 94 | +# |
| 95 | +find_path(PostgreSQL_INCLUDE_DIR |
| 96 | + NAMES libpq-fe.h |
| 97 | + PATHS |
| 98 | + # Look in other places. |
| 99 | + ${PostgreSQL_ROOT_DIRECTORIES} |
| 100 | + PATH_SUFFIXES |
| 101 | + pgsql |
| 102 | + postgresql |
| 103 | + include |
| 104 | + # Help the user find it if we cannot. |
| 105 | + DOC "The ${PostgreSQL_INCLUDE_DIR_MESSAGE}" |
| 106 | +) |
| 107 | + |
| 108 | +# The PostgreSQL library. |
| 109 | +set (PostgreSQL_LIBRARY_TO_FIND pq) |
| 110 | +# Setting some more prefixes for the library |
| 111 | +set (PostgreSQL_LIB_PREFIX "") |
| 112 | +if ( FALSE AND WIN32 ) |
| 113 | + set (PostgreSQL_LIB_PREFIX ${PostgreSQL_LIB_PREFIX} "lib") |
| 114 | + set ( PostgreSQL_LIBRARY_TO_FIND ${PostgreSQL_LIB_PREFIX}${PostgreSQL_LIBRARY_TO_FIND}) |
| 115 | +endif() |
| 116 | + |
| 117 | +find_library( PostgreSQL_LIBRARY |
| 118 | + NAMES ${PostgreSQL_LIBRARY_TO_FIND} |
| 119 | + PATHS |
| 120 | + ${PostgreSQL_ROOT_DIRECTORIES} |
| 121 | + PATH_SUFFIXES |
| 122 | + lib |
| 123 | +) |
| 124 | +get_filename_component(PostgreSQL_LIBRARY_DIR ${PostgreSQL_LIBRARY} PATH) |
| 125 | + |
| 126 | +if ( MINGW ) |
| 127 | + |
| 128 | + find_library(SSL_LIBRARY |
| 129 | + NAMES ssl |
| 130 | + PATHS ${PostgreSQL_ROOT_DIRECTORIES} |
| 131 | + PATH_SUFFIXES lib) |
| 132 | + set(PostgreSQL_LIBRARY ${PostgreSQL_LIBRARY} ${SSL_LIBRARY}) |
| 133 | + |
| 134 | + find_library(CRYPTO_LIBRARY |
| 135 | + NAMES crypto |
| 136 | + PATHS ${PostgreSQL_ROOT_DIRECTORIES} |
| 137 | + PATH_SUFFIXES lib) |
| 138 | + set(PostgreSQL_LIBRARY ${PostgreSQL_LIBRARY} ${CRYPTO_LIBRARY}) |
| 139 | + |
| 140 | + find_library(ZLIB_LIBRARY |
| 141 | + NAMES z |
| 142 | + PATHS ${PostgreSQL_ROOT_DIRECTORIES} |
| 143 | + PATH_SUFFIXESlib) |
| 144 | + set(PostgreSQL_LIBRARY ${PostgreSQL_LIBRARY} ${ZLIB_LIBRARY}) |
| 145 | + |
| 146 | + find_library(WS2_32_LIBRARY |
| 147 | + NAMES ws2_32 |
| 148 | + PATHS ${PostgreSQL_ROOT_DIRECTORIES} |
| 149 | + PATH_SUFFIXES lib) |
| 150 | + set(PostgreSQL_LIBRARY ${PostgreSQL_LIBRARY} ${WS2_32_LIBRARY}) |
| 151 | + |
| 152 | + find_library(SECUR32_LIBRARY |
| 153 | + NAMES secur32 |
| 154 | + PATHS ${PostgreSQL_ROOT_DIRECTORIES} |
| 155 | + PATH_SUFFIXES lib) |
| 156 | + set(PostgreSQL_LIBRARY ${PostgreSQL_LIBRARY} ${SECUR32_LIBRARY}) |
| 157 | + |
| 158 | +endif() |
| 159 | + |
| 160 | +if (PostgreSQL_INCLUDE_DIR AND EXISTS "${PostgreSQL_INCLUDE_DIR}/pg_config.h") |
| 161 | + file(STRINGS "${PostgreSQL_INCLUDE_DIR}/pg_config.h" pgsql_version_str |
| 162 | + REGEX "^#define[\t ]+PG_VERSION[\t ]+\".*\"") |
| 163 | + |
| 164 | + string(REGEX REPLACE "^#define[\t ]+PG_VERSION[\t ]+\"([^\"]*)\".*" "\\1" |
| 165 | + PostgreSQL_VERSION_STRING "${pgsql_version_str}") |
| 166 | + unset(pgsql_version_str) |
| 167 | +endif() |
| 168 | + |
| 169 | +# Did we find anything? |
| 170 | +include(FindPackageHandleStandardArgs) |
| 171 | +find_package_handle_standard_args(PostgreSQL |
| 172 | + REQUIRED_VARS PostgreSQL_LIBRARY |
| 173 | + VERSION_VAR PostgreSQL_VERSION_STRING) |
| 174 | +set(PostgreSQL_FOUND ${POSTGRESQL_FOUND}) |
| 175 | + |
| 176 | +# Now try to get the include and library path. |
| 177 | +if(PostgreSQL_FOUND) |
| 178 | + |
| 179 | + set(PostgreSQL_INCLUDE_DIRS ${PostgreSQL_INCLUDE_DIR}) |
| 180 | + set(PostgreSQL_LIBRARY_DIRS ${PostgreSQL_LIBRARY_DIR}) |
| 181 | + set(PostgreSQL_LIBRARIES ${PostgreSQL_LIBRARY}) |
| 182 | + |
| 183 | + #message("Final PostgreSQL include dir: ${PostgreSQL_INCLUDE_DIRS}") |
| 184 | + #message("Final PostgreSQL library dir: ${PostgreSQL_LIBRARY_DIRS}") |
| 185 | + #message("Final PostgreSQL libraries: ${PostgreSQL_LIBRARIES}") |
| 186 | +endif() |
| 187 | + |
| 188 | +mark_as_advanced(PostgreSQL_INCLUDE_DIRS PostgreSQL_LIBRARIES) |
0 commit comments