changeset 173:30d3f68631d2

support of mingw in postgresql
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 11 Dec 2020 14:50:51 +0100
parents 8c7bb94adff7
children 77a5d1a5ebfd
files Framework/PostgreSQL/PostgreSQLIncludes.h Resources/CMake/PostgreSQLConfiguration.cmake
diffstat 2 files changed, 160 insertions(+), 172 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/PostgreSQL/PostgreSQLIncludes.h	Fri Dec 11 12:49:33 2020 +0100
+++ b/Framework/PostgreSQL/PostgreSQLIncludes.h	Fri Dec 11 14:50:51 2020 +0100
@@ -36,6 +36,7 @@
  * "__builtin_expect()" used by PostgreSQL 11.
  **/
 #include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/system/error_code.hpp>
 
 // PostgreSQL includes
 #include <pg_config.h>
--- a/Resources/CMake/PostgreSQLConfiguration.cmake	Fri Dec 11 12:49:33 2020 +0100
+++ b/Resources/CMake/PostgreSQLConfiguration.cmake	Fri Dec 11 14:50:51 2020 +0100
@@ -62,10 +62,6 @@
   ##
   
   if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
-    add_definitions(
-      -DEXEC_BACKEND
-      )
-
     configure_file(
       ${LIBPQ_SOURCES_DIR}/src/include/port/win32.h
       ${AUTOGENERATED_DIR}/pg_config_os.h
@@ -114,150 +110,163 @@
   ## Generation of "pg_config.h"
   ## 
   
-  if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
-    configure_file(
-      ${LIBPQ_SOURCES_DIR}/src/include/pg_config_ext.h.win32
-      ${AUTOGENERATED_DIR}/pg_config_ext.h
-      COPYONLY)
-
-    configure_file(
-      ${LIBPQ_SOURCES_DIR}/src/include/pg_config.h.win32
-      ${AUTOGENERATED_DIR}/pg_config.h
-      COPYONLY)
+  set(PG_VERSION "\"${LIBPQ_MAJOR}.${LIBPQ_MINOR}\"")
+  math(EXPR PG_VERSION_NUM "${LIBPQ_MAJOR} * 10000 + ${LIBPQ_MINOR}")
 
-    if (CMAKE_COMPILER_IS_GNUCXX)  # MinGW
-      add_definitions(
-        -DPG_PRINTF_ATTRIBUTE=gnu_printf
-        -DHAVE_GETTIMEOFDAY
-        -DHAVE_LONG_LONG_INT_64
-        -DHAVE_STRUCT_ADDRINFO
-        -DHAVE_STRUCT_SOCKADDR_STORAGE
-        -DHAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY
-        )
-    endif()
-    
-    if (ENABLE_SSL)
-      add_definitions(
-        -DHAVE_LIBSSL=1
-        -DUSE_OPENSSL=1
-        )
-    endif()
-
-  elseif(CROSS_COMPILING)
-    message(FATAL_ERROR "Cannot auto-generate the configuration file cross-compiling")
-    
-  else()
-    set(PG_VERSION "\"${LIBPQ_MAJOR}.${LIBPQ_MINOR}\"")
-    math(EXPR PG_VERSION_NUM "${LIBPQ_MAJOR} * 10000 + ${LIBPQ_MINOR}")
-
-    include(${CMAKE_CURRENT_LIST_DIR}/../PostgreSQL/func_accept_args.cmake)
-    include(${CMAKE_CURRENT_LIST_DIR}/../PostgreSQL/CheckTypeAlignment.cmake)
+  include(${CMAKE_CURRENT_LIST_DIR}/../PostgreSQL/func_accept_args.cmake)
+  include(${CMAKE_CURRENT_LIST_DIR}/../PostgreSQL/CheckTypeAlignment.cmake)
 
-    check_include_file("execinfo.h"           HAVE_EXECINFO_H) 
-    check_include_file("getopt.h"             HAVE_GETOPT_H) 
-    check_include_file("ifaddrs.h"            HAVE_IFADDRS_H) 
-    check_include_file("inttypes.h"           HAVE_INTTYPES_H) 
-    check_include_file("langinfo.h"           HAVE_LANGINFO_H)
-    check_include_file("memory.h"             HAVE_MEMORY_H) 
-    check_include_file("netinet/tcp.h"        HAVE_NETINET_TCP_H)
-    check_include_file("readline/history.h"   HAVE_READLINE_HISTORY_H)
-    check_include_file("readline/readline.h"  HAVE_READLINE_READLINE_H)
-    check_include_file("stdbool.h"            HAVE_STDBOOL_H)
-    check_include_file("stdlib.h"             HAVE_STDLIB_H)
-    check_include_file("string.h"             HAVE_STRING_H)
-    check_include_file("strings.h"            HAVE_STRINGS_H)
-    check_include_file("sys/epoll.h"          HAVE_SYS_EPOLL_H)
-    check_include_file("sys/event.h"          HAVE_SYS_EVENT_H)
-    check_include_file("sys/ipc.h"            HAVE_SYS_IPC_H)
-    check_include_file("sys/prctl.h"          HAVE_SYS_PRCTL_H)
-    check_include_file("sys/resource.h"       HAVE_SYS_RESOURCE_H)
-    check_include_file("sys/select.h"         HAVE_SYS_SELECT_H)
-    check_include_file("sys/sem.h"            HAVE_SYS_SEM_H)
-    check_include_file("sys/shm.h"            HAVE_SYS_SHM_H)
-    check_include_file("sys/stat.h"           HAVE_SYS_STAT_H)
-    check_include_file("sys/termios.h"        HAVE_SYS_TERMIOS_H)
-    check_include_file("sys/types.h"          HAVE_SYS_TYPES_H)
-    check_include_file("sys/un.h"             HAVE_SYS_UN_H)
-    check_include_file("termios.h"            HAVE_TERMIOS_H)
-    check_include_file("unistd.h"             HAVE_UNISTD_H)
-    check_include_file("wctype.h"             HAVE_WCTYPE_H)
+  check_include_file("execinfo.h"           HAVE_EXECINFO_H) 
+  check_include_file("getopt.h"             HAVE_GETOPT_H) 
+  check_include_file("ifaddrs.h"            HAVE_IFADDRS_H) 
+  check_include_file("inttypes.h"           HAVE_INTTYPES_H) 
+  check_include_file("langinfo.h"           HAVE_LANGINFO_H)
+  check_include_file("memory.h"             HAVE_MEMORY_H) 
+  check_include_file("netinet/tcp.h"        HAVE_NETINET_TCP_H)
+  check_include_file("readline/history.h"   HAVE_READLINE_HISTORY_H)
+  check_include_file("readline/readline.h"  HAVE_READLINE_READLINE_H)
+  check_include_file("stdbool.h"            HAVE_STDBOOL_H)
+  check_include_file("stdlib.h"             HAVE_STDLIB_H)
+  check_include_file("string.h"             HAVE_STRING_H)
+  check_include_file("strings.h"            HAVE_STRINGS_H)
+  check_include_file("sys/epoll.h"          HAVE_SYS_EPOLL_H)
+  check_include_file("sys/event.h"          HAVE_SYS_EVENT_H)
+  check_include_file("sys/ipc.h"            HAVE_SYS_IPC_H)
+  check_include_file("sys/prctl.h"          HAVE_SYS_PRCTL_H)
+  check_include_file("sys/resource.h"       HAVE_SYS_RESOURCE_H)
+  check_include_file("sys/select.h"         HAVE_SYS_SELECT_H)
+  check_include_file("sys/sem.h"            HAVE_SYS_SEM_H)
+  check_include_file("sys/shm.h"            HAVE_SYS_SHM_H)
+  check_include_file("sys/stat.h"           HAVE_SYS_STAT_H)
+  check_include_file("sys/termios.h"        HAVE_SYS_TERMIOS_H)
+  check_include_file("sys/types.h"          HAVE_SYS_TYPES_H)
+  check_include_file("sys/un.h"             HAVE_SYS_UN_H)
+  check_include_file("termios.h"            HAVE_TERMIOS_H)
+  check_include_file("unistd.h"             HAVE_UNISTD_H)
+  check_include_file("wctype.h"             HAVE_WCTYPE_H)
 
-    check_type_size("long long int" SIZEOF_LONG_LONG_INT)
-    if (SIZEOF_LONG_LONG_INT EQUAL 8)
-      set(HAVE_LONG_LONG_INT_64 1)
-      set(PG_INT64_TYPE "long long int")
-    endif()
+  check_type_size("long long int" SIZEOF_LONG_LONG_INT)
+  if (SIZEOF_LONG_LONG_INT EQUAL 8)
+    set(HAVE_LONG_LONG_INT_64 1)
+    set(PG_INT64_TYPE "long long int")
+  endif()
 
-    check_type_size("long int" SIZEOF_LONG_INT)
-    if (SIZEOF_LONG_INT EQUAL 8)
-      set(HAVE_LONG_INT_64 1)
-      set(PG_INT64_TYPE "long int")
-    endif()
-    
-    if (CMAKE_COMPILER_IS_GNUCXX OR
-        "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
-      set(PG_PRINTF_ATTRIBUTE "gnu_printf")
-      set(pg_restrict "__restrict")
-    else()
-      set(pg_restrict "")
-    endif()
-
+  check_type_size("long int" SIZEOF_LONG_INT)
+  if (SIZEOF_LONG_INT EQUAL 8)
+    set(HAVE_LONG_INT_64 1)
+    set(PG_INT64_TYPE "long int")
+  endif()
+  
+  if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
+    set(ALIGNOF_DOUBLE 8)
+    set(ALIGNOF_INT 4)
+    set(ALIGNOF_LONG 4)
+    set(ALIGNOF_LONG_LONG_INT 8)
+    set(ALIGNOF_SHORT 2)
+  else()
     check_type_alignment(double ALIGNOF_DOUBLE)
     check_type_alignment(int ALIGNOF_INT)
     check_type_alignment(long ALIGNOF_LONG)
     check_type_alignment("long long int" ALIGNOF_LONG_LONG_INT)
     check_type_alignment(short ALIGNOF_SHORT)
-    
-    set(MAXIMUM_ALIGNOF ${ALIGNOF_LONG})
-    if (MAXIMUM_ALIGNOF LESS ALIGNOF_DOUBLE)
-      set(MAXIMUM_ALIGNOF ${ALIGNOF_DOUBLE})
-    endif()
-    if (HAVE_LONG_LONG_INT_64 AND (MAXIMUM_ALIGNOF LESS HAVE_LONG_LONG_INT_64))
-      set(MAXIMUM_ALIGNOF ${HAVE_LONG_LONG_INT_64})
-    endif()
-    
-    set(CMAKE_EXTRA_INCLUDE_FILES "sys/socket.h;netdb.h")
-    check_type_size("struct addrinfo" HAVE_STRUCT_ADDRINFO)    
-    check_type_size("struct sockaddr_storage" HAVE_STRUCT_SOCKADDR_STORAGE)
-    check_struct_has_member("struct sockaddr_storage" ss_family
-      "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY)
-    check_function_exists(unsetenv HAVE_UNSETENV)
-    check_function_exists(strchrnul HAVE_STRCHRNUL)
-    check_function_exists(random HAVE_RANDOM)
-    check_function_exists(srandom HAVE_SRANDOM)
-      
-    # Hardcoded stuff from "./configure" of libpq
-    set(MEMSET_LOOP_LIMIT 1024)
-    set(BLCKSZ 8192)
-    set(XLOG_BLCKSZ 8192)
-    set(DEF_PGPORT 5432)
-    set(DEF_PGPORT_STR "\"${DEF_PGPORT}\"")
-    set(PG_KRB_SRVNAM "\"postgres\"")
+  endif()
+  
+  set(MAXIMUM_ALIGNOF ${ALIGNOF_LONG})
+  if (MAXIMUM_ALIGNOF LESS ALIGNOF_DOUBLE)
+    set(MAXIMUM_ALIGNOF ${ALIGNOF_DOUBLE})
+  endif()
+  if (HAVE_LONG_LONG_INT_64 AND (MAXIMUM_ALIGNOF LESS HAVE_LONG_LONG_INT_64))
+    set(MAXIMUM_ALIGNOF ${HAVE_LONG_LONG_INT_64})
+  endif()
+  
+  if (CMAKE_COMPILER_IS_GNUCXX OR
+      "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
+    set(PG_PRINTF_ATTRIBUTE "gnu_printf")
+    set(pg_restrict "__restrict")
+  else()
+    set(pg_restrict "")
+  endif()
+
+  if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
+    set(CMAKE_EXTRA_INCLUDE_FILES "sys/types.h;winsock2.h;ws2tcpip.h")
+  else()
+    set(CMAKE_EXTRA_INCLUDE_FILES "sys/types.h;sys/socket.h;netdb.h")
+  endif()
+  
+  check_type_size("struct addrinfo" HAVE_STRUCT_ADDRINFO)    
+  check_type_size("struct sockaddr_storage" HAVE_STRUCT_SOCKADDR_STORAGE)
+  check_struct_has_member("struct sockaddr_storage" ss_family
+    "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY)
+
+  check_function_exists(gethostbyname_r HAVE_GETHOSTBYNAME_R)
+  check_function_exists(getopt HAVE_GETOPT)
+  check_function_exists(getopt_long HAVE_GETOPT_LONG)
+  check_function_exists(getpwuid_r HAVE_GETPWUID_R)
+  check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
+  check_function_exists(random HAVE_RANDOM)
+  check_function_exists(srandom HAVE_SRANDOM)
+  check_function_exists(strchrnul HAVE_STRCHRNUL)
+  check_function_exists(strerror HAVE_STRERROR)
+  check_function_exists(strerror_r HAVE_STRERROR_R)
+  check_function_exists(unsetenv HAVE_UNSETENV)
 
-    # Assume that zlib and openssl are always present
-    set(HAVE_LIBZ 1)
-    set(HAVE_LIBSSL 1)
-    set(HAVE_OPENSSL_INIT_SSL 1)
-    set(USE_OPENSSL 1)
-    set(USE_OPENSSL_RANDOM 1)
-        
-    PrepareCMakeConfigurationFile(
-      ${LIBPQ_SOURCES_DIR}/src/include/pg_config_ext.h.in
-      ${AUTOGENERATED_DIR}/pg_config_ext.h.in)
-      
-    PrepareCMakeConfigurationFile(
-      ${LIBPQ_SOURCES_DIR}/src/include/pg_config.h.in
-      ${AUTOGENERATED_DIR}/pg_config.h.in)
-          
-    configure_file(
-      ${AUTOGENERATED_DIR}/pg_config_ext.h.in
-      ${AUTOGENERATED_DIR}/pg_config_ext.h)
+  check_c_source_compiles("
+	#include <sys/time.h>
+	int main(void){
+		struct timeval *tp;
+		struct timezone *tzp;
+		gettimeofday(tp,tzp);
+		return 0;
+	}
+  " GETTIMEOFDAY_2ARG)
 
-    configure_file(
-      ${AUTOGENERATED_DIR}/pg_config.h.in
-      ${AUTOGENERATED_DIR}/pg_config.h)
+  if(NOT GETTIMEOFDAY_2ARG)
+    set(GETTIMEOFDAY_1ARG 1)
+  endif(NOT GETTIMEOFDAY_2ARG)
+  
+  check_c_source_compiles("
+	#include <time.h>
+	int main(void){
+		int res;
+	#ifndef __CYGWIN__
+		res = timezone / 60;
+	#else
+		res = _timezone / 60;
+	#endif
+		return 0;
+	}
+  " HAVE_INT_TIMEZONE)
+  
+  # Hardcoded stuff from "./configure" of libpq
+  set(MEMSET_LOOP_LIMIT 1024)
+  set(BLCKSZ 8192)
+  set(XLOG_BLCKSZ 8192)
+  set(DEF_PGPORT 5432)
+  set(DEF_PGPORT_STR "\"${DEF_PGPORT}\"")
+  set(PG_KRB_SRVNAM "\"postgres\"")
 
-  endif()
+  # Assume that zlib and openssl are always present
+  set(HAVE_LIBZ 1)
+  set(HAVE_LIBSSL 1)
+  set(HAVE_OPENSSL_INIT_SSL 1)
+  set(USE_OPENSSL 1)
+  set(USE_OPENSSL_RANDOM 1)
+  
+  PrepareCMakeConfigurationFile(
+    ${LIBPQ_SOURCES_DIR}/src/include/pg_config_ext.h.in
+    ${AUTOGENERATED_DIR}/pg_config_ext.h.in)
+  
+  PrepareCMakeConfigurationFile(
+    ${LIBPQ_SOURCES_DIR}/src/include/pg_config.h.in
+    ${AUTOGENERATED_DIR}/pg_config.h.in)
+  
+  configure_file(
+    ${AUTOGENERATED_DIR}/pg_config_ext.h.in
+    ${AUTOGENERATED_DIR}/pg_config_ext.h)
+
+  configure_file(
+    ${AUTOGENERATED_DIR}/pg_config.h.in
+    ${AUTOGENERATED_DIR}/pg_config.h)
 
 
 
@@ -316,6 +325,7 @@
     ${LIBPQ_SOURCES_DIR}/src/port/chklocale.c
     ${LIBPQ_SOURCES_DIR}/src/port/explicit_bzero.c
     ${LIBPQ_SOURCES_DIR}/src/port/getaddrinfo.c
+    ${LIBPQ_SOURCES_DIR}/src/port/getpeereid.c
     ${LIBPQ_SOURCES_DIR}/src/port/inet_net_ntop.c
     ${LIBPQ_SOURCES_DIR}/src/port/noblock.c
     ${LIBPQ_SOURCES_DIR}/src/port/pg_strong_random.c
@@ -323,15 +333,11 @@
     ${LIBPQ_SOURCES_DIR}/src/port/pqsignal.c
     ${LIBPQ_SOURCES_DIR}/src/port/snprintf.c
     ${LIBPQ_SOURCES_DIR}/src/port/strerror.c
+    ${LIBPQ_SOURCES_DIR}/src/port/strlcpy.c
     ${LIBPQ_SOURCES_DIR}/src/port/thread.c
     )
 
-  if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
-    LIST(APPEND LIBPQ_SOURCES
-      ${LIBPQ_SOURCES_DIR}/src/port/strlcpy.c
-      )      
-
-  elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows")
+  if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
     link_libraries(secur32)
     
     include_directories(
@@ -340,47 +346,28 @@
       )
     
     LIST(APPEND LIBPQ_SOURCES
-      # libpgport C files that are needed if identified by configure
+      ${LIBPQ_SOURCES_DIR}/src/interfaces/libpq/pthread-win32.c
       ${LIBPQ_SOURCES_DIR}/src/interfaces/libpq/win32.c
-      ${LIBPQ_SOURCES_DIR}/src/port/crypt.c 
+      ${LIBPQ_SOURCES_DIR}/src/port/dirmod.c
       ${LIBPQ_SOURCES_DIR}/src/port/inet_aton.c
       ${LIBPQ_SOURCES_DIR}/src/port/open.c
       ${LIBPQ_SOURCES_DIR}/src/port/pgsleep.c
-      ${LIBPQ_SOURCES_DIR}/src/port/snprintf.c
-      ${LIBPQ_SOURCES_DIR}/src/port/system.c 
+      ${LIBPQ_SOURCES_DIR}/src/port/system.c
+      ${LIBPQ_SOURCES_DIR}/src/port/win32error.c
       ${LIBPQ_SOURCES_DIR}/src/port/win32setlocale.c
-      ${LIBPQ_SOURCES_DIR}/src/port/getaddrinfo.c
-      ${LIBPQ_SOURCES_DIR}/src/port/strlcpy.c
       )
-      
-    if (CMAKE_COMPILER_IS_GNUCXX OR 
-        (MSVC AND MSVC_VERSION GREATER 1800))
-      # Starting Visual Studio 2013 (version 1800), it is necessary to also add "win32error.c"
-      LIST(APPEND LIBPQ_SOURCES ${LIBPQ_SOURCES_DIR}/src/port/win32error.c)
-    endif()
 
     if (MSVC)
-      LIST(APPEND LIBPQ_SOURCES ${LIBPQ_SOURCES_DIR}/src/interfaces/libpq/pthread-win32.c)
+      include_directories(
+        ${LIBPQ_SOURCES_DIR}/src/include/port/win32_msvc
+        )
+      
+      LIST(APPEND LIBPQ_SOURCES
+        ${LIBPQ_SOURCES_DIR}/src/port/dirent.c 
+        )
     endif()
   endif()
 
-  if (CMAKE_COMPILER_IS_GNUCXX AND
-      NOT CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
-    LIST(APPEND LIBPQ_SOURCES
-      ${LIBPQ_SOURCES_DIR}/src/port/getpeereid.c
-      )
-
-  elseif (MSVC)
-    include_directories(
-      ${LIBPQ_SOURCES_DIR}/src/include/port/win32_msvc
-      )
-    
-    LIST(APPEND LIBPQ_SOURCES
-      ${LIBPQ_SOURCES_DIR}/src/port/dirent.c 
-      ${LIBPQ_SOURCES_DIR}/src/port/dirmod.c 
-      )
-  endif()
-
   source_group(ThirdParty\\PostgreSQL REGULAR_EXPRESSION ${LIBPQ_SOURCES_DIR}/.*)
 
 else()