Mercurial > hg > orthanc-postgresql
changeset 139:171da992b0a5
trying autodetection of compiler features
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 23 Aug 2017 17:41:16 +0200 (2017-08-23) |
parents | 4968c70ba17e |
children | 2b4bc54f9627 |
files | CMakeLists.txt NEWS Resources/CMake/PostgreSQLConfiguration.cmake Resources/Platforms/PrepareCMakeConfigurationFile.py UnitTestsSources/PostgreSQLTests.cpp |
diffstat | 5 files changed, 177 insertions(+), 127 deletions(-) [+] |
line wrap: on
line diff
--- a/CMakeLists.txt Wed Aug 23 16:53:45 2017 +0200 +++ b/CMakeLists.txt Wed Aug 23 17:41:16 2017 +0200 @@ -54,8 +54,8 @@ # The CMake script in "Graveyard" was used up to release 2.0. The new # script makes auto-configuration of the variables. -#include(${CMAKE_SOURCE_DIR}/Resources/CMake/PostgreSQLConfiguration.cmake) -include(${CMAKE_SOURCE_DIR}/Resources/Graveyard/PostgreSQLConfiguration.cmake) +include(${CMAKE_SOURCE_DIR}/Resources/CMake/PostgreSQLConfiguration.cmake) +#include(${CMAKE_SOURCE_DIR}/Resources/Graveyard/PostgreSQLConfiguration.cmake) include(${ORTHANC_ROOT}/Resources/CMake/JsonCppConfiguration.cmake) include(${ORTHANC_ROOT}/Resources/CMake/BoostConfiguration.cmake)
--- a/NEWS Wed Aug 23 16:53:45 2017 +0200 +++ b/NEWS Wed Aug 23 17:41:16 2017 +0200 @@ -4,7 +4,7 @@ * Upgrade to PostgreSQL 9.6.1 client library for static builds * Performance warning if runtime debug assertions are turned on * Fix issue 62 (use correct type for lo_read() value) -* Support of OpenBSD 64bit +* Support of OpenBSD and FreeBSD Release 2.0 (2015/12/02)
--- a/Resources/CMake/PostgreSQLConfiguration.cmake Wed Aug 23 16:53:45 2017 +0200 +++ b/Resources/CMake/PostgreSQLConfiguration.cmake Wed Aug 23 17:41:16 2017 +0200 @@ -41,31 +41,12 @@ "http://www.orthanc-server.com/downloads/third-party/postgresql-${LIBPQ_VERSION}.tar.gz" "${LIBPQ_SOURCES_DIR}") - if (MSVC) - configure_file( - ${LIBPQ_SOURCES_DIR}/src/include/pg_config.h.win32 - ${AUTOGENERATED_DIR}/pg_config.h - COPYONLY) - - configure_file( - ${LIBPQ_SOURCES_DIR}/src/include/pg_config_ext.h.win32 - ${AUTOGENERATED_DIR}/pg_config_ext.h - COPYONLY) - else() - - endif() - - if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows") - set(LIBPQ_CONFIG_H ${LIBPQ_SOURCES_DIR}/src/include/pg_config.h.win32) - - else() - if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") - set(LIBPQ_CONFIG_H ${CMAKE_SOURCE_DIR}/Resources/Platforms/pg_config-windows64.h) - else() - set(LIBPQ_CONFIG_H ${CMAKE_SOURCE_DIR}/Resources/Platforms/pg_config-windows32.h) - endif() - endif() - + + ## + ## Platform-specific configuration + ## + + if (CMAKE_SYSTEM_NAME STREQUAL "Windows") add_definitions( -DEXEC_BACKEND ) @@ -75,7 +56,7 @@ ${AUTOGENERATED_DIR}/pg_config_os.h COPYONLY) - elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux") add_definitions( -D_GNU_SOURCE -D_THREAD_SAFE @@ -87,13 +68,7 @@ ${AUTOGENERATED_DIR}/pg_config_os.h COPYONLY) - elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") - if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") - set(LIBPQ_CONFIG_H ${CMAKE_SOURCE_DIR}/Resources/Platforms/pg_config-darwin64.h) - else() - message(FATAL_ERROR "Support your platform here") - endif() - + elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin") add_definitions( -D_GNU_SOURCE -D_THREAD_SAFE @@ -105,105 +80,147 @@ ${AUTOGENERATED_DIR}/pg_config_os.h COPYONLY) - elseif (${CMAKE_SYSTEM_NAME} STREQUAL "OpenBSD") - if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") - set(LIBPQ_CONFIG_H ${CMAKE_SOURCE_DIR}/Resources/Platforms/pg_config-openbsd64.h) - else() - message(FATAL_ERROR "Support your platform here") - endif() - + elseif (CMAKE_SYSTEM_NAME STREQUAL "OpenBSD") configure_file( ${LIBPQ_SOURCES_DIR}/src/include/port/openbsd.h ${AUTOGENERATED_DIR}/pg_config_os.h COPYONLY) + elseif (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") + configure_file( + ${LIBPQ_SOURCES_DIR}/src/include/port/freebsd.h + ${AUTOGENERATED_DIR}/pg_config_os.h + COPYONLY) + else() message(FATAL_ERROR "Support your platform here") endif() - configure_file( - ${LIBPQ_CONFIG_H} - ${AUTOGENERATED_DIR}/pg_config.h - COPYONLY - ) + ## + ## 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) + + 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() + + else() + configure_file( + ${CMAKE_SOURCE_DIR}/Resources/Platforms/pg_config_ext.h + ${AUTOGENERATED_DIR}/pg_config_ext.h + COPYONLY + ) + + set(CMAKE_EXTRA_INCLUDE_FILES "sys/socket.h;netdb.h;sys/types.h") + + check_type_size("long int" SIZE_LONG_INT) + if (SIZE_LONG_INT EQUAL 8) + set(HAVE_LONG_INT_64 1) + endif() + + check_type_size("long long int" SIZE_LONG_LONG_INT) + if (SIZE_LONG_LONG_INT EQUAL 8) + set(HAVE_LONG_LONG_INT_64 1) + endif() + + file(READ ${CMAKE_SOURCE_DIR}/Resources/Platforms/c_flexmember.c SOURCE) + check_c_source_compiles("${SOURCE}" c_flexmember) + if (c_flexmember) + set(FLEXIBLE_ARRAY_MEMBER 1) + endif() + + file(READ ${CMAKE_SOURCE_DIR}/Resources/Platforms/printf_archetype.c SOURCE) + check_c_source_compiles("${SOURCE}" printf_archetype) + if (printf_archetype) + set(PG_PRINTF_ATTRIBUTE "gnu_printf") + else() + set(PG_PRINTF_ATTRIBUTE "printf") + endif() + + check_function_exists("unsetenv" HAVE_UNSETENV) + check_function_exists("getaddrinfo" HAVE_GETADDRINFO) + check_function_exists("gettimeofday" HAVE_GETTIMEOFDAY) + + check_type_size("struct addrinfo" SIZE_STRUCT_ADDRINFO) + if (HAVE_SIZE_STRUCT_ADDRINFO) + set(HAVE_STRUCT_ADDRINFO 1) + endif() + + check_type_size("struct sockaddr_storage" SIZE_STRUCT_SOCKADDR_STORAGE) + if (HAVE_SIZE_STRUCT_SOCKADDR_STORAGE) + set(HAVE_STRUCT_SOCKADDR_STORAGE 1) + endif() + + set(MEMSET_LOOP_LIMIT 1024) # This is hardcoded in "postgresql-9.6.1/configure" + set(DEF_PGPORT 5432) # Default port number of PostgreSQL + set(DEF_PGPORT_STR "\"5432\"") # Same as above, as a string + set(PG_VERSION "\"${LIBPQ_VERSION}\"") # Version of PostgreSQL, as a string + + # Version of PostgreSQL, as a number + math(EXPR PG_VERSION_NUM "${LIBPQ_MAJOR} * 10000 + ${LIBPQ_MINOR} * 100 + ${LIBPQ_REVISION}") + + set(HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY 1) # TODO + set(HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN 1) # TODO + set(ACCEPT_TYPE_ARG3 socklen_t) # TODO + + # Compute maximum alignment of any basic type. + # We assume long's alignment is at least as strong as char, short, or int; + # but we must check long long (if it exists) and double. + check_type_size("long" SIZE_LONG) + check_type_size("long long" SIZE_LONG_LONG) + check_type_size("double" SIZE_DOUBLE) + set(MAXIMUM_ALIGNOF ${SIZE_LONG}) + if(SIZE_LONG_LONG AND SIZE_LONG_LONG GREATER MAXIMUM_ALIGNOF) + set(MAXIMUM_ALIGNOF ${SIZE_LONG_LONG}) + endif() + if(SIZE_DOUBLE GREATER MAXIMUM_ALIGNOF) + set(MAXIMUM_ALIGNOF ${SIZE_DOUBLE}) + endif() - - set(CMAKE_EXTRA_INCLUDE_FILES "sys/socket.h;netdb.h;sys/types.h") - - check_type_size("long int" SIZE_LONG_INT) - if (SIZE_LONG_INT EQUAL 8) - set(HAVE_LONG_INT_64 1) - endif() - - file(READ ${CMAKE_SOURCE_DIR}/Resources/Platforms/c_flexmember.c SOURCE) - check_c_source_compiles("${SOURCE}" c_flexmember) - if (c_flexmember) - set(FLEXIBLE_ARRAY_MEMBER 1) - endif() - - file(READ ${CMAKE_SOURCE_DIR}/Resources/Platforms/printf_archetype.c SOURCE) - check_c_source_compiles("${SOURCE}" printf_archetype) - if (printf_archetype) - set(PG_PRINTF_ATTRIBUTE "gnu_printf") - else() - set(PG_PRINTF_ATTRIBUTE "printf") - endif() - - check_function_exists("unsetenv" HAVE_UNSETENV) - check_function_exists("getaddrinfo" HAVE_GETADDRINFO) - - check_type_size("struct addrinfo" SIZE_STRUCT_ADDRINFO) - if (HAVE_SIZE_STRUCT_ADDRINFO) - set(HAVE_STRUCT_ADDRINFO 1) - endif() + execute_process( + COMMAND + ${PYTHON_EXECUTABLE} + "${CMAKE_SOURCE_DIR}/Resources/Platforms/PrepareCMakeConfigurationFile.py" + "${LIBPQ_SOURCES_DIR}/src/include/pg_config.h.in" + "${AUTOGENERATED_DIR}/pg_config.h.in" + ERROR_VARIABLE NO_PG_CONFIG + OUTPUT_VARIABLE out + ) - check_type_size("struct sockaddr_storage" SIZE_STRUCT_SOCKADDR_STORAGE) - if (HAVE_SIZE_STRUCT_SOCKADDR_STORAGE) - set(HAVE_STRUCT_SOCKADDR_STORAGE 1) + if (NO_PG_CONFIG) + message(FATAL_ERROR "Cannot find pg_config.h.in") + endif() + + configure_file( + ${AUTOGENERATED_DIR}/pg_config.h.in + ${AUTOGENERATED_DIR}/pg_config.h) endif() - set(MEMSET_LOOP_LIMIT 1024) # This is hardcoded in "postgresql-9.6.1/configure" - set(DEF_PGPORT 5432) # Default port number of PostgreSQL - set(DEF_PGPORT_STR "\"5432\"") # Same as above, as a string - set(PG_VERSION "\"${LIBPQ_VERSION}\"") # Version of PostgreSQL, as a string - - # Version of PostgreSQL, as a number - math(EXPR PG_VERSION_NUM "${LIBPQ_MAJOR} * 10000 + ${LIBPQ_MINOR} * 100 + ${LIBPQ_REVISION}") - - set(HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY 1) # TODO - set(HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN 1) # TODO - set(ACCEPT_TYPE_ARG3 socklen_t) # TODO - - # Compute maximum alignment of any basic type. - # We assume long's alignment is at least as strong as char, short, or int; - # but we must check long long (if it exists) and double. - check_type_size("long" SIZE_LONG) - check_type_size("long long" SIZE_LONG_LONG) - check_type_size("double" SIZE_DOUBLE) - set(MAXIMUM_ALIGNOF ${SIZE_LONG}) - if(SIZE_LONG_LONG AND SIZE_LONG_LONG GREATER MAXIMUM_ALIGNOF) - set(MAXIMUM_ALIGNOF ${SIZE_LONG_LONG}) - endif() - if(SIZE_DOUBLE GREATER MAXIMUM_ALIGNOF) - set(MAXIMUM_ALIGNOF ${SIZE_DOUBLE}) - endif() - - - configure_file( - /tmp/toto.h - ${AUTOGENERATED_DIR}/pg_config.h) - - - - configure_file( - ${CMAKE_SOURCE_DIR}/Resources/Platforms/pg_config_ext.h - ${AUTOGENERATED_DIR}/pg_config_ext.h - COPYONLY - ) + ## + ## Generic configuration + ## file(WRITE ${AUTOGENERATED_DIR}/pg_config_paths.h @@ -250,12 +267,12 @@ ) - if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + if (CMAKE_SYSTEM_NAME STREQUAL "Linux") LIST(APPEND LIBPQ_SOURCES ${LIBPQ_SOURCES_DIR}/src/port/strlcpy.c ) - elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Windows") + elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows") include_directories( ${LIBPQ_SOURCES_DIR}/src/include/port/win32 ${LIBPQ_SOURCES_DIR}/src/port @@ -286,13 +303,13 @@ endif() endif() - if (${CMAKE_COMPILER_IS_GNUCXX}) - if (NOT CMAKE_SYSTEM_NAME STREQUAL "OpenBSD") - LIST(APPEND LIBPQ_SOURCES - ${LIBPQ_SOURCES_DIR}/src/port/getpeereid.c - ) - endif() - elseif (${MSVC}) + 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 )
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Platforms/PrepareCMakeConfigurationFile.py Wed Aug 23 17:41:16 2017 +0200 @@ -0,0 +1,20 @@ +#!/usr/bin/python + +import re +import sys + +if len(sys.argv) != 3: + raise Exception('Bad number of arguments') + +r = re.compile(r'^#undef ([A-Z0-9_]+)$') + +with open(sys.argv[1], 'r') as f: + with open(sys.argv[2], 'w') as g: + for l in f.readlines(): + m = r.match(l) + if m != None: + s = m.group(1) + g.write('#cmakedefine %s @%s@\n' % (s, s)) + else: + g.write(l) +
--- a/UnitTestsSources/PostgreSQLTests.cpp Wed Aug 23 16:53:45 2017 +0200 +++ b/UnitTestsSources/PostgreSQLTests.cpp Wed Aug 23 17:41:16 2017 +0200 @@ -21,6 +21,19 @@ #include <gtest/gtest.h> +#if defined(_WIN32) +// Fix redefinition of symbols on MinGW (these symbols are manually +// defined both by PostgreSQL and Google Test) +# undef S_IRGRP +# undef S_IROTH +# undef S_IRWXG +# undef S_IRWXO +# undef S_IWGRP +# undef S_IWOTH +# undef S_IXGRP +# undef S_IXOTH +#endif + #include <boost/lexical_cast.hpp> #include "../Core/PostgreSQLTransaction.h"