Mercurial > hg > orthanc-databases
annotate Resources/CMake/FindPostgreSQL.cmake @ 78:2ee166f77501 db-changes
renamed macro
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sun, 06 Jan 2019 12:48:18 +0100 |
parents | 0ff0ad51181d |
children |
rev | line source |
---|---|
0 | 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} | |
58
0ff0ad51181d
fix build with postgresql-11
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
78 "11" "10" "9.6" "9.5" "9.4" "9.3" "9.2" "9.1" "9.0" "8.4" "8.3" "8.2" "8.1" "8.0") |
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 else() | |
86 foreach (suffix ${PostgreSQL_KNOWN_VERSIONS} ) | |
87 set(PostgreSQL_ADDITIONAL_SEARCH_PATHS ${PostgreSQL_ADDITIONAL_SEARCH_PATHS} "/usr/include/postgresql/${suffix}" "/usr/local/include/postgresql/${suffix}") | |
88 endforeach() | |
89 endif() | |
90 set( PostgreSQL_ROOT_DIRECTORIES | |
91 ENV PostgreSQL_ROOT | |
92 ${PostgreSQL_ROOT} | |
93 ${PostgreSQL_ADDITIONAL_SEARCH_PATHS} | |
94 ) | |
95 | |
96 # | |
97 # Look for an installation. | |
98 # | |
99 find_path(PostgreSQL_INCLUDE_DIR | |
100 NAMES libpq-fe.h | |
101 PATHS | |
102 # Look in other places. | |
103 ${PostgreSQL_ROOT_DIRECTORIES} | |
104 PATH_SUFFIXES | |
105 pgsql | |
106 postgresql | |
107 include | |
108 # Help the user find it if we cannot. | |
109 DOC "The ${PostgreSQL_INCLUDE_DIR_MESSAGE}" | |
110 ) | |
111 | |
112 find_path(PostgreSQL_TYPE_INCLUDE_DIR | |
113 NAMES catalog/pg_type.h | |
114 PATHS | |
115 # Look in other places. | |
116 ${PostgreSQL_ROOT_DIRECTORIES} | |
117 PATH_SUFFIXES | |
118 postgresql | |
119 pgsql/server | |
120 postgresql/server | |
121 include/server | |
122 server | |
123 # Help the user find it if we cannot. | |
124 DOC "The ${PostgreSQL_INCLUDE_DIR_MESSAGE}" | |
125 ) | |
126 | |
127 # The PostgreSQL library. | |
128 set (PostgreSQL_LIBRARY_TO_FIND pq) | |
129 # Setting some more prefixes for the library | |
130 set (PostgreSQL_LIB_PREFIX "") | |
131 if ( WIN32 ) | |
132 set (PostgreSQL_LIB_PREFIX ${PostgreSQL_LIB_PREFIX} "lib") | |
133 set ( PostgreSQL_LIBRARY_TO_FIND ${PostgreSQL_LIB_PREFIX}${PostgreSQL_LIBRARY_TO_FIND}) | |
134 endif() | |
135 | |
136 find_library( PostgreSQL_LIBRARY | |
137 NAMES ${PostgreSQL_LIBRARY_TO_FIND} | |
138 PATHS | |
139 ${PostgreSQL_ROOT_DIRECTORIES} | |
140 PATH_SUFFIXES | |
141 lib | |
142 ) | |
143 get_filename_component(PostgreSQL_LIBRARY_DIR ${PostgreSQL_LIBRARY} PATH) | |
144 | |
145 if (PostgreSQL_INCLUDE_DIR AND EXISTS "${PostgreSQL_INCLUDE_DIR}/pg_config.h") | |
146 file(STRINGS "${PostgreSQL_INCLUDE_DIR}/pg_config.h" pgsql_version_str | |
147 REGEX "^#define[\t ]+PG_VERSION[\t ]+\".*\"") | |
148 | |
149 string(REGEX REPLACE "^#define[\t ]+PG_VERSION[\t ]+\"([^\"]*)\".*" "\\1" | |
150 PostgreSQL_VERSION_STRING "${pgsql_version_str}") | |
151 unset(pgsql_version_str) | |
152 endif() | |
153 | |
154 # Did we find anything? | |
155 include(FindPackageHandleStandardArgs) | |
156 find_package_handle_standard_args(PostgreSQL | |
157 REQUIRED_VARS PostgreSQL_LIBRARY PostgreSQL_INCLUDE_DIR PostgreSQL_TYPE_INCLUDE_DIR | |
158 VERSION_VAR PostgreSQL_VERSION_STRING) | |
159 set( PostgreSQL_FOUND ${POSTGRESQL_FOUND}) | |
160 | |
161 # Now try to get the include and library path. | |
162 if(PostgreSQL_FOUND) | |
163 | |
164 set(PostgreSQL_INCLUDE_DIRS ${PostgreSQL_INCLUDE_DIR} ${PostgreSQL_TYPE_INCLUDE_DIR} ) | |
165 set(PostgreSQL_LIBRARY_DIRS ${PostgreSQL_LIBRARY_DIR} ) | |
166 set(PostgreSQL_LIBRARIES ${PostgreSQL_LIBRARY_TO_FIND}) | |
167 #message("Final PostgreSQL include dir: ${PostgreSQL_INCLUDE_DIRS}") | |
168 #message("Final PostgreSQL library dir: ${PostgreSQL_LIBRARY_DIRS}") | |
169 #message("Final PostgreSQL libraries: ${PostgreSQL_LIBRARIES}") | |
170 endif() | |
171 | |
172 mark_as_advanced(PostgreSQL_INCLUDE_DIR PostgreSQL_TYPE_INCLUDE_DIR PostgreSQL_LIBRARY ) |