Mercurial > hg > orthanc-databases
annotate Resources/CMake/PostgreSQLConfiguration.cmake @ 81:515a783630df
injecting fix to issue #105 into the mainline
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 10 Jan 2019 13:32:34 +0100 |
parents | 714c5d2bee76 |
children | ff2d56d37bfd |
rev | line source |
---|---|
0 | 1 # Orthanc - A Lightweight, RESTful DICOM Store |
2 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
3 # Department, University Hospital of Liege, Belgium | |
67 | 4 # Copyright (C) 2017-2019 Osimis S.A., Belgium |
0 | 5 # |
6 # This program is free software: you can redistribute it and/or | |
7 # modify it under the terms of the GNU Affero General Public License | |
8 # as published by the Free Software Foundation, either version 3 of | |
9 # the License, or (at your option) any later version. | |
10 # | |
11 # This program is distributed in the hope that it will be useful, but | |
12 # WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 # Affero General Public License for more details. | |
15 # | |
16 # You should have received a copy of the GNU Affero General Public License | |
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | |
19 | |
20 ##################################################################### | |
21 ## PostgreSQL | |
22 ##################################################################### | |
23 | |
24 INCLUDE(CheckTypeSize) | |
25 INCLUDE(CheckCSourceCompiles) | |
26 INCLUDE(CheckFunctionExists) | |
27 INCLUDE(CheckStructHasMember) | |
28 | |
29 | |
30 if (STATIC_BUILD OR NOT USE_SYSTEM_LIBPQ) | |
31 add_definitions(-DORTHANC_POSTGRESQL_STATIC=1) | |
32 | |
33 SET(LIBPQ_MAJOR 9) | |
34 SET(LIBPQ_MINOR 6) | |
35 SET(LIBPQ_REVISION 1) | |
36 SET(LIBPQ_VERSION ${LIBPQ_MAJOR}.${LIBPQ_MINOR}.${LIBPQ_REVISION}) | |
37 | |
38 SET(LIBPQ_SOURCES_DIR ${CMAKE_BINARY_DIR}/postgresql-${LIBPQ_VERSION}) | |
39 DownloadPackage( | |
40 "eaa7e267e89ea1ed2693d2b88d3cd290" | |
41 "http://www.orthanc-server.com/downloads/third-party/postgresql-${LIBPQ_VERSION}.tar.gz" | |
42 "${LIBPQ_SOURCES_DIR}") | |
43 | |
44 | |
45 ## | |
46 ## Platform-specific configuration | |
47 ## | |
48 | |
49 if (CMAKE_SYSTEM_NAME STREQUAL "Windows") | |
50 add_definitions( | |
51 -DEXEC_BACKEND | |
52 ) | |
53 | |
54 configure_file( | |
55 ${LIBPQ_SOURCES_DIR}/src/include/port/win32.h | |
56 ${AUTOGENERATED_DIR}/pg_config_os.h | |
57 COPYONLY) | |
58 | |
59 elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux") | |
60 add_definitions( | |
61 -D_GNU_SOURCE | |
62 -D_THREAD_SAFE | |
63 -D_POSIX_PTHREAD_SEMANTICS | |
64 ) | |
65 | |
66 configure_file( | |
67 ${LIBPQ_SOURCES_DIR}/src/include/port/linux.h | |
68 ${AUTOGENERATED_DIR}/pg_config_os.h | |
69 COPYONLY) | |
70 | |
71 elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin") | |
72 add_definitions( | |
73 -D_GNU_SOURCE | |
74 -D_THREAD_SAFE | |
75 -D_POSIX_PTHREAD_SEMANTICS | |
76 ) | |
77 | |
78 configure_file( | |
79 ${LIBPQ_SOURCES_DIR}/src/include/port/darwin.h | |
80 ${AUTOGENERATED_DIR}/pg_config_os.h | |
81 COPYONLY) | |
82 | |
83 elseif (CMAKE_SYSTEM_NAME STREQUAL "OpenBSD") | |
84 configure_file( | |
85 ${LIBPQ_SOURCES_DIR}/src/include/port/openbsd.h | |
86 ${AUTOGENERATED_DIR}/pg_config_os.h | |
87 COPYONLY) | |
88 | |
89 elseif (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") | |
90 configure_file( | |
91 ${LIBPQ_SOURCES_DIR}/src/include/port/freebsd.h | |
92 ${AUTOGENERATED_DIR}/pg_config_os.h | |
93 COPYONLY) | |
94 | |
95 else() | |
96 message(FATAL_ERROR "Support your platform here") | |
97 endif() | |
98 | |
99 | |
100 ## | |
101 ## Generation of "pg_config.h" | |
102 ## | |
103 | |
104 if (CMAKE_SYSTEM_NAME STREQUAL "Windows") | |
105 configure_file( | |
106 ${LIBPQ_SOURCES_DIR}/src/include/pg_config_ext.h.win32 | |
107 ${AUTOGENERATED_DIR}/pg_config_ext.h | |
108 COPYONLY) | |
109 | |
110 configure_file( | |
111 ${LIBPQ_SOURCES_DIR}/src/include/pg_config.h.win32 | |
112 ${AUTOGENERATED_DIR}/pg_config.h | |
113 COPYONLY) | |
114 | |
115 if (CMAKE_COMPILER_IS_GNUCXX) # MinGW | |
116 add_definitions( | |
117 -DPG_PRINTF_ATTRIBUTE=gnu_printf | |
118 -DHAVE_GETTIMEOFDAY | |
119 -DHAVE_LONG_LONG_INT_64 | |
120 -DHAVE_STRUCT_ADDRINFO | |
121 -DHAVE_STRUCT_SOCKADDR_STORAGE | |
122 -DHAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY | |
123 ) | |
124 endif() | |
125 | |
126 elseif(CROSS_COMPILING) | |
127 message(FATAL_ERROR "Cannot auto-generate the configuration file cross-compiling") | |
128 | |
129 else() | |
130 configure_file( | |
131 ${CMAKE_CURRENT_LIST_DIR}/../PostgreSQL/pg_config_ext.h | |
132 ${AUTOGENERATED_DIR}/pg_config_ext.h | |
133 COPYONLY | |
134 ) | |
135 | |
136 set(CMAKE_EXTRA_INCLUDE_FILES "sys/socket.h;netdb.h;sys/types.h") | |
137 | |
138 include(${CMAKE_CURRENT_LIST_DIR}/../PostgreSQL/func_accept_args.cmake) | |
139 set(ACCEPT_TYPE_ARG3 ${ACCEPT_TYPE_ARG3}) | |
140 | |
141 check_type_size("long int" SIZE_LONG_INT) | |
142 if (SIZE_LONG_INT EQUAL 8) | |
143 set(HAVE_LONG_INT_64 1) | |
144 endif() | |
145 | |
146 check_type_size("long long int" SIZE_LONG_LONG_INT) | |
147 if (SIZE_LONG_LONG_INT EQUAL 8) | |
148 set(HAVE_LONG_LONG_INT_64 1) | |
149 endif() | |
150 | |
151 file(READ ${CMAKE_CURRENT_LIST_DIR}/../PostgreSQL/c_flexmember.c SOURCE) | |
152 check_c_source_compiles("${SOURCE}" c_flexmember) | |
153 if (c_flexmember) | |
154 set(FLEXIBLE_ARRAY_MEMBER "/**/") | |
155 endif() | |
156 | |
157 if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR | |
158 CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR | |
159 CMAKE_SYSTEM_NAME STREQUAL "OpenBSD") | |
160 set(PG_PRINTF_ATTRIBUTE "printf") | |
161 else() | |
162 file(READ ${CMAKE_CURRENT_LIST_DIR}/../PostgreSQL/printf_archetype.c SOURCE) | |
163 check_c_source_compiles("${SOURCE}" printf_archetype) | |
164 if (printf_archetype) | |
165 set(PG_PRINTF_ATTRIBUTE "gnu_printf") | |
166 else() | |
167 set(PG_PRINTF_ATTRIBUTE "printf") | |
168 endif() | |
169 endif() | |
170 | |
171 check_function_exists("isinf" HAVE_ISINF) | |
172 check_function_exists("getaddrinfo" HAVE_GETADDRINFO) | |
173 check_function_exists("gettimeofday" HAVE_GETTIMEOFDAY) | |
174 check_function_exists("snprintf" HAVE_DECL_SNPRINTF) | |
175 check_function_exists("srandom" HAVE_SRANDOM) | |
176 check_function_exists("strlcat" HAVE_DECL_STRLCAT) | |
177 check_function_exists("strlcpy" HAVE_DECL_STRLCPY) | |
178 check_function_exists("unsetenv" HAVE_UNSETENV) | |
179 check_function_exists("vsnprintf" HAVE_DECL_VSNPRINTF) | |
180 | |
181 check_type_size("struct addrinfo" SIZE_STRUCT_ADDRINFO) | |
182 if (HAVE_SIZE_STRUCT_ADDRINFO) | |
183 set(HAVE_STRUCT_ADDRINFO 1) | |
184 endif() | |
185 | |
186 check_type_size("struct sockaddr_storage" SIZE_STRUCT_SOCKADDR_STORAGE) | |
187 if (HAVE_SIZE_STRUCT_SOCKADDR_STORAGE) | |
188 set(HAVE_STRUCT_SOCKADDR_STORAGE 1) | |
189 endif() | |
190 | |
191 set(MEMSET_LOOP_LIMIT 1024) # This is hardcoded in "postgresql-9.6.1/configure" | |
192 set(DEF_PGPORT 5432) # Default port number of PostgreSQL | |
193 set(DEF_PGPORT_STR "\"5432\"") # Same as above, as a string | |
194 set(PG_VERSION "\"${LIBPQ_VERSION}\"") # Version of PostgreSQL, as a string | |
195 | |
196 # Version of PostgreSQL, as a number | |
197 math(EXPR PG_VERSION_NUM "${LIBPQ_MAJOR} * 10000 + ${LIBPQ_MINOR} * 100 + ${LIBPQ_REVISION}") | |
198 | |
199 set(HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY 1) # TODO Autodetection | |
200 | |
201 # Compute maximum alignment of any basic type. | |
202 # We assume long's alignment is at least as strong as char, short, or int; | |
203 # but we must check long long (if it exists) and double. | |
204 check_type_size("long" SIZE_LONG) | |
205 check_type_size("long long" SIZE_LONG_LONG) | |
206 check_type_size("double" SIZE_DOUBLE) | |
207 set(MAXIMUM_ALIGNOF ${SIZE_LONG}) | |
208 if(SIZE_LONG_LONG AND SIZE_LONG_LONG GREATER MAXIMUM_ALIGNOF) | |
209 set(MAXIMUM_ALIGNOF ${SIZE_LONG_LONG}) | |
210 endif() | |
211 if(SIZE_DOUBLE GREATER MAXIMUM_ALIGNOF) | |
212 set(MAXIMUM_ALIGNOF ${SIZE_DOUBLE}) | |
213 endif() | |
214 | |
215 check_include_file("poll.h" HAVE_POLL_H) | |
216 check_include_file("net/if.h" HAVE_NET_IF_H) | |
217 check_include_file("netinet/in.h" HAVE_NETINET_IN_H) | |
218 check_include_file("netinet/tcp.h" HAVE_NETINET_TCP_H) | |
219 check_include_file("sys/ioctl.h" HAVE_SYS_IOCTL_H) | |
220 check_include_file("sys/un.h" HAVE_SYS_UN_H) | |
221 | |
222 If (NOT HAVE_NET_IF_H) # This is the case of OpenBSD | |
223 unset(HAVE_NET_IF_H CACHE) | |
224 check_include_files("sys/socket.h;net/if.h" HAVE_NET_IF_H) | |
225 endif() | |
226 | |
227 if (NOT HAVE_NETINET_TCP_H) # This is the case of OpenBSD | |
228 unset(HAVE_NETINET_TCP_H CACHE) | |
229 check_include_files("sys/socket.h;netinet/tcp.h" HAVE_NETINET_TCP_H) | |
230 endif() | |
231 | |
232 | |
81
515a783630df
injecting fix to issue 105 into the mainline
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
233 if (ENABLE_SSL) |
515a783630df
injecting fix to issue 105 into the mainline
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
234 set(HAVE_LIBSSL 1) |
515a783630df
injecting fix to issue 105 into the mainline
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
235 set(HAVE_SSL_GET_CURRENT_COMPRESSION 1) |
515a783630df
injecting fix to issue 105 into the mainline
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
236 set(USE_OPENSSL 1) |
515a783630df
injecting fix to issue 105 into the mainline
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
237 endif() |
515a783630df
injecting fix to issue 105 into the mainline
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
238 |
0 | 239 execute_process( |
240 COMMAND | |
241 ${PYTHON_EXECUTABLE} | |
242 "${CMAKE_CURRENT_LIST_DIR}/../PostgreSQL/PrepareCMakeConfigurationFile.py" | |
243 "${LIBPQ_SOURCES_DIR}/src/include/pg_config.h.in" | |
244 "${AUTOGENERATED_DIR}/pg_config.h.in" | |
245 ERROR_VARIABLE NO_PG_CONFIG | |
246 OUTPUT_VARIABLE out | |
247 ) | |
248 | |
249 if (NO_PG_CONFIG) | |
250 message(FATAL_ERROR "Cannot find pg_config.h.in") | |
251 endif() | |
252 | |
253 configure_file( | |
254 ${AUTOGENERATED_DIR}/pg_config.h.in | |
255 ${AUTOGENERATED_DIR}/pg_config.h) | |
256 endif() | |
257 | |
258 | |
259 | |
260 ## | |
261 ## Generic configuration | |
262 ## | |
263 | |
264 file(WRITE | |
265 ${AUTOGENERATED_DIR}/pg_config_paths.h | |
266 "") | |
267 | |
268 add_definitions( | |
269 -D_REENTRANT | |
270 -DFRONTEND | |
271 -DUNSAFE_STAT_OK | |
272 -DSYSCONFDIR="" | |
273 ) | |
274 | |
275 include_directories( | |
276 ${LIBPQ_SOURCES_DIR}/src/include | |
277 ${LIBPQ_SOURCES_DIR}/src/include/libpq | |
278 ${LIBPQ_SOURCES_DIR}/src/interfaces/libpq | |
279 ) | |
280 | |
281 set(LIBPQ_SOURCES | |
282 ${LIBPQ_SOURCES_DIR}/src/interfaces/libpq/fe-auth.c | |
283 ${LIBPQ_SOURCES_DIR}/src/interfaces/libpq/fe-connect.c | |
284 ${LIBPQ_SOURCES_DIR}/src/interfaces/libpq/fe-exec.c | |
285 ${LIBPQ_SOURCES_DIR}/src/interfaces/libpq/fe-lobj.c | |
286 ${LIBPQ_SOURCES_DIR}/src/interfaces/libpq/fe-misc.c | |
287 ${LIBPQ_SOURCES_DIR}/src/interfaces/libpq/fe-print.c | |
288 ${LIBPQ_SOURCES_DIR}/src/interfaces/libpq/fe-protocol2.c | |
289 ${LIBPQ_SOURCES_DIR}/src/interfaces/libpq/fe-protocol3.c | |
290 ${LIBPQ_SOURCES_DIR}/src/interfaces/libpq/fe-secure.c | |
291 ${LIBPQ_SOURCES_DIR}/src/interfaces/libpq/libpq-events.c | |
292 ${LIBPQ_SOURCES_DIR}/src/interfaces/libpq/pqexpbuffer.c | |
293 | |
294 # libpgport C files we always use | |
295 ${LIBPQ_SOURCES_DIR}/src/port/chklocale.c | |
296 ${LIBPQ_SOURCES_DIR}/src/port/inet_net_ntop.c | |
297 ${LIBPQ_SOURCES_DIR}/src/port/noblock.c | |
298 ${LIBPQ_SOURCES_DIR}/src/port/pgstrcasecmp.c | |
299 ${LIBPQ_SOURCES_DIR}/src/port/pqsignal.c | |
300 ${LIBPQ_SOURCES_DIR}/src/port/thread.c | |
301 | |
302 ${LIBPQ_SOURCES_DIR}/src/backend/libpq/ip.c | |
303 ${LIBPQ_SOURCES_DIR}/src/backend/libpq/md5.c | |
304 ${LIBPQ_SOURCES_DIR}/src/backend/utils/mb/encnames.c | |
305 ${LIBPQ_SOURCES_DIR}/src/backend/utils/mb/wchar.c | |
306 ) | |
307 | |
81
515a783630df
injecting fix to issue 105 into the mainline
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
308 if (ENABLE_SSL) |
515a783630df
injecting fix to issue 105 into the mainline
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
309 list(APPEND LIBPQ_SOURCES |
515a783630df
injecting fix to issue 105 into the mainline
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
310 ${LIBPQ_SOURCES_DIR}/src/interfaces/libpq/fe-secure-openssl.c |
515a783630df
injecting fix to issue 105 into the mainline
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
311 ) |
515a783630df
injecting fix to issue 105 into the mainline
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
312 endif() |
515a783630df
injecting fix to issue 105 into the mainline
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
313 |
0 | 314 |
315 if (CMAKE_SYSTEM_NAME STREQUAL "Linux") | |
316 LIST(APPEND LIBPQ_SOURCES | |
317 ${LIBPQ_SOURCES_DIR}/src/port/strlcpy.c | |
318 ) | |
319 | |
320 elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows") | |
5 | 321 link_libraries(secur32) |
322 | |
0 | 323 include_directories( |
324 ${LIBPQ_SOURCES_DIR}/src/include/port/win32 | |
325 ${LIBPQ_SOURCES_DIR}/src/port | |
326 ) | |
327 | |
328 LIST(APPEND LIBPQ_SOURCES | |
329 # libpgport C files that are needed if identified by configure | |
330 ${LIBPQ_SOURCES_DIR}/src/interfaces/libpq/win32.c | |
331 ${LIBPQ_SOURCES_DIR}/src/port/crypt.c | |
332 ${LIBPQ_SOURCES_DIR}/src/port/inet_aton.c | |
333 ${LIBPQ_SOURCES_DIR}/src/port/open.c | |
334 ${LIBPQ_SOURCES_DIR}/src/port/pgsleep.c | |
335 ${LIBPQ_SOURCES_DIR}/src/port/snprintf.c | |
336 ${LIBPQ_SOURCES_DIR}/src/port/system.c | |
337 ${LIBPQ_SOURCES_DIR}/src/port/win32setlocale.c | |
338 ${LIBPQ_SOURCES_DIR}/src/port/getaddrinfo.c | |
339 ${LIBPQ_SOURCES_DIR}/src/port/strlcpy.c | |
340 ) | |
341 | |
342 if (CMAKE_COMPILER_IS_GNUCXX OR | |
343 (MSVC AND MSVC_VERSION GREATER 1800)) | |
344 # Starting Visual Studio 2013 (version 1800), it is necessary to also add "win32error.c" | |
345 LIST(APPEND LIBPQ_SOURCES ${LIBPQ_SOURCES_DIR}/src/port/win32error.c) | |
346 endif() | |
347 | |
348 if (MSVC) | |
349 LIST(APPEND LIBPQ_SOURCES ${LIBPQ_SOURCES_DIR}/src/interfaces/libpq/pthread-win32.c) | |
350 endif() | |
351 endif() | |
352 | |
353 if (CMAKE_COMPILER_IS_GNUCXX AND | |
354 NOT CMAKE_SYSTEM_NAME STREQUAL "OpenBSD") | |
355 LIST(APPEND LIBPQ_SOURCES | |
356 ${LIBPQ_SOURCES_DIR}/src/port/getpeereid.c | |
357 ) | |
358 | |
359 elseif (MSVC) | |
360 include_directories( | |
361 ${LIBPQ_SOURCES_DIR}/src/include/port/win32_msvc | |
362 ) | |
363 | |
364 LIST(APPEND LIBPQ_SOURCES | |
365 ${LIBPQ_SOURCES_DIR}/src/port/dirent.c | |
366 ${LIBPQ_SOURCES_DIR}/src/port/dirmod.c | |
367 ) | |
368 endif() | |
369 | |
370 source_group(ThirdParty\\PostgreSQL REGULAR_EXPRESSION ${LIBPQ_SOURCES_DIR}/.*) | |
371 | |
372 else() | |
373 include(${CMAKE_CURRENT_LIST_DIR}/FindPostgreSQL.cmake) | |
374 include_directories( | |
375 ${PostgreSQL_INCLUDE_DIR} | |
376 ${PostgreSQL_TYPE_INCLUDE_DIR} | |
377 ) | |
378 link_libraries(${PostgreSQL_LIBRARY}) | |
379 endif() |