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