"Fossies" - the Fresh Open Source Software Archive

Member "icinga2-2.10.5/third-party/cmake/FindPostgreSQL.cmake" (23 May 2019, 8270 Bytes) of package /linux/misc/icinga2-2.10.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) CMake source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #.rst:
    2 # FindPostgreSQL
    3 # --------------
    4 #
    5 # Find the PostgreSQL installation.
    6 #
    7 # In Windows, we make the assumption that, if the PostgreSQL files are
    8 # installed, the default directory will be C:\Program Files\PostgreSQL.
    9 #
   10 # This module defines
   11 #
   12 # ::
   13 #
   14 #   PostgreSQL_LIBRARIES - the PostgreSQL libraries needed for linking
   15 #   PostgreSQL_INCLUDE_DIRS - the directories of the PostgreSQL headers
   16 
   17 #=============================================================================
   18 # Copyright 2004-2009 Kitware, Inc.
   19 #
   20 # Redistribution and use in source and binary forms, with or without
   21 # modification, are permitted provided that the following conditions
   22 # are met:
   23 #
   24 # * Redistributions of source code must retain the above copyright
   25 #   notice, this list of conditions and the following disclaimer.
   26 #
   27 # * Redistributions in binary form must reproduce the above copyright
   28 #   notice, this list of conditions and the following disclaimer in the
   29 #   documentation and/or other materials provided with the distribution.
   30 #
   31 # * Neither the names of Kitware, Inc., the Insight Software Consortium,
   32 #   nor the names of their contributors may be used to endorse or promote
   33 #   products derived from this software without specific prior written
   34 #   permission.
   35 #
   36 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   37 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   38 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   39 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
   40 # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   41 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   42 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   43 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   44 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   45 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
   46 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   47 #
   48 # This software is distributed WITHOUT ANY WARRANTY; without even the
   49 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
   50 # See the License for more information.
   51 #=============================================================================
   52 
   53 # ----------------------------------------------------------------------------
   54 # History:
   55 # This module is derived from the module originally found in the VTK source tree.
   56 #
   57 # ----------------------------------------------------------------------------
   58 # Note:
   59 # PostgreSQL_ADDITIONAL_VERSIONS is a variable that can be used to set the
   60 # version mumber of the implementation of PostgreSQL.
   61 # In Windows the default installation of PostgreSQL uses that as part of the path.
   62 # E.g C:\Program Files\PostgreSQL\8.4.
   63 # Currently, the following version numbers are known to this module:
   64 # "9.1" "9.0" "8.4" "8.3" "8.2" "8.1" "8.0"
   65 #
   66 # To use this variable just do something like this:
   67 # set(PostgreSQL_ADDITIONAL_VERSIONS "9.2" "8.4.4")
   68 # before calling find_package(PostgreSQL) in your CMakeLists.txt file.
   69 # This will mean that the versions you set here will be found first in the order
   70 # specified before the default ones are searched.
   71 #
   72 # ----------------------------------------------------------------------------
   73 # You may need to manually set:
   74 #  PostgreSQL_INCLUDE_DIR  - the path to where the PostgreSQL include files are.
   75 #  PostgreSQL_LIBRARY_DIR  - The path to where the PostgreSQL library files are.
   76 # If FindPostgreSQL.cmake cannot find the include files or the library files.
   77 #
   78 # ----------------------------------------------------------------------------
   79 # The following variables are set if PostgreSQL is found:
   80 #  PostgreSQL_FOUND         - Set to true when PostgreSQL is found.
   81 #  PostgreSQL_INCLUDE_DIRS  - Include directories for PostgreSQL
   82 #  PostgreSQL_LIBRARY_DIRS  - Link directories for PostgreSQL libraries
   83 #  PostgreSQL_LIBRARIES     - The PostgreSQL libraries.
   84 #
   85 # ----------------------------------------------------------------------------
   86 # If you have installed PostgreSQL in a non-standard location.
   87 # (Please note that in the following comments, it is assumed that <Your Path>
   88 # points to the root directory of the include directory of PostgreSQL.)
   89 # Then you have three options.
   90 # 1) After CMake runs, set PostgreSQL_INCLUDE_DIR to <Your Path>/include and
   91 #    PostgreSQL_LIBRARY_DIR to wherever the library pq (or libpq in windows) is
   92 # 2) Use CMAKE_INCLUDE_PATH to set a path to <Your Path>/PostgreSQL<-version>. This will allow find_path()
   93 #    to locate PostgreSQL_INCLUDE_DIR by utilizing the PATH_SUFFIXES option. e.g. In your CMakeLists.txt file
   94 #    set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "<Your Path>/include")
   95 # 3) Set an environment variable called ${PostgreSQL_ROOT} that points to the root of where you have
   96 #    installed PostgreSQL, e.g. <Your Path>.
   97 #
   98 # ----------------------------------------------------------------------------
   99 
  100 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")
  101 set(PostgreSQL_INCLUDE_DIR_MESSAGE "Set the PostgreSQL_INCLUDE_DIR cmake cache entry to the ${PostgreSQL_INCLUDE_PATH_DESCRIPTION}")
  102 set(PostgreSQL_LIBRARY_PATH_DESCRIPTION "top-level directory containing the PostgreSQL libraries.")
  103 set(PostgreSQL_LIBRARY_DIR_MESSAGE "Set the PostgreSQL_LIBRARY_DIR cmake cache entry to the ${PostgreSQL_LIBRARY_PATH_DESCRIPTION}")
  104 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")
  105 
  106 
  107 set(PostgreSQL_KNOWN_VERSIONS ${PostgreSQL_ADDITIONAL_VERSIONS}
  108     "9.1" "9.0" "8.4" "8.3" "8.2" "8.1" "8.0")
  109 
  110 # Define additional search paths for root directories.
  111 if ( WIN32 )
  112   foreach (suffix ${PostgreSQL_KNOWN_VERSIONS} )
  113     set(PostgreSQL_ADDITIONAL_SEARCH_PATHS ${PostgreSQL_ADDITIONAL_SEARCH_PATHS} "C:/Program Files/PostgreSQL/${suffix}" )
  114   endforeach()
  115 else()
  116   set(PostgreSQL_ADDITIONAL_SEARCH_PATHS ${PostgreSQL_ADDITIONAL_SEARCH_PATHS} "/Library/PostgreSQL/*")
  117 endif()
  118 set( PostgreSQL_ROOT_DIRECTORIES
  119    ENV PostgreSQL_ROOT
  120    ${PostgreSQL_ROOT}
  121    ${PostgreSQL_ADDITIONAL_SEARCH_PATHS}
  122 )
  123 
  124 #
  125 # Look for an installation.
  126 #
  127 find_path(PostgreSQL_INCLUDE_DIR
  128   NAMES libpq-fe.h
  129   PATHS
  130    # Look in other places.
  131    ${PostgreSQL_ROOT_DIRECTORIES}
  132   PATH_SUFFIXES
  133     pgsql
  134     postgresql
  135     include
  136   # Help the user find it if we cannot.
  137   DOC "The ${PostgreSQL_INCLUDE_DIR_MESSAGE}"
  138 )
  139 
  140 # The PostgreSQL library.
  141 set (PostgreSQL_LIBRARY_TO_FIND pq)
  142 # Setting some more prefixes for the library
  143 set (PostgreSQL_LIB_PREFIX "")
  144 if ( WIN32 )
  145   set (PostgreSQL_LIB_PREFIX ${PostgreSQL_LIB_PREFIX} "lib")
  146   set ( PostgreSQL_LIBRARY_TO_FIND ${PostgreSQL_LIB_PREFIX}${PostgreSQL_LIBRARY_TO_FIND})
  147 endif()
  148 
  149 find_library( PostgreSQL_LIBRARY
  150  NAMES ${PostgreSQL_LIBRARY_TO_FIND}
  151  PATHS
  152    ${PostgreSQL_ROOT_DIRECTORIES}
  153  PATH_SUFFIXES
  154    lib
  155 )
  156 get_filename_component(PostgreSQL_LIBRARY_DIR ${PostgreSQL_LIBRARY} PATH)
  157 
  158 if (PostgreSQL_INCLUDE_DIR AND EXISTS "${PostgreSQL_INCLUDE_DIR}/pg_config.h")
  159   file(STRINGS "${PostgreSQL_INCLUDE_DIR}/pg_config.h" pgsql_version_str
  160        REGEX "^#define[\t ]+PG_VERSION[\t ]+\".*\"")
  161 
  162   string(REGEX REPLACE "^#define[\t ]+PG_VERSION[\t ]+\"([^\"]*)\".*" "\\1"
  163          PostgreSQL_VERSION_STRING "${pgsql_version_str}")
  164   set(pgsql_version_str "")
  165 endif()
  166 
  167 # Did we find anything?
  168 include(FindPackageHandleStandardArgs)
  169 find_package_handle_standard_args(PostgreSQL DEFAULT_MSG
  170                                   PostgreSQL_LIBRARY PostgreSQL_INCLUDE_DIR)
  171 set( PostgreSQL_FOUND  ${POSTGRESQL_FOUND})
  172 
  173 # Now try to get the include and library path.
  174 if(PostgreSQL_FOUND)
  175 
  176   set(PostgreSQL_INCLUDE_DIRS ${PostgreSQL_INCLUDE_DIR} )
  177   set(PostgreSQL_LIBRARY_DIRS ${PostgreSQL_LIBRARY_DIR} )
  178   set(PostgreSQL_LIBRARIES ${PostgreSQL_LIBRARY_TO_FIND})
  179 
  180   #message("Final PostgreSQL include dir: ${PostgreSQL_INCLUDE_DIRS}")
  181   #message("Final PostgreSQL library dir: ${PostgreSQL_LIBRARY_DIRS}")
  182   #message("Final PostgreSQL libraries:   ${PostgreSQL_LIBRARIES}")
  183 endif()
  184 
  185 mark_as_advanced(PostgreSQL_INCLUDE_DIR PostgreSQL_LIBRARY )