Skip to content

Instantly share code, notes, and snippets.

@stalkerg
Last active October 9, 2017 23:22
Show Gist options
  • Save stalkerg/9da894195628d24b3cf25f399af3714e to your computer and use it in GitHub Desktop.
Save stalkerg/9da894195628d24b3cf25f399af3714e to your computer and use it in GitHub Desktop.
cmake_10_v2
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000000..795f34db48
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,1429 @@
+cmake_minimum_required(VERSION 2.8.4)
+
+project(Postgres C)
+
+include(CheckTypeSize)
+include(CheckSymbolExists)
+include(CheckFunctionExists)
+include(CheckIncludeFiles)
+include(CheckCSourceCompiles)
+include(CheckCSourceRuns)
+include(TestBigEndian)
+include(CheckStructHasMember)
+
+if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
+ message(STATUS "${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}")
+ message(FATAL_ERROR "You must use another folder for build PostgreSQL")
+endif()
+
+set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
+
+set(POSTGRES_MAJOR_VERSION 10)
+set(POSTGRES_MINOR_VERSION 0)
+set(POSTGRES_PATCH_VERSION 0)
+set(POSTGRES_VERSION
+ ${POSTGRES_MAJOR_VERSION}.${POSTGRES_MINOR_VERSION}.${POSTGRES_PATCH_VERSION})
+
+set(PG_VERSION "10.0")
+set(PG_VERSION_NUM 100000)
+set(PACKAGE_BUGREPORT "pgsql-bugs@postgresql.org")
+
+ # Offer the user the choice of overriding the installation directories
+set(INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries")
+set(INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables")
+set(INSTALL_INCLUDE_DIR include CACHE PATH
+ "Installation directory for header files")
+
+if(NOT PGBINDIR)
+ set(PGBINDIR "${CMAKE_INSTALL_PREFIX}/bin")
+endif(NOT PGBINDIR)
+
+if(NOT PGSHAREDIR)
+ set(PGSHAREDIR "${CMAKE_INSTALL_PREFIX}/share/postgresql")
+endif(NOT PGSHAREDIR)
+
+if(NOT SYSCONFDIR)
+ set(SYSCONFDIR "${CMAKE_INSTALL_PREFIX}/etc")
+endif(NOT SYSCONFDIR)
+
+if(NOT INCLUDEDIR)
+ set(INCLUDEDIR "${CMAKE_INSTALL_PREFIX}/include")
+endif(NOT INCLUDEDIR)
+
+if(NOT PKGINCLUDEDIR)
+ set(PKGINCLUDEDIR "${CMAKE_INSTALL_PREFIX}/include")
+endif(NOT PKGINCLUDEDIR)
+
+if(NOT INCLUDEDIRSERVER)
+ set(INCLUDEDIRSERVER "${CMAKE_INSTALL_PREFIX}/include/server")
+endif(NOT INCLUDEDIRSERVER)
+
+if(MSVC)
+ if(NOT LIBDIR)
+ set(LIBDIR "${CMAKE_INSTALL_PREFIX}/bin")
+ endif(NOT LIBDIR)
+
+ if(NOT PKGLIBDIR)
+ set(PKGLIBDIR "${CMAKE_INSTALL_PREFIX}/bin")
+ endif(NOT PKGLIBDIR)
+else()
+ if(NOT LIBDIR)
+ set(LIBDIR "${CMAKE_INSTALL_PREFIX}/lib")
+ endif(NOT LIBDIR)
+
+ if(NOT PKGLIBDIR)
+ set(PKGLIBDIR "${CMAKE_INSTALL_PREFIX}/lib")
+ endif(NOT PKGLIBDIR)
+endif()
+
+if(NOT LOCALEDIR)
+ set(LOCALEDIR "${CMAKE_INSTALL_PREFIX}/share/locale")
+endif(NOT LOCALEDIR)
+
+if(NOT DOCDIR)
+ set(DOCDIR "${CMAKE_INSTALL_PREFIX}/share/doc/")
+endif(NOT DOCDIR)
+
+if(NOT HTMLDIR)
+ set(HTMLDIR "${CMAKE_INSTALL_PREFIX}/share/doc/")
+endif(NOT HTMLDIR)
+
+if(NOT MANDIR)
+ set(MANDIR "${CMAKE_INSTALL_PREFIX}/share/man")
+endif(NOT MANDIR)
+
+if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
+ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -multiply_defined suppress -undefined dynamic_lookup")
+ set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -multiply_defined suppress -undefined dynamic_lookup")
+endif()
+
+if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD|NetBSD|OpenBSD")
+ set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-Wl,-x,-soname,")
+endif()
+
+set(PLUGIN_TYPE MODULE)
+
+if(MSVC)
+ # Try hide warnings
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D_CRT_SECURE_NO_WARNINGS /D_SCL_SECURE_NO_WARNINGS ")
+ option(USE_FP_STRICT "use strict mode for float and double in MSVC" ON)
+ if (USE_FP_STRICT)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /fp:strict")
+ endif()
+ # We can't use MODULE because CMake get export symbols only for SHARED.
+ set(PLUGIN_TYPE SHARED)
+endif()
+
+if(CMAKE_SYSTEM_NAME STREQUAL "AIX" AND "${CMAKE_C_FLAGS}" MATCHES "aix64")
+ SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> <LINK_FLAGS> -X64 cr <TARGET> <OBJECTS>")
+ SET(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> <LINK_FLAGS> -X64 r <TARGET> <OBJECTS>")
+endif()
+
+test_big_endian(WORDS_BIGENDIAN)
+set(FIND_LIBRARY_USE_LIB64_PATHS ON)
+
+find_package(Perl REQUIRED)
+option(WITH_PERL "libperl is optional" OFF)
+if(WITH_PERL)
+ find_package(PerlLibs)
+endif()
+if(PERLLIBS_FOUND)
+ EXECUTE_PROCESS(COMMAND ${PERL_EXECUTABLE} -MExtUtils::Embed -e ccopts OUTPUT_VARIABLE PERL_CFLAGS)
+ EXECUTE_PROCESS(COMMAND ${PERL_EXECUTABLE} -MExtUtils::Embed -e ldopts OUTPUT_VARIABLE PERL_LDFLAGS)
+ STRING(REGEX REPLACE "[\r\n]" " " PERL_CFLAGS ${PERL_CFLAGS})
+ STRING(REGEX REPLACE " +$" "" PERL_CFLAGS ${PERL_CFLAGS})
+ STRING(STRIP "${PERL_CFLAGS}" PERL_CFLAGS)
+ STRING(REGEX REPLACE "[\r\n]" " " PERL_LDFLAGS ${PERL_LDFLAGS})
+ STRING(REGEX REPLACE " +$" "" PERL_LDFLAGS ${PERL_LDFLAGS})
+ STRING(REGEX REPLACE "-lperl" "" PERL_LDFLAGS ${PERL_LDFLAGS})
+ if(MINGW AND NOT MSYS)
+ STRING(REGEX REPLACE "\\\\" "/" PERL_LDFLAGS ${PERL_LDFLAGS})
+ endif()
+ STRING(STRIP "${PERL_LDFLAGS}" PERL_LDFLAGS)
+endif()
+
+option(WITH_TAP "try enable TAP tests" OFF)
+# It's really pain to use the TAP tests without env cmake command
+if (CMAKE_VERSION VERSION_GREATER "3.2.0")
+ find_program(PROVE prove)
+endif()
+if(NOT WITH_TAP)
+ set(PROVE "")
+endif()
+
+find_package(BISON REQUIRED)
+find_package(FLEX REQUIRED)
+find_package(Threads)
+
+option(WITH_OPENSSL "OPENSSL is optional" OFF)
+if(WITH_OPENSSL)
+ find_package(OpenSSL)
+endif()
+find_package(ZLIB)
+
+option(WITH_PYTHON "Python is optional" OFF)
+if(WITH_PYTHON)
+ find_package(PythonInterp)
+ find_package(PythonLibs)
+endif()
+find_package(SELinux)
+
+option(WITH_LIBXML "LIBXML is optional" OFF)
+if(WITH_LIBXML)
+ find_package(LibXml2)
+ find_package(LibXslt)
+endif()
+
+option(WITH_TCL "TCL is optional" OFF)
+if(WITH_TCL)
+ find_package(TCL)
+endif()
+find_package(LibSocket)
+
+option(WITH_ICU "ICU is optional" OFF)
+if(WITH_ICU)
+ find_package(ICU 4.0 COMPONENTS i18n REQUIRED)
+endif()
+if(ICU_FOUND)
+ set(CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES};${ICU_INCLUDE_DIRS}")
+ check_include_files(unicode/ucol.h HAVE_UCOL_H)
+ if(NOT HAVE_UCOL_H)
+ message(FATAL_ERROR "unicode/ucol.h not found")
+ endif()
+ set(USE_ICU 1)
+endif()
+option(USE_PAM "build with PAM support" OFF)
+if(USE_PAM)
+ find_library(PAM_LIB pam)
+ if(NOT PAM_LIB)
+ message(ERROR "library 'pam' is required for PAM")
+ endif()
+endif()
+
+option(USE_LDAP "build with LDAP support" OFF)
+if(USE_LDAP)
+ find_package(LDAP REQUIRED)
+endif()
+
+if(WIN32 OR MINGW)
+ set(NEED_REPL_SNPRINTF ON)
+else()
+ set(NEED_REPL_SNPRINTF OFF)
+endif()
+
+option(ENABLE_NLS "Define if you want National Language Support" OFF)
+if(ENABLE_NLS)
+ include(MakeNLS)
+ find_package(Gettext REQUIRED)
+ find_program(GETTEXT_XGETTEXT_EXECUTABLE xgettext)
+ if(NOT GETTEXT_XGETTEXT_EXECUTABLE)
+ message(FATAL_ERROR "xgettext not found")
+ endif(NOT GETTEXT_XGETTEXT_EXECUTABLE)
+ if(NOT NLS_LANGUAGES)
+ set(NLS_LANGUAGES "ko;cs;pt_BR;zh_CN;ru;fr;de;es;it;tr;ja;pl;zh_TW")
+ endif()
+
+ if(NOT NEED_REPL_SNPRINTF)
+ check_c_source_runs("
+ #include <stdio.h>
+ #include <string.h>
+
+ int main()
+ {
+ char buf[100];
+
+ /* can it swap arguments? */
+ snprintf(buf, 100, \"%2\$d %1\$d\", 3, 4);
+ if (strcmp(buf, \"4 3\") != 0)
+ return 1;
+ return 0;
+ }
+ " SNPRINTF_ARG_CONTROL)
+ if(NOT SNPRINTF_ARG_CONTROL)
+ set(NEED_REPL_SNPRINTF ON)
+ endif()
+ endif()
+endif()
+
+option(ENABLE_GSS "Define to build with GSSAPI support." OFF)
+if(ENABLE_GSS)
+ check_include_files(gssapi/gssapi.h HAVE_GSSAPI_GSSAPI_H)
+ check_include_files(gssapi.h HAVE_GSSAPI_H)
+ set(PG_KRB_SRVTAB "FILE:${SYSCONFDIR}/krb5.keytab")
+ if(WIN32)
+ SET(GSS_LIBS "-lgssapi32")
+ else()
+ set(CMAKE_REQUIRED_LIBRARIES_OLD ${CMAKE_REQUIRED_LIBRARIES})
+ set(CMAKE_REQUIRED_LIBRARIES "-lgssapi_krb5")
+ check_function_exists(gss_init_sec_context HAVE_GSS_INIT)
+ if(NOT HAVE_GSS_INIT)
+ set(CMAKE_REQUIRED_LIBRARIES "-lgss")
+ check_function_exists(gss_init_sec_context HAVE_GSS_INIT)
+ if(NOT HAVE_GSS_INIT)
+ set(CMAKE_REQUIRED_LIBRARIES "-lgssapi -lkrb5 -lcrypto")
+ check_function_exists(gss_init_sec_context HAVE_GSS_INIT)
+ endif(NOT HAVE_GSS_INIT)
+ endif(NOT HAVE_GSS_INIT)
+ if(HAVE_GSS_INIT)
+ set(GSS_LIBS ${CMAKE_REQUIRED_LIBRARIES})
+ else()
+ message(FATAL_ERROR "Not found gss_init_sec_context function for GSSAPI")
+ endif()
+ set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_OLD})
+ endif()
+else()
+ set(GSS_LIBS "")
+endif()
+
+option(USE_SYSTEMD "Define to build with systemd support" OFF)
+option(USE_BSD_AUTH "Define to build with BSD Authentication support" OFF)
+option(USE_ASSERT_CHECKING "Define to build with assertion checks." OFF)
+option(USE_BONJOUR "Define to build with Bonjour support." OFF)
+if(USE_BONJOUR)
+ check_include_files(dns_sd.h HAVE_DNS_SD_H)
+ if(NOT HAVE_DNS_SD_H)
+ message(FATAL_ERROR "header file <dns_sd.h> is required for Bonjour")
+ endif()
+endif()
+
+option(STRONG_RANDOM "Strong random number source" ON)
+option(STRONG_RANDOM_SOURCE "which random number source to use - openssl, win32, dev" OFF)
+if(STRONG_RANDOM)
+ if(NOT STRONG_RANDOM_SOURCE)
+ if(WITH_OPENSSL)
+ set(STRONG_RANDOM_SOURCE "openssl")
+ elseif(WIN32)
+ set(STRONG_RANDOM_SOURCE "win32")
+ elseif(EXISTS "/dev/urandom")
+ set(STRONG_RANDOM_SOURCE "dev")
+ endif()
+ endif()
+ if(STRONG_RANDOM_SOURCE STREQUAL "openssl")
+ set(USE_OPENSSL_RANDOM 1)
+ elseif(STRONG_RANDOM_SOURCE STREQUAL "win32")
+ set(USE_WIN32_RANDOM 1)
+ elseif(STRONG_RANDOM_SOURCE STREQUAL "dev")
+ set(USE_DEV_URANDOM 1)
+ else()
+ message(ERROR "no source of strong random numbers was found
+PostgreSQL can use OpenSSL or /dev/urandom as a source of random numbers,
+for authentication protocols. You can use -DSTRONG_RANDOM=OFF to use of a built-in
+pseudo random number generator, but that may be insecure.")
+ endif()
+
+ set(HAVE_STRONG_RANDOM 1)
+else()
+ message(WARNING "Not using a strong random number source may be insecure.")
+endif()
+
+if(NOT MSVC)
+ find_library(DL_LIBRARIES NAMES dl)
+ find_library(M_LIB m)
+ if(NOT M_LIB)
+ set(M_LIB "")
+ endif()
+endif()
+
+if(NOT DL_LIBRARIES)
+ set(DL_LIBRARIES "")
+endif()
+
+if(LIBXML2_FOUND)
+ set(HAVE_LIBXML2 1)
+ set(USE_LIBXML 1)
+endif()
+
+if(LIBXSLT_FOUND)
+ set(HAVE_LIBXSLT 1)
+ set(USE_LIBXSLT 1)
+endif()
+
+if(ZLIB_FOUND)
+ set(HAVE_LIBZ 1)
+endif()
+
+if(NOT CMAKE_C_FLAGS)
+ set(CMAKE_C_FLAGS "-O2")
+endif()
+
+if(CMAKE_COMPILER_IS_GNUCC)
+ if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 3.3 OR CMAKE_C_COMPILER_VERSION VERSION_EQUAL 3.3)
+ # Disable strict-aliasing rules; needed for gcc 3.3+
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing")
+ endif()
+
+ if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 3.4 OR CMAKE_C_COMPILER_VERSION VERSION_EQUAL 3.4)
+ # Disable FP optimizations that cause various errors on gcc 4.5+ or maybe 4.6+
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fwrapv")
+ endif()
+
+ if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.5 OR CMAKE_C_COMPILER_VERSION VERSION_EQUAL 4.5)
+ # Disable FP optimizations that cause various errors on gcc 4.5+ or maybe 4.6+
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexcess-precision=standard")
+ endif()
+
+ # Optimization flags for specific files that benefit from vectorization
+ set(CFLAGS_VECTOR "${CFLAGS_VECTOR} -funroll-loops")
+ if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.5 OR CMAKE_C_COMPILER_VERSION VERSION_EQUAL 4.5)
+ set(CFLAGS_VECTOR "${CFLAGS_VECTOR} -ftree-vectorize")
+ endif()
+
+ option(PROFILE_PID_DIR "Enable to allow profiling output to be saved separately for each process." OFF)
+endif()
+
+if(CMAKE_C_COMPILER_ID MATCHES "Clang")
+ # Disable strict-aliasing rules; needed for gcc 3.3+
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing")
+ # Disable FP optimizations that cause various errors on gcc 4.5+ or maybe 4.6+
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fwrapv")
+
+ # Optimization flags for specific files that benefit from vectorization
+ set(CFLAGS_VECTOR "${CFLAGS_VECTOR} -funroll-loops")
+ set(CFLAGS_VECTOR "${CFLAGS_VECTOR} -ftree-vectorize")
+endif()
+
+if(CMAKE_C_COMPILER_ID STREQUAL "Intel")
+ # Intel's compiler has a bug/misoptimization in checking for
+ # division by NAN (NaN == 0), -mp1 fixes it, so add it to the CFLAGS.
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mp1")
+ # Make sure strict aliasing is off (though this is said to be the default)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing")
+endif()
+
+check_symbol_exists(strlcpy "stdio.h;string.h" HAVE_DECL_STRLCPY)
+if(NOT HAVE_DECL_STRLCPY)
+ set(HAVE_DECL_STRLCPY 0)
+endif()
+check_symbol_exists(strlcat "stdio.h;string.h" HAVE_DECL_STRLCAT)
+if(NOT HAVE_DECL_STRLCAT)
+ set(HAVE_DECL_STRLCAT 0)
+endif()
+check_symbol_exists(snprintf "stdio.h;string.h" HAVE_DECL_SNPRINTF)
+if(NOT HAVE_DECL_SNPRINTF)
+ set(HAVE_DECL_SNPRINTF 0)
+endif()
+check_symbol_exists(vsnprintf "stdio.h;string.h" HAVE_DECL_VSNPRINTF)
+if(NOT HAVE_DECL_VSNPRINTF)
+ set(HAVE_DECL_VSNPRINTF 0)
+endif()
+check_symbol_exists(unsetenv "stdlib.h" HAVE_UNSETENV)
+check_symbol_exists(srandom "stdlib.h" HAVE_SRANDOM)
+
+# Test math functions
+check_symbol_exists(rint "math.h" HAVE_RINT)
+
+if(WIN32 AND NOT MINGW)
+ set(LIB_M "")
+else()
+ set(LIB_M m)
+endif()
+set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES} ${LIB_M}")
+check_c_source_runs("
+ #include <math.h>
+ int main(void){
+#ifdef _MSC_VER
+ return isinf(INFINITY) ? 0 : 1;
+#else
+ return isinf(1.0/0.0) ? 0 : 1;
+#endif
+ }
+" HAVE_ISINF)
+
+# Check common include files
+
+check_include_files(ieeefp.h HAVE_IEEEFP_H)
+if(NOT HAVE_IEEEFP_H)
+ set(HAVE_IEEEFP_H 0)
+else()
+ set(HAVE_IEEEFP_H 1)
+ set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};ieeefp.h")
+endif()
+
+check_include_files(fp_class.h HAVE_FP_CLASS_H)
+if (HAVE_FP_CLASS_H)
+ set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};fp_class.h")
+endif()
+set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};float.h;math.h")
+
+check_include_files(sys/un.h HAVE_SYS_UN_H)
+check_include_files(ucred.h HAVE_UCRED_H)
+check_include_files(sys/ucred.h HAVE_SYS_UCRED_H)
+check_include_files(sys/types.h HAVE_SYS_TYPES_H)
+check_include_files(sys/socket.h HAVE_SYS_SOCKET_H)
+check_include_files(sys/sockio.h HAVE_SYS_SOCKIO_H)
+check_include_files(stdint.h HAVE_STDINT_H)
+
+check_include_files(sys/select.h HAVE_SYS_SELECT_H)
+check_include_files(sys/poll.h HAVE_SYS_POLL_H)
+check_include_files(sys/epoll.h HAVE_SYS_EPOLL_H)
+check_include_files(sys/pstat.h HAVE_SYS_PSTAT_H)
+check_include_files(sys/tas.h HAVE_SYS_TAS_H)
+check_include_files(dld.h HAVE_DLD_H)
+check_include_files(langinfo.h HAVE_LANGINFO_H)
+check_include_files(poll.h HAVE_POLL_H)
+
+check_include_files(wchar.h HAVE_WCHAR_H)
+check_include_files(wctype.h HAVE_WCTYPE_H)
+check_include_files(winldap.h HAVE_WINLDAP_H)
+check_include_files(pwd.h HAVE_PWD_H)
+check_include_files(crtdefs.h HAVE_CRTDEFS_H)
+
+check_include_files(nbtool_config.h HAVE_NBTOOL_CONFIG_H)
+
+check_include_files(mbarrier.h HAVE_MBARRIER_H)
+check_include_files(atomic.h HAVE_ATOMIC_H)
+
+check_include_files(netinet/tcp.h HAVE_NETINET_TCP_H)
+check_include_files(net/if.h HAVE_NET_IF_H)
+
+check_include_files(pam/pam_appl.h HAVE_PAM_PAM_APPL_H)
+check_include_files(security/pam_appl.h HAVE_SECURITY_PAM_APPL_H)
+if(USE_PAM AND NOT (HAVE_PAM_PAM_APPL_H OR HAVE_SECURITY_PAM_APPL_H))
+ message(FATAL_ERROR "header file <security/pam_appl.h> or <pam/pam_appl.h> is required for PAM.")
+endif()
+
+check_include_files(syslog.h HAVE_SYSLOG)
+check_include_files(termios.h HAVE_TERMIOS_H)
+
+check_include_files("sys/ipc.h" HAVE_SYS_IPC_H)
+check_include_files("sys/sem.h" HAVE_SYS_SEM_H)
+check_include_files("sys/shm.h" HAVE_SYS_SHM_H)
+check_include_files("sys/ioctl.h" HAVE_SYS_IOCTL_H)
+
+check_include_files(ifaddrs.h HAVE_IFADDRS_H)
+check_include_files(crypt.h HAVE_CRYPT_H)
+check_include_files(unistd.h HAVE_UNISTD_H)
+
+check_include_files("locale.h" HAVE_LOCALE_H)
+check_include_files("xlocale.h" HAVE_XLOCALE_H)
+
+check_include_files(bsd_auth.h HAVE_BSD_AUTH_H)
+check_include_files(strings.h HAVE_STRINGS_H)
+check_include_files(string.h HAVE_STRING_H)
+check_include_files(getopt.h HAVE_GETOPT_H)
+check_include_files(sys/mman.h HAVE_SYS_MMAN_H)
+check_include_files(sys/time.h HAVE_SYS_TIME_H)
+check_include_files(sys/resource.h HAVE_SYS_RESOURCE_H)
+check_include_files(utime.h HAVE_UTIME_H)
+
+# Check functions
+
+check_function_exists(fpclass HAVE_FPCLASS) # Need for isinf implementation
+check_function_exists(fp_class HAVE_FP_CLASS)
+check_function_exists(fp_class_d HAVE_FP_CLASS_D)
+check_function_exists(class HAVE_CLASS)
+
+check_function_exists(getpeereid HAVE_GETPEEREID)
+check_function_exists(getpeerucred HAVE_GETPEERUCRED)
+check_function_exists(memmove HAVE_MEMMOVE)
+if(MSVC)
+ check_function_exists(_mbstowcs_l HAVE_MBSTOWCS_L)
+else()
+ check_function_exists(mbstowcs_l HAVE_MBSTOWCS_L)
+endif()
+
+check_function_exists(towlower HAVE_TOWLOWER)
+check_function_exists(wcstombs HAVE_WCSTOMBS)
+
+check_function_exists(mkdtemp HAVE_MKDTEMP)
+check_function_exists(mkstemp HAVE_MKSTEMP)
+check_function_exists(poll HAVE_POLL)
+
+check_function_exists(getrlimit HAVE_GETRLIMIT)
+check_function_exists(readlink HAVE_READLINK)
+check_function_exists(cbrt HAVE_CBRT)
+check_function_exists(pthread_is_threaded_np HAVE_PTHREAD_IS_THREADED_NP)
+check_function_exists(random HAVE_RANDOM)
+check_function_exists(sync_file_range HAVE_SYNC_FILE_RANGE)
+
+#So strange
+check_function_exists(pstat HAVE_PSTAT)
+
+if(HAVE_IFADDRS_H)
+ set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};ifaddrs.h")
+endif()
+check_function_exists(getifaddrs HAVE_GETIFADDRS)
+
+if(MSVC)
+ set(HAVE_MINIDUMP_TYPE 1)
+endif()
+
+if(NOT CMAKE_SYSTEM_NAME STREQUAL "SunOS")
+ set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};fcntl.h")
+ check_function_exists(posix_fadvise HAVE_DECL_POSIX_FADVISE)
+ if(HAVE_DECL_POSIX_FADVISE)
+ set(HAVE_POSIX_FADVISE 1)
+ endif()
+endif()
+
+find_library(CRYPT_LIB crypt)
+if(CRYPT_LIB)
+ set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES} ${CRYPT_LIB}")
+endif()
+
+if(HAVE_CRYPT_H)
+ set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};crypt.h")
+endif()
+check_function_exists(crypt HAVE_CRYPT)
+
+if(HAVE_UNISTD_H)
+ set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};unistd.h")
+endif()
+check_function_exists(fdatasync HAVE_DECL_FDATASYNC)
+check_function_exists(sys_siglist HAVE_DECL_FDATASYNC)
+check_function_exists(setproctitle HAVE_SETPROCTITLE)
+check_function_exists(setsid HAVE_SETSID)
+if(HAVE_UNISTD_H)
+ check_symbol_exists(sys_siglist "signal.h;unistd.h" HAVE_DECL_SYS_SIGLIST)
+ check_symbol_exists(opterr "unistd.h" HAVE_INT_OPTERR)
+ check_symbol_exists(optreset "unistd.h" HAVE_INT_OPTRESET)
+else()
+ check_symbol_exists(sys_siglist "signal.h" HAVE_DECL_SYS_SIGLIST)
+endif()
+
+set(CMAKE_MACOSX_RPATH 1)
+#set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
+
+if(MSVC)
+ check_function_exists(_fseeki64 HAVE_FSEEKO)
+else()
+ check_function_exists(fseeko HAVE_FSEEKO)
+endif()
+
+if(NOT MSVC)
+ check_include_files(dlfcn.h HAVE_DLFCN_H)
+ if(HAVE_DLFCN_H)
+ set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};dlfcn.h")
+ endif()
+ set(CMAKE_REQUIRED_LIBRARIES ${DL_LIBRARIES})
+ check_function_exists(dlopen HAVE_DLOPEN)
+endif()
+
+set(CMAKE_REQUIRED_LIBRARIES "")
+
+if(HAVE_STRINGS_H)
+ set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};strings.h")
+endif()
+if(HAVE_STRING_H)
+ set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};string.h")
+endif()
+check_function_exists(fls HAVE_FLS)
+
+if(HAVE_GETOPT_H)
+ set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};getopt.h")
+endif()
+
+check_function_exists(strtoll HAVE_STRTOLL)
+check_function_exists(strtoq HAVE_STRTOQ)
+check_function_exists(strtoull HAVE_STRTOULL)
+check_function_exists(strtouq HAVE_STRTOUQ)
+
+check_type_size("struct option" HAVE_STRUCT_OPTION)
+check_function_exists(getopt HAVE_GETOPT)
+check_function_exists(getopt_long HAVE_GETOPT_LONG)
+check_function_exists(gethostbyname_r HAVE_GETHOSTBYNAME_R)
+check_function_exists(getpwuid_r HAVE_GETPWUID_R)
+check_function_exists(strerror_r HAVE_STRERROR_R)
+check_function_exists(strerror HAVE_STRERROR)
+#I am not sure about this code.
+check_c_source_runs("
+#include <string.h>
+int main(void){
+#ifndef _AIX
+int strerror_r(int, char *, size_t);
+#else
+/* Older AIX has 'int' for the third argument so we don't test the args. */
+int strerror_r();
+#endif
+return 0;
+}
+" STRERROR_R_INT)
+
+check_c_source_runs("
+int main(void){
+int a = 0; int *p = &a; int r;
+ __asm__ __volatile__ (\" lwarx %0,0,%1,1\n\" : \"=&r\"(r) : \"r\"(p));
+return 0;
+}
+" HAVE_PPC_LWARX_MUTEX_HINT)
+
+check_c_source_runs("
+#include <machine/vmparam.h>
+#include <sys/exec.h>
+int main(void){
+PS_STRINGS->ps_nargvstr = 1;
+PS_STRINGS->ps_argvstr = \"foo\";
+return 0;
+}
+" HAVE_PS_STRINGS)
+
+if(HAVE_SYS_MMAN_H)
+ set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};sys/mman.h")
+endif()
+if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+ set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES} -lrt")
+endif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+check_function_exists(shm_open HAVE_SHM_OPEN)
+
+
+if(HAVE_SYS_TIME_H)
+ set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};sys/time.h")
+endif()
+if(HAVE_SYS_RESOURCE_H)
+ set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};sys/resource.h")
+endif()
+check_function_exists(getrusage HAVE_GETRUSAGE)
+check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
+
+if(HAVE_UTIME_H)
+ set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};utime.h")
+endif()
+check_function_exists(utime HAVE_UTIME)
+check_function_exists(utimes HAVE_UTIMES)
+
+set(OLD_INCLUDES "${CMAKE_EXTRA_INCLUDE_FILES}")
+set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};netinet/in.h;arpa/inet.h")
+check_function_exists(inet_aton HAVE_INET_ATON)
+set(CMAKE_EXTRA_INCLUDE_FILES "${OLD_INCLUDES}")
+
+if(OPENSSL_FOUND)
+ set(USE_OPENSSL 1)
+ set(CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES};${OPENSSL_INCLUDE_DIR}")
+ set(CMAKE_REQUIRED_LIBRARIES ${OPENSSL_LIBRARIES})
+ check_function_exists(SSL_get_current_compression HAVE_SSL_GET_CURRENT_COMPRESSION)
+endif(OPENSSL_FOUND)
+
+if(USE_SYSTEMD)
+ check_include_files(systemd/sd-daemon.h HAVE_SYSTEMD_SD_DAEMON_H)
+ if(NOT HAVE_SYSTEMD_SD_DAEMON_H)
+ message(FATAL_ERROR "header file <systemd/sd-daemon.h> is required for systemd support")
+ endif()
+endif()
+
+
+if(USE_BSD_AUTH AND NOT HAVE_BSD_AUTH_H)
+ message(FATAL_ERROR "header file <bsd_auth.h> is required for BSD Authentication support")
+endif()
+
+# Check ReadLine includes
+option(WITH_READLINE "do not use GNU Readline nor BSD Libedit for editing" ON)
+if(WITH_READLINE AND NOT MSVC)
+ find_package(Readline)
+ if(READLINE_FOUND)
+ #Sometimes for redline need curses
+ message(STATUS "Found Readline: ${READLINE_LIBRARY}")
+ find_package(Curses)
+ if(NOT CURSES_FOUND)
+ set(CURSES_NEED_NCURSES TRUE)
+ endif()
+ find_package(Curses)
+ check_include_files("stdio.h;readline.h" HAVE_READLINE_H)
+ check_include_files("stdio.h;history.h" HAVE_HISTORY_H)
+ check_include_files("stdio.h;readline/history.h" HAVE_READLINE_HISTORY_H)
+ check_include_files("stdio.h;readline/readline.h" HAVE_READLINE_READLINE_H)
+ check_include_files("stdio.h;editline/history.h" HAVE_EDITLINE_HISTORY_H)
+ check_include_files("stdio.h;editline/readline.h" HAVE_EDITLINE_READLINE_H)
+
+ set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${READLINE_LIBRARY})
+ if(CURSES_FOUND)
+ set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${CURSES_LIBRARIES})
+ set(READLINE_LIBRARY ${READLINE_LIBRARY} ${CURSES_LIBRARIES})
+ endif()
+ check_function_exists(rl_completion_append_character HAVE_RL_COMPLETION_APPEND_CHARACTER)
+ check_function_exists(rl_completion_matches HAVE_RL_COMPLETION_MATCHES)
+ check_function_exists(rl_filename_completion_function HAVE_RL_FILENAME_COMPLETION_FUNCTION)
+ check_function_exists(rl_reset_screen_size HAVE_RL_RESET_SCREEN_SIZE)
+ check_function_exists(append_history HAVE_APPEND_HISTORY)
+ check_function_exists(history_truncate_file HAVE_HISTORY_TRUNCATE_FILE)
+ endif(READLINE_FOUND)
+endif()
+
+if(READLINE_FOUND)
+ set(HAVE_LIBREADLINE TRUE)
+else()
+ set(READLINE_LIBRARY "")
+ set(HAVE_LIBREADLINE FALSE)
+endif()
+
+# Check if _GNU_SOURCE is available.
+check_symbol_exists(__GNU_LIBRARY__ "features.h" _GNU_SOURCE)
+check_symbol_exists(F_FULLFSYNC "fcntl.h" HAVE_DECL_F_FULLFSYNC)
+
+include(ReplacePython)
+include(CheckCpuID)
+include(CheckSSE42)
+
+if(MSVC)
+ if(HAVE__GET_CPUID OR HAVE__CPUID)
+ set(USE_SSE42_CRC32C_WITH_RUNTIME_CHECK 1)
+ endif()
+else()
+ if(HAVE_SSE42 AND HAVE_SSE42_INTRINSICS)
+ set(USE_SSE42_CRC32C 1)
+ elseif(HAVE_SSE42_INTRINSICS AND (HAVE__GET_CPUID OR HAVE__CPUID))
+ set(USE_SSE42_CRC32C_WITH_RUNTIME_CHECK 1)
+ else()
+ set(USE_SLICING_BY_8_CRC32C 1)
+ endif()
+endif()
+
+include(FuncAcceptArgtypes)
+include(CheckTypeAlignment)
+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)
+
+check_type_size(int64 HAVE_INT64)
+check_type_size(uint64 HAVE_UINT64)
+check_type_size(int8 HAVE_INT8)
+check_type_size(uint8 HAVE_UINT8)
+check_type_size("void *" VOID_POINTER_SIZE)
+math(EXPR VOID_POINTER_SIZE_BIT "${VOID_POINTER_SIZE}*8")
+check_type_size("long int" LONG_INT_SIZE)
+check_type_size("long long int" HAVE_LONG_LONG_INT)
+check_type_size("long" SIZEOF_LONG)
+check_type_size("size_t" SIZEOF_SIZE_T)
+check_type_size(__int128 PG_INT128_TYPE)
+if(PG_INT128_TYPE AND NOT WIN32)
+ set(HAVE_INT128 1)
+ set(PG_INT128_TYPE __int128)
+endif()
+
+
+if(HAVE_LOCALE_H)
+ set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};locale.h")
+endif()
+check_type_size("locale_t" HAVE_LOCALE_T)
+if(NOT HAVE_LOCALE_T AND HAVE_XLOCALE_H)
+ set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};xlocale.h")
+ check_type_size("locale_t" HAVE_LOCALE_T)
+ if(HAVE_LOCALE_T)
+ set(LOCALE_T_IN_XLOCALE 1)
+ else()
+ set(LOCALE_T_IN_XLOCALE 0)
+ endif()
+else()
+ set(LOCALE_T_IN_XLOCALE 0)
+endif()
+
+check_type_size("wcstombs_l" HAVE_WCSTOMBS_L)
+#check_function_exists(wcstombs_l HAVE_WCSTOMBS_L)
+if(NOT HAVE_WCSTOMBS_L AND HAVE_XLOCALE_H)
+ set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};xlocale.h")
+ check_type_size("wcstombs_l" HAVE_WCSTOMBS_L)
+ if(HAVE_WCSTOMBS_L)
+ set(WCSTOMBS_L_IN_XLOCALE 1)
+ else()
+ set(WCSTOMBS_L_IN_XLOCALE 0)
+ endif()
+else()
+ set(WCSTOMBS_L_IN_XLOCALE 0)
+endif()
+
+if(LONG_INT_SIZE EQUAL 8)
+ set(PG_INT64_TYPE "long int")
+ set(HAVE_LONG_INT_64 ${LONG_INT_SIZE})
+else(LONG_INT_SIZE EQUAL 8)
+ if(HAVE_LONG_LONG_INT EQUAL 8)
+ set(PG_INT64_TYPE "long long int")
+ set(HAVE_LONG_LONG_INT_64 1)
+ else()
+ message(FATAL_ERROR "Cannot find a working 64-bit integer type.")
+ endif()
+endif(LONG_INT_SIZE EQUAL 8)
+
+message(STATUS "PG_INT64_TYPE: ${PG_INT64_TYPE} HAVE_LONG_INT_64: ${HAVE_LONG_INT_64}")
+# 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.
+
+if(NOT MAXIMUM_ALIGNOF)
+ set(MAX_ALIGNOF ${ALIGNOF_LONG})
+ if(MAX_ALIGNOF LESS ALIGNOF_DOUBLE)
+ set(MAX_ALIGNOF ${ALIGNOF_DOUBLE})
+ endif(MAX_ALIGNOF LESS ALIGNOF_DOUBLE)
+ if(HAVE_LONG_LONG_INT_64 AND MAX_ALIGNOF LESS HAVE_LONG_LONG_INT_64)
+ set(MAX_ALIGNOF ${HAVE_LONG_LONG_INT_64})
+ endif(HAVE_LONG_LONG_INT_64 AND MAX_ALIGNOF LESS HAVE_LONG_LONG_INT_64)
+ if(MAX_ALIGNOF)
+ set(MAXIMUM_ALIGNOF ${MAX_ALIGNOF})
+ endif(MAX_ALIGNOF)
+endif(NOT MAXIMUM_ALIGNOF)
+message(STATUS "MAXIMUM_ALIGNOF ${MAXIMUM_ALIGNOF}")
+
+if(HAVE_LONG_LONG_INT_64)
+ if(NOT NEED_REPL_SNPRINTF)
+ include(CheckSnprintfLongLongIntModifier)
+ if(NOT LONG_LONG_INT_MODIFIER)
+ set(LONG_LONG_INT_MODIFIER "ll")
+ set(NEED_REPL_SNPRINTF ON)
+ endif(NOT LONG_LONG_INT_MODIFIER)
+ else(NOT NEED_REPL_SNPRINTF)
+ set(LONG_LONG_INT_MODIFIER "ll")
+ endif(NOT NEED_REPL_SNPRINTF)
+else(HAVE_LONG_LONG_INT_64)
+ set(LONG_LONG_INT_MODIFIER "l")
+endif(HAVE_LONG_LONG_INT_64)
+
+if(HAVE_LONG_LONG_INT_64)
+ message(STATUS "HAVE_LONG_LONG_INT_64 ${HAVE_LONG_LONG_INT_64}")
+endif()
+if(HAVE_LONG_LONG_INT_64)
+ include(CheckLLConstants)
+endif()
+
+#TODO: some strange here
+option(USE_FLOAT4_BYVAL "float4 values are passed by value" ON)
+if(USE_FLOAT4_BYVAL)
+ set(FLOAT4PASSBYVAL 1)
+else(USE_FLOAT4_BYVAL)
+ set(FLOAT4PASSBYVAL 0)
+endif(USE_FLOAT4_BYVAL)
+
+if(VOID_POINTER_SIZE EQUAL 8)
+ option(USE_FLOAT8_BYVAL "float8 values are passed by value" ON)
+else()
+ option(USE_FLOAT8_BYVAL "float8 values are passed by value" OFF)
+endif()
+if(USE_FLOAT8_BYVAL AND NOT (VOID_POINTER_SIZE EQUAL 8))
+ message(FATAL_ERROR "USE_FLOAT8_BYVAL is not supported on 32-bit platforms.")
+elseif(USE_FLOAT8_BYVAL AND VOID_POINTER_SIZE EQUAL 8)
+ set(FLOAT8PASSBYVAL 1)
+ set(USE_FLOAT8_BYVAL 1)
+else()
+ set(FLOAT8PASSBYVAL 0)
+ set(USE_FLOAT8_BYVAL 0)
+endif(USE_FLOAT8_BYVAL AND NOT (VOID_POINTER_SIZE EQUAL 8))
+
+if (_GNU_SOURCE)
+ add_definitions(-D_GNU_SOURCE)
+endif()
+if(Threads_FOUND)
+ set(ENABLE_THREAD_SAFETY 1)
+ set(THREADS_PREFER_PTHREAD_FLAG ON)
+ set(PTHREAD_CFLAGS "-D_REENTRANT -D_THREAD_SAFE -D_POSIX_PTHREAD_SEMANTICS")
+ if(THREADS_HAVE_PTHREAD_ARG)
+ set(PTHREAD_CFLAGS "${PTHREAD_CFLAGS} -pthread")
+ endif()
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PTHREAD_CFLAGS}")
+endif()
+
+set(PORT_DIR "${PROJECT_SOURCE_DIR}/src/port")
+set(PQ_BACKEND_DIR "${PROJECT_SOURCE_DIR}/src/backend/libpq")
+set(MB_UTILS_BACKEND_DIR "${PROJECT_SOURCE_DIR}/src/backend/utils/mb")
+
+
+set(fallback_SRCS "")
+
+if(NOT HAVE_DECL_STRLCPY)
+ set(fallback_SRCS ${fallback_SRCS} "${PORT_DIR}/strlcpy.c")
+endif(NOT HAVE_DECL_STRLCPY)
+
+if(NOT HAVE_DECL_STRLCAT)
+ set(fallback_SRCS ${fallback_SRCS} "${PORT_DIR}/strlcat.c")
+endif(NOT HAVE_DECL_STRLCAT)
+
+if(NOT HAVE_GETPEEREID)
+ set(fallback_SRCS ${fallback_SRCS} "${PORT_DIR}/getpeereid.c")
+endif(NOT HAVE_GETPEEREID)
+
+set(TABLE_BLOCKSIZE 8 CACHE STRING "set table block size in kB")
+
+if(TABLE_BLOCKSIZE EQUAL 1)
+ set(BLCKSZ 1024)
+elseif(TABLE_BLOCKSIZE EQUAL 2)
+ set(BLCKSZ 2048)
+elseif(TABLE_BLOCKSIZE EQUAL 4)
+ set(BLCKSZ 4096)
+elseif(TABLE_BLOCKSIZE EQUAL 8)
+ set(BLCKSZ 8192)
+elseif(TABLE_BLOCKSIZE EQUAL 16)
+ set(BLCKSZ 16384)
+elseif(TABLE_BLOCKSIZE EQUAL 32)
+ set(BLCKSZ 32768)
+else(TABLE_BLOCKSIZE EQUAL 1)
+ message(FATAL_ERROR "Invalid block size. Allowed values are 1,2,4,8,16,32.")
+endif(TABLE_BLOCKSIZE EQUAL 1)
+
+message(STATUS "BLCKSZ - ${BLCKSZ}")
+
+set(SEGSIZE 1 CACHE STRING "set table segment size in GB")
+math(EXPR RELSEG_SIZE "(1024 / ${TABLE_BLOCKSIZE}) * ${SEGSIZE} * 1024")
+
+set(WAL_BLOCKSIZE 8 CACHE STRING "set WAL block size in kB")
+
+if(WAL_BLOCKSIZE EQUAL 1)
+ set(XLOG_BLCKSZ 1024)
+elseif(WAL_BLOCKSIZE EQUAL 2)
+ set(XLOG_BLCKSZ 2048)
+elseif(WAL_BLOCKSIZE EQUAL 4)
+ set(XLOG_BLCKSZ 4096)
+elseif(WAL_BLOCKSIZE EQUAL 8)
+ set(XLOG_BLCKSZ 8192)
+elseif(WAL_BLOCKSIZE EQUAL 16)
+ set(XLOG_BLCKSZ 16384)
+elseif(WAL_BLOCKSIZE EQUAL 32)
+ set(XLOG_BLCKSZ 32768)
+elseif(WAL_BLOCKSIZE EQUAL 64)
+ set(XLOG_BLCKSZ 65536)
+else(WAL_BLOCKSIZE EQUAL 1)
+ message(FATAL_ERROR "Invalid WAL block size. Allowed values are 1,2,4,8,16,32,64.")
+endif(WAL_BLOCKSIZE EQUAL 1)
+
+message(STATUS "XLOG_BLCKSZ - ${XLOG_BLCKSZ}")
+
+set(WAL_SEGSIZE 16 CACHE STRING "set WAL segment size in MB")
+
+if (";1;2;4;8;16;32;64;" MATCHES ";${WAL_SEGSIZE};")
+ math(EXPR XLOG_SEG_SIZE "${WAL_SEGSIZE} * 1024 * 1024")
+else()
+ message(FATAL_ERROR "${WAL_SEGSIZE} Invalid WAL segment size. Allowed values are 1,2,4,8,16,32,64.")
+endif()
+
+message(STATUS "XLOG_SEG_SIZE - ${XLOG_SEG_SIZE}")
+
+option(HAVE_ATOMICS "Define to ON if you want to use atomics if available." ON)
+
+if(HAVE_ATOMICS)
+ check_c_source_compiles("
+ int main(void){
+ char lock = 0;
+ __sync_lock_test_and_set(&lock, 1);
+ __sync_lock_release(&lock);
+ return 0;
+ }
+ " HAVE_GCC__SYNC_CHAR_TAS)
+
+ check_c_source_compiles("
+ int main(void){
+ int lock = 0;
+ __sync_lock_test_and_set(&lock, 1);
+ __sync_lock_release(&lock);
+ return 0;
+ }
+ " HAVE_GCC__SYNC_INT32_TAS)
+
+ check_c_source_compiles("
+ int main(void){
+ int val = 0;
+ __sync_val_compare_and_swap(&val, 0, 37);
+ return 0;
+ }
+ " HAVE_GCC__SYNC_INT32_CAS)
+
+ check_c_source_compiles("
+ int main(void){
+ ${PG_INT64_TYPE} lock = 0;
+ __sync_val_compare_and_swap(&lock, 0, (${PG_INT64_TYPE}) 37);
+ return 0;
+ }
+ " HAVE_GCC__SYNC_INT64_CAS)
+
+ check_c_source_compiles("
+ int main(void){
+ int val = 0;
+ int expect = 0;
+ __atomic_compare_exchange_n(&val, &expect, 37, 0, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED);
+ return 0;
+ }
+ " HAVE_GCC__ATOMIC_INT32_CAS)
+
+ check_c_source_compiles("
+ int main(void){
+ ${PG_INT64_TYPE} val = 0;
+ ${PG_INT64_TYPE} expect = 0;
+ __atomic_compare_exchange_n(&val, &expect, 37, 0, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED);
+ return 0;
+ }
+ " HAVE_GCC__ATOMIC_INT64_CAS)
+endif(HAVE_ATOMICS)
+
+check_c_source_runs("
+ int main(void){
+ static unsigned long int x = __builtin_bswap32(0xaabbccdd);
+ return 0;
+ }
+" HAVE__BUILTIN_BSWAP32)
+
+check_c_source_runs("
+ int main(void){
+ static unsigned long int x = __builtin_bswap64(0xaabbccddeeff0011);
+ return 0;
+ }
+" HAVE__BUILTIN_BSWAP64)
+
+check_c_source_runs("
+ int main(void){
+ static int x; static int y[__builtin_constant_p(x) ? x : 1];
+ return 0;
+ }
+" HAVE__BUILTIN_CONSTANT_P)
+
+check_c_source_runs("
+ int main(void){
+ int x; static int y[__builtin_types_compatible_p(__typeof__(x), int)];
+ return 0;
+ }
+" HAVE__BUILTIN_TYPES_COMPATIBLE_P)
+
+check_c_source_runs("
+ int main(void){
+ __builtin_unreachable();
+ return 0;
+ }
+" HAVE__BUILTIN_UNREACHABLE)
+
+check_c_source_runs("
+ int main(void){
+ { _Static_assert(1, \"foo\"); }
+ return 0;
+ }
+" HAVE__STATIC_ASSERT)
+
+if(NOT PGPORT)
+ set(PGPORT 5432)
+endif(NOT PGPORT)
+
+include(CheckFlexibleArray)
+
+check_c_source_compiles("
+ #include <sys/time.h>
+ int main(void){
+ struct timeval *tp;
+ struct timezone *tzp;
+ gettimeofday(tp,tzp);
+ return 0;
+ }
+" GETTIMEOFDAY_2ARG)
+
+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)
+
+check_c_source_compiles("
+ #include <stdio.h>
+ int main(void){
+ printf(\"%s\", __func__);
+ return 0;
+ }
+" HAVE_FUNCNAME__FUNC)
+
+check_c_source_compiles("
+ #include <stdio.h>
+ int main(void){
+ printf(\"%s\", __FUNCTION__);
+ return 0;
+ }
+" HAVE_FUNCNAME__FUNCTION)
+
+check_c_source_compiles("
+ #include <stdio.h>
+ int main(void){
+ #define debug(...) fprintf(stderr, __VA_ARGS__)
+ debug(\"%s\", \"blarg\");
+ return 0;
+ }
+" HAVE__VA_ARGS)
+
+check_struct_has_member("struct tm" tm_zone "sys/types.h;time.h" HAVE_TM_ZONE LANGUAGE C)
+check_struct_has_member("struct tm" tm_gmtoff "sys/types.h;time.h" HAVE_STRUCT_TM_TM_ZONE LANGUAGE C)
+set(CMAKE_EXTRA_INCLUDE_FILES "time.h")
+check_type_size("*tzname" HAVE_TZNAME)
+
+if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
+ set(CMAKE_REQUIRED_FLAGS "-Werror")
+endif()
+check_c_source_compiles("
+ extern int pgac_write(int ignore, const char *fmt,...) __attribute__((format(gnu_printf, 2, 3)));
+ int main(void){return 0;}
+" PG_PRINTF_ATTRIBUTE)
+
+if(PG_PRINTF_ATTRIBUTE)
+ set(PG_PRINTF_ATTRIBUTE gnu_printf)
+else(PG_PRINTF_ATTRIBUTE)
+ set(PG_PRINTF_ATTRIBUTE printf)
+endif(PG_PRINTF_ATTRIBUTE)
+
+if(NOT MEMSET_LOOP_LIMIT)
+ set(MEMSET_LOOP_LIMIT 1024)
+endif(NOT MEMSET_LOOP_LIMIT)
+
+
+if(WIN32 OR MINGW)
+ 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 cmsgcred" HAVE_STRUCT_CMSGCRED)
+if(HAVE_STRUCT_ADDRINFO)
+ CHECK_STRUCT_HAS_MEMBER("struct addrinfo" sa_len "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRUCT_SOCKADDR_SA_LEN LANGUAGE C)
+ if(NOT (WIN32 OR MINGW))
+ set(HAVE_GETADDRINFO 1)
+ endif()
+endif(HAVE_STRUCT_ADDRINFO)
+
+check_type_size("struct sockaddr_storage" HAVE_STRUCT_SOCKADDR_STORAGE)
+if(HAVE_STRUCT_SOCKADDR_STORAGE)
+ CHECK_STRUCT_HAS_MEMBER("struct sockaddr_storage" ss_family "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY LANGUAGE C)
+ CHECK_STRUCT_HAS_MEMBER("struct sockaddr_storage" __ss_family "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY LANGUAGE C)
+ CHECK_STRUCT_HAS_MEMBER("struct sockaddr_storage" ss_len "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN LANGUAGE C)
+ CHECK_STRUCT_HAS_MEMBER("struct sockaddr_storage" __ss_len "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN LANGUAGE C)
+endif(HAVE_STRUCT_SOCKADDR_STORAGE)
+
+# If `struct sockaddr_un' exists, define HAVE_UNIX_SOCKETS.
+if(HAVE_SYS_UN_H)
+ set(CMAKE_EXTRA_INCLUDE_FILES "sys/types.h;sys/un.h")
+else(HAVE_SYS_UN_H)
+ set(CMAKE_EXTRA_INCLUDE_FILES "sys/types.h")
+endif(HAVE_SYS_UN_H)
+check_type_size("struct sockaddr_un" HAVE_UNIX_SOCKETS)
+
+if(WIN32)
+ set(HAVE_IPV6 1)
+else()
+ set(CMAKE_EXTRA_INCLUDE_FILES "netinet/in.h")
+ check_type_size("struct sockaddr_in6" HAVE_IPV6)
+endif()
+
+set(CMAKE_EXTRA_INCLUDE_FILES "sys/types.h;sys/ipc.h;sys/sem.h")
+check_type_size("union semun" HAVE_UNION_SEMUN)
+
+check_include_file("sys/stat.h" HAVE_SYS_STAT_H)
+
+check_symbol_exists(fdatasync "unistd.h" HAVE_FDATASYNC)
+
+if(WIN32 OR MINGW)
+ set(USE_WIN32_SEMAPHORES 1)
+ set(SEMA_IMPLEMENTATION "${PROJECT_SOURCE_DIR}/src/backend/port/win32_sema.c")
+else(WIN32 OR MINGW)
+ if(USE_NAMED_POSIX_SEMAPHORES)
+ set(USE_NAMED_POSIX_SEMAPHORES 1)
+ set(SEMA_IMPLEMENTATION "${PROJECT_SOURCE_DIR}/src/backend/port/posix_sema.c")
+ elseif(USE_UNNAMED_POSIX_SEMAPHORES)
+ set(USE_UNNAMED_POSIX_SEMAPHORES 1)
+ set(SEMA_IMPLEMENTATION "${PROJECT_SOURCE_DIR}/src/backend/port/posix_sema.c")
+ else(USE_NAMED_POSIX_SEMAPHORES)
+ set(USE_SYSV_SEMAPHORES 1)
+ set(SEMA_IMPLEMENTATION "${PROJECT_SOURCE_DIR}/src/backend/port/sysv_sema.c")
+ endif(USE_NAMED_POSIX_SEMAPHORES)
+endif(WIN32 OR MINGW)
+
+#Realy bad name for win32
+set(USE_SYSV_SHARED_MEMORY 1)
+if(WIN32 OR MINGW)
+ set(SHMEM_IMPLEMENTATION "${PROJECT_SOURCE_DIR}/src/backend/port/win32_shmem.c")
+else(WIN32 OR MINGW)
+ set(SHMEM_IMPLEMENTATION "${PROJECT_SOURCE_DIR}/src/backend/port/sysv_shmem.c")
+endif(WIN32 OR MINGW)
+
+option(HAVE_SPINLOCKS "Define to ON if you have spinlocks." ON)
+
+
+option(USE_INTEGER_DATETIMES "Define to ON if you want 64-bit integer timestamp and interval support." ON)
+
+if(WIN32)
+ option(HAVE_SYMLINK "Define to ON if you have the `symlink' function." ON)
+else(WIN32)
+ set(HAVE_SYMLINK 1)
+endif(WIN32)
+
+option(PG_KRB_SRVNAM "Define to the name of the default PostgreSQL service principal in Kerberos (GSSAPI)." "postgres")
+
+#TODO: Need test this
+if(CMAKE_C_COMPILER_ID STREQUAL "SunPro")
+ if(CMAKE_SYSTEM_PROCESSOR MATCHES "sparc")
+ set(TAS sunstudio_sparc.s)
+ else(CMAKE_SYSTEM_PROCESSOR MATCHES "sparc")
+ set(TAS sunstudio_x86.s)
+ endif(CMAKE_SYSTEM_PROCESSOR MATCHES "sparc")
+elseif(CMAKE_C_COMPILER_ID STREQUAL "HP-UX")
+ set(TAS hpux_hppa.s)
+else(CMAKE_C_COMPILER_ID STREQUAL "SunPro")
+ set(TAS dummy.s)
+endif(CMAKE_C_COMPILER_ID STREQUAL "SunPro")
+
+if(WIN32 OR MINGW)
+ set(CMAKE_EXTRA_INCLUDE_FILES
+ ${CMAKE_EXTRA_INCLUDE_FILES}
+ windows.h
+ string.h
+ dbghelp.h
+ )
+ set(CMAKE_REQUIRED_DEFINITIONS "WIN32_LEAN_AND_MEAN")
+ check_type_size(MINIDUMP_TYPE NAVE_MINIDUMP_TYPE)
+endif(WIN32 OR MINGW)
+
+set(WIN32_STACK_RLIMIT 4194304)
+if(WIN32)
+ add_definitions(-DWIN32_STACK_RLIMIT=${WIN32_STACK_RLIMIT})
+endif()
+
+if(NEED_REPL_SNPRINTF)
+ option(USE_REPL_SNPRINTF "Use replacement snprintf() functions." ON)
+endif()
+
+find_program(SED_EXECUTABLE sed)
+if(NOT SED_EXECUTABLE)
+ message(FATAL_ERROR "sed programm not found")
+endif(NOT SED_EXECUTABLE)
+
+include(GenDef)
+#Not work correctly for postgres see bug:
+#https://gitlab.kitware.com/cmake/cmake/issues/16161
+#set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
+
+include(RegressCheck)
+
+# Need add sco and unixware?
+if(WIN32 OR MINGW)
+ set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/win32.h)
+elseif(APPLE)
+ set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/darwin.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+ set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/linux.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
+ set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/hpux.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
+ set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/freebsd.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
+ set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/openbsd.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
+ set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/newtbsd.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
+ set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/solaris.h)
+elseif(CMAKE_SYSTEM_NAME STREQUAL "AIX")
+ set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/aix.h)
+elseif(CYGWIN)
+ set(pgos_include_SRCS ${PROJECT_SOURCE_DIR}/src/include/port/cygwin.h)
+else(WIN32 OR MINGW)
+ message(WARNING "${CMAKE_SYSTEM_NAME}")
+endif(WIN32 OR MINGW)
+
+# Try make fake host tuple for regress and isolation tests
+if(MINGW AND VOID_POINTER_SIZE EQUAL 8)
+ set(HOST_TUPLE "x86_64-w64-mingw32")
+elseif(MINGW AND VOID_POINTER_SIZE EQUAL 4)
+ set(HOST_TUPLE "i686-pc-mingw32")
+elseif(CYGWIN)
+ set(HOST_TUPLE "i686-pc-cygwin")
+elseif(MSVC AND VOID_POINTER_SIZE EQUAL 4)
+ set(HOST_TUPLE "i686-pc-win32vc")
+else()
+ set(HOST_TUPLE ${CMAKE_HOST_SYSTEM})
+endif()
+
+set(WITH_UUID "OFF" CACHE STRING "type of uuid lib [bsd, e2fs, ossp]")
+if(WITH_UUID)
+ find_package(LibUUID)
+
+ if(WITH_UUID STREQUAL "bsd")
+ set(HAVE_UUID_BSD 1)
+ set(UUID_EXTRA_OBJS
+ ${PROJECT_SOURCE_DIR}/contrib/pgcrypto/md5.c
+ ${PROJECT_SOURCE_DIR}/contrib/pgcrypto/sha1.c
+ )
+ elseif(WITH_UUID STREQUAL "e2fs")
+ set(HAVE_UUID_E2FS 1)
+ set(UUID_EXTRA_OBJS
+ ${PROJECT_SOURCE_DIR}/contrib/pgcrypto/md5.c
+ ${PROJECT_SOURCE_DIR}/contrib/pgcrypto/sha1.c
+ )
+ elseif(WITH_UUID STREQUAL "ossp")
+ set(HAVE_UUID_OSSP 1)
+ set(UUID_EXTRA_OBJS "")
+ else()
+ message(WARNING "Not correct type of uuid lib:${WITH_UUID}")
+ endif()
+endif()
+
+#file(REMOVE ${PROJECT_SOURCE_DIR}/src/include/pg_config_os.h)
+file(GENERATE OUTPUT ${PROJECT_SOURCE_DIR}/src/include/pg_config_os.h
+ INPUT ${pgos_include_SRCS})
+
+if(MINGW OR MSVC)
+ include_directories("${PROJECT_SOURCE_DIR}/src/include/port/win32")
+endif()
+
+if(MSVC)
+ include_directories("${PROJECT_SOURCE_DIR}/src/include/port/win32_msvc")
+endif()
+
+configure_file(
+ "${PROJECT_SOURCE_DIR}/src/include/pg_config_cmake.in"
+ "${PROJECT_SOURCE_DIR}/src/include/pg_config.h"
+)
+
+configure_file(
+ "${PROJECT_SOURCE_DIR}/src/include/pg_config_ext_cmake.in"
+ "${PROJECT_SOURCE_DIR}/src/include/pg_config_ext.h"
+)
+
+configure_file(
+ "${PROJECT_SOURCE_DIR}/src/include/pg_config_paths_cmake.in"
+ "${PROJECT_SOURCE_DIR}/src/port/pg_config_paths.h"
+)
+
+configure_file(
+ "${PROJECT_SOURCE_DIR}/src/interfaces/ecpg/include/ecpg_config_cmake.in"
+ "${PROJECT_SOURCE_DIR}/src/interfaces/ecpg/include/ecpg_config.h"
+)
+
+configure_file(
+ "${PROJECT_SOURCE_DIR}/PGXS.cmake.in"
+ "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/PGXS.cmake"
+ @ONLY
+)
+
+install(FILES ${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/PGXS.cmake
+ DESTINATION ${LIBDIR}/cmake)
+
+
+option(CMAKE_USE_FOLDERS "Enable folder grouping of projects in IDEs." ON)
+mark_as_advanced(CMAKE_USE_FOLDERS)
+
+macro(CMAKE_SET_TARGET_FOLDER tgt folder)
+ if(CMAKE_USE_FOLDERS)
+ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
+ if(MSVC AND TARGET ${tgt})
+ set_property(TARGET "${tgt}" PROPERTY FOLDER "${folder}")
+ endif()
+ else()
+ set_property(GLOBAL PROPERTY USE_FOLDERS OFF)
+ endif()
+endmacro()
+
+# Add sub-directories
+add_subdirectory(src)
+add_subdirectory(contrib)
+
+message(STATUS "------------------")
+message(STATUS " Conclusion")
+message(STATUS "Host tuple: ${HOST_TUPLE}")
+message(STATUS "OpenSSL: ${OPENSSL_FOUND} version: ${OPENSSL_VERSION} libs: ${OPENSSL_LIBRARIES} include: ${OPENSSL_INCLUDE_DIR}")
+message(STATUS "Python: ${PYTHONINTERP_FOUND}")
+message(STATUS "PythonLibs: ${PYTHONLIBS_FOUND}")
+message(STATUS "PerlLibs: ${PERLLIBS_FOUND}")
+message(STATUS "LibXML2: ${LIBXML2_FOUND}")
+message(STATUS "LibXslt: ${LIBXSLT_FOUND}")
+message(STATUS "TCL: ${TCL_FOUND}")
+message(STATUS "PAM: ${PAM_LIB}")
+message(STATUS "PROVE (TAP tests): ${PROVE}")
+message(STATUS "Strong random source: ${STRONG_RANDOM_SOURCE}")
+message(STATUS "------------------")
diff --git a/PGXS.cmake.in b/PGXS.cmake.in
new file mode 100644
index 0000000000..c8bb151fed
--- /dev/null
+++ b/PGXS.cmake.in
@@ -0,0 +1,48 @@
+cmake_minimum_required(VERSION 2.8)
+
+set(POSTGRES_MAJOR_VERSION "@POSTGRES_MAJOR_VERSION@")
+set(POSTGRES_MINOR_VERSION "@POSTGRES_MINOR_VERSION@")
+set(POSTGRES_PATCH_VERSION "@POSTGRES_MINOR_VERSION@")
+set(POSTGRES_VERSION "@POSTGRES_VERSION@")
+set(PG_VERSION "10.0")
+set(PG_VERSION_NUM 100000)
+
+set(PGBINDIR "@PGBINDIR@")
+set(PGSHAREDIR "@PGSHAREDIR@")
+set(SYSCONFDIR "@SYSCONFDIR@")
+set(INCLUDEDIR "@INCLUDEDIR@")
+set(PKGINCLUDEDIR "@PKGINCLUDEDIR@")
+set(INCLUDEDIRSERVER "@INCLUDEDIRSERVER@")
+set(LIBDIR "@LIBDIR@")
+set(PKGLIBDIR "@PKGLIBDIR@")
+set(LOCALEDIR "@LOCALEDIR@")
+set(DOCDIR "@DOCDIR@")
+set(HTMLDIR "@HTMLDIR@")
+set(MANDIR "@MANDIR@")
+
+
+set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
+set(CMAKE_MACOSX_RPATH 1)
+
+set(CMAKE_CXX_FLAGS "@CMAKE_CXX_FLAGS@")
+set(CMAKE_C_FLAGS "@CMAKE_C_FLAGS@")
+set(CMAKE_SHARED_LINKER_FLAGS "@CMAKE_SHARED_LINKER_FLAGS@")
+set(CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "@CMAKE_SHARED_LIBRARY_SONAME_C_FLAG@")
+set(CMAKE_SHARED_LINKER_FLAGS "@CMAKE_SHARED_LINKER_FLAGS@")
+
+include_directories(${INCLUDEDIRSERVER})
+link_directories(${LIBDIR})
+
+if(WIN32)
+ set(contrib_libs
+ port
+ pgcommon
+ )
+endif()
+
+if(MSVC)
+ set(contrib_libs
+ ${contrib_libs}
+ postgres
+ )
+endif()
diff --git a/README.cmake b/README.cmake
new file mode 100644
index 0000000000..615a80e2ac
--- /dev/null
+++ b/README.cmake
@@ -0,0 +1,245 @@
+Requirements
+============
+For Unix system you can build postgres with CMake 3.0 and higher.
+For Windows build you must use CMake 3.7.1 and higher.
+If you don't have CMake on your system (Solaris, AIX or old Linux),
+you can build it from source without any problems.
+
+
+Basic commands
+==============
+Full documentations you can find here:
+https://cmake.org/cmake/help/latest/
+and small but usefull tutorial here:
+https://cmake.org/cmake-tutorial/
+
+Very basic usage in Unix systems:
+cmake ..
+
+where .. is path to postgres source dir. To use Ninja instead
+of GNU Make you must write:
+
+cmake .. -G "Ninja"
+
+To explore other generators use:
+cmake .. -G help
+
+Once you have generated Makefile or Ninja you should run
+make or ninja commands to build postgres. If you want to show all compiler
+option you must set env variable VERBOSE. Example:
+VERBOSE=1 make
+
+Choose configure options
+========================
+All options can be set via -DNAME_OPTION=(ON|OFF|NUMBER|STRING) param in command line.
+Example:
+cmake .. -DCMAKE_INSTALL_PREFIX="/usr/local" -DWITH_LIBXML=ON
+
+here we set install prefix and enable build with libXML.
+
+Set CFLAGS or LDFLAGS
+=====================
+CFLAGS or LDFLAGS you can set only on the generation stage as
+environment variable. Example:
+CFLAGS="-s -O2" cmake ..
+
+you can't change CFLAGS if project has been generated.
+This example won't work:
+CFLAGS="-s -O3" make
+
+You must remove cache and generate project again:
+rm ./CMakeCache.txt
+CFLAGS="-s -O3" cmake ..
+
+Targets
+=======
+In CMake you can have only one main target other targets cannot be installed.
+Also we have only one enter point to the project.
+To build postgres input:
+make
+
+or
+make all
+
+All test targets implemented as optional targets:
+make check
+make isolation_check
+make contrib_check
+make ecpg_check
+make modules_check
+
+also you can use installcheck insted check in target name to run tests for installed postgres.
+Example:
+make installcheck
+make isolation_installcheck
+
+Some tests we can run only if corresponding option is enabled:
+make plperl_check
+make pltcl_check
+make plpython_check
+
+And experemental TAP tests:
+make commit_ts_tap_check
+make bloom_tap_check
+make initdb_tap_check
+make pg_basebackup_tap_check
+make pg_config_tap_check
+make pg_controldata_tap_check
+make pg_ctl_tap_check
+make pg_dump_tap_check
+make pg_rewind_tap_check
+make pgbench_tap_check
+make scripts_tap_check
+make test_pg_dump_tap_check
+make recovery_tap_check
+make ssl_tap_check
+
+Postgres CMake build options
+============================
+**-DWITH_PERL** default OFF, optional
+
+**-DWITH_OPENSSL** default OFF, optional
+
+**-DOPENSSL_ROOT_DIR** Set this variable to the root installation of OpenSSL
+
+**-DWITH_PYTHON** default OFF, optional
+
+**-DWITH_LIBXML** default OFF, optional
+
+**-DWITH_TCL** default OFF, optional
+
+**-DWITH_ICU** default OFF, optional
+
+**-DENABLE_NLS** default OFF
+
+**-DENABLE_GSS** default OFF
+
+**-DUSE_PAM** default OFF
+
+**-DUSE_ASSERT_CHECKING** default OFF
+
+**-DUSE_BONJOUR** default OFF
+
+**-DUSE_SYSTEMD** default OFF
+
+**-DUSE_BSD_AUTH** default OFF
+
+**-DUSE_LDAP** default OFF
+
+**-DPROFILE_PID_DIR** default OFF, only for GCC, enable to allow profiling output to be saved separately for each process
+
+**-DUSE_FLOAT4_BYVAL** default ON
+
+**-DUSE_FLOAT8_BYVAL** default ON for 64bit system
+
+**-DHAVE_ATOMICS** default ON
+
+**-DHAVE_SPINLOCKS** default ON
+
+**-DUSE_INTEGER_DATETIMES** default ON, 64-bit integer timestamp and interval support
+
+**-DHAVE_SYMLINK** only for WIN32, default ON
+
+**-DPG_KRB_SRVNAM** default 'postgres', the name of the default PostgreSQL service principal in Kerberos (GSSAPI)
+
+**-DCMAKE_USE_FOLDERS** default ON, folder grouping of projects in IDEs, actual for MSVC
+
+**-DUSE_REPL_SNPRINTF** default not use but if ON you can switch OFF
+
+**-DWITH_TAP** default OFF, experemental support TAP tests
+
+**-DSTRONG_RANDOM** default ON, strong random number source
+
+**-DSTRONG_RANDOM_SOURCE** default OFF (autodetect), which random number source to use - openssl, win32, dev
+
+Only **MSVC** options:
+
+**-DUSE_FP_STRICT** default ON, if we use /fp:stirct compiler option we much closer to C99 standart in float part
+
+CMake options for modules
+=========================
+To find some libraries we use standard CMake modules and you can read documentation
+on the CMake site.
+
+For example setup for python2.7:
+-DPython_ADDITIONAL_VERSIONS=2.7 -DPYTHON_EXECUTABLE=/usr/bin/python2.7
+
+For details you can read:
+Python lib options: https://cmake.org/cmake/help/latest/module/FindPythonLibs.html
+Python interpreter options: https://cmake.org/cmake/help/latest/module/FindPythonInterp.html
+Perl libs: https://cmake.org/cmake/help/latest/module/FindPerlLibs.html
+OpenSSL: https://cmake.org/cmake/help/latest/module/FindOpenSSL.html
+Curses: https://cmake.org/cmake/help/latest/module/FindCurses.htm
+
+Uncommon CMake Examples
+=======================
+
+Solaris 10, Sun-Fire-V210:
+CFLAGS="-m64 -mcpu=v9" cmake .. -DFIND_LIBRARY_USE_LIB64_PATHS=ON -DCURSES_LIBRARY=/usr/ccs/lib/sparcv9/libcurses.so -DCURSES_FORM_LIBRARY=/usr/ccs/lib/sparcv9/libform.so -DCMAKE_INSTALL_PREFIX="/home/stalkerg/postgresql_bin"
+
+AIX 7.1, Power8, gcc 4.8:
+CFLAGS="-std=c11 -mcpu=power8 -mtune=power8 -mveclibabi=mass -maix64" LDFLAGS="-Wl,-bbigtoc" cmake ..
+
+
+CMake build and test howto
+==========================
+git clone https://github.com/stalkerg/postgres_cmake.git
+cd ./postgres_cmake
+#build dir is optional but best way for CMake
+mkdir build
+cd build
+CFLAGS="-s -O2" cmake .. -DCMAKE_INSTALL_PREFIX="/usr/local" -DWITH_PERL=ON -DWITH_LIBXML=ON
+#strip binary + O2 optimisation, for CLang you must use -strip-all insted -s
+#also you can use -G Ninja for Ninja make system
+make -j2
+make check
+make isolation_check
+make contrib_check
+
+#Optional:
+make ecpg_check
+make modules_check
+make plperl_check
+make pltcl_check
+
+#For example setup for python2.7:
+#-DPython_ADDITIONAL_VERSIONS=2.7 -DPYTHON_EXECUTABLE=/usr/bin/python2.7
+make plpython_check
+
+#TAP tests (experimental):
+make commit_ts_tap_check
+make bloom_tap_check
+make initdb_tap_check
+make pg_basebackup_tap_check
+make pg_config_tap_check
+make pg_controldata_tap_check
+make pg_ctl_tap_check
+make pg_dump_tap_check
+make pg_rewind_tap_check
+make pgbench_tap_check
+make scripts_tap_check
+make test_pg_dump_tap_check
+make recovery_tap_check
+make ssl_tap_check
+
+make install
+make installcheck
+
+Minimal build for Windows 7/10 with VisualStudio 2015/2017
+==========================================================
+
+First, you should install next programms:
+CMake - https://cmake.org/ (64 bit if you have 64 bit windows)
+Perl - https://www.activestate.com/activeperl/downloads (not forget add perl to %PATH% in options, 64 bit for build 64 bit Postgres with Perl)
+Bison and Flex - https://sourceforge.net/projects/winflexbison/ (after unzip to folder please add this folder to %PATH%)
+Sed - http://gnuwin32.sourceforge.net/packages/sed.htm
+Diff - http://gnuwin32.sourceforge.net/packages/diffutils.htm
+
+After installing Sed and Diff please add "C:/Program Files (x86)/GnuWin32/bin/" to %PATH% .
+How change %PATH% on windows? Look here https://www.computerhope.com/issues/ch000549.htm .
+Now you can clone our repo create "build" dir inside and open CMake GUI.
+In CMake GUI you should choose current repo folder and new "build" as for build and click "Configure".
+After this process, you should change CMAKE_INSTALL_PREFIX variable to something like "C:\\postgres_bin" (and create this folder).
+Now you can click on "Generate" for generation MSVC solution and after you can open this solution in your MSVC.
+In MSVC important find ALL_BUILD "project" and build this target. After complete, you should build INSTALL.
+Also, after all, that you can run build "insatllcheck".
diff --git a/cmake/CheckCpuID.cmake b/cmake/CheckCpuID.cmake
new file mode 100644
index 0000000000..3346302361
--- /dev/null
+++ b/cmake/CheckCpuID.cmake
@@ -0,0 +1,17 @@
+CHECK_C_SOURCE_COMPILES("
+ #include <cpuid.h>
+ int main() {
+ unsigned int exx[4] = {0, 0, 0, 0};
+ __get_cpuid(1, &exx[0], &exx[1], &exx[2], &exx[3]);
+ return 0;
+ }
+" HAVE__GET_CPUID)
+
+CHECK_C_SOURCE_COMPILES("
+ #include <intrin.h>
+ int main() {
+ unsigned int exx[4] = {0, 0, 0, 0};
+ __cpuid(exx[0], 1);
+ return 0;
+ }
+" HAVE__CPUID)
diff --git a/cmake/CheckFlexibleArray.cmake b/cmake/CheckFlexibleArray.cmake
new file mode 100644
index 0000000000..ce57aa4f65
--- /dev/null
+++ b/cmake/CheckFlexibleArray.cmake
@@ -0,0 +1,37 @@
+set(C99_C_FLAG_CANDIDATES
+ " "
+ "-std=c99"
+ "-std=gnu99"
+ "-c99"
+ "-AC99"
+ "-xc99=all"
+ "-qlanglvl=extc99"
+)
+
+message(STATUS "Check flexible array support")
+if(NOT MSVC)
+ foreach(FLAG ${C99_C_FLAG_CANDIDATES})
+ set(CMAKE_REQUIRED_FLAGS "${FLAG}")
+ unset(FLEXIBLE_ARRAY_MEMBER CACHE)
+ CHECK_C_SOURCE_COMPILES("
+ int main(void){
+ int x = 10;
+ int y[x];
+ return 0;
+ }
+ " FLEXIBLE_ARRAY_MEMBER)
+ if(FLEXIBLE_ARRAY_MEMBER)
+ set(C99_C_FLAGS_INTERNAL "${FLAG}")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAG}")
+ break()
+ endif(FLEXIBLE_ARRAY_MEMBER)
+ endforeach(FLAG ${C99_C_FLAG_CANDIDATES})
+endif()
+
+if(FLEXIBLE_ARRAY_MEMBER)
+ message(STATUS "Check flexible array support - yes with ${C99_C_FLAGS_INTERNAL}")
+ set(FLEXIBLE_ARRAY_MEMBER "")
+else(FLEXIBLE_ARRAY_MEMBER)
+ message(STATUS "Check flexible array support - no")
+ set(FLEXIBLE_ARRAY_MEMBER 1)
+endif(FLEXIBLE_ARRAY_MEMBER)
\ No newline at end of file
diff --git a/cmake/CheckLLConstants.cmake b/cmake/CheckLLConstants.cmake
new file mode 100644
index 0000000000..68bf65fd02
--- /dev/null
+++ b/cmake/CheckLLConstants.cmake
@@ -0,0 +1,9 @@
+CHECK_C_SOURCE_COMPILES("
+ main() {
+ #define INT64CONST(x) x##LL
+ long long int foo = INT64CONST(0x1234567890123456);
+ return 0;
+ }
+" HAVE_LL_CONSTANTS)
+
+message(STATUS "HAVE_LL_CONSTANTS ${HAVE_LL_CONSTANTS}")
\ No newline at end of file
diff --git a/cmake/CheckSSE42.cmake b/cmake/CheckSSE42.cmake
new file mode 100644
index 0000000000..3fee3b4641
--- /dev/null
+++ b/cmake/CheckSSE42.cmake
@@ -0,0 +1,30 @@
+foreach(FLAG ";-msse4.2")
+ unset(HAVE_SSE42_INTRINSICS CACHE)
+ set(CMAKE_REQUIRED_FLAGS ${FLAG})
+ check_c_source_runs("
+ #include <nmmintrin.h>
+ int main(void) {
+ unsigned int crc = 0;
+ crc = _mm_crc32_u8(crc, 0);
+ crc = _mm_crc32_u32(crc, 0);
+ /* return computed value, to prevent the above being optimized away */
+ return !(crc == 0);
+ }
+ " HAVE_SSE42_INTRINSICS)
+ if (HAVE_SSE42_INTRINSICS)
+ set(CFLAGS_SSE42 ${FLAG})
+ break()
+ endif()
+endforeach()
+
+message(STATUS "SSE4.2 flags: ${CFLAGS_SSE42}")
+set(CMAKE_REQUIRED_FLAGS ${CFLAGS_SSE42})
+check_c_source_compiles("
+ #ifndef __SSE4_2__
+ #error __SSE4_2__ not defined
+ #endif
+ int main(void){
+ return 0;
+ }
+" HAVE_SSE42)
+set(CMAKE_REQUIRED_FLAGS "")
diff --git a/cmake/CheckSnprintfLongLongIntModifier.cmake b/cmake/CheckSnprintfLongLongIntModifier.cmake
new file mode 100644
index 0000000000..f07623890a
--- /dev/null
+++ b/cmake/CheckSnprintfLongLongIntModifier.cmake
@@ -0,0 +1,31 @@
+set(CMAKE_REQUIRED_INCLUDES "stdio.h")
+foreach(pgac_modifier "ll" "q" "I64")
+ unset(LONG_LONG_INT_MODIFIER CACHE)
+ CHECK_C_SOURCE_COMPILES("
+ typedef long long int ac_int64;
+
+ ac_int64 a = 20000001;
+ ac_int64 b = 40000005;
+
+ int does_int64_snprintf_work() {
+ ac_int64 c;
+ char buf[100];
+ if (sizeof(ac_int64) != 8)
+ return 0; /* doesn't look like the right size */
+
+ c = a * b;
+ snprintf(buf, 100, \"%${pgac_modifier}d\", c);
+ if (strcmp(buf, \"800000140000005\") != 0)
+ return 0; /* either multiply or snprintf is busted */
+ return 1;
+ }
+ main() {
+ exit(! does_int64_snprintf_work());
+ }
+ " LONG_LONG_INT_MODIFIER)
+ if(LONG_LONG_INT_MODIFIER)
+ set(LONG_LONG_INT_MODIFIER ${pgac_modifier})
+ break()
+ endif(LONG_LONG_INT_MODIFIER)
+endforeach(pgac_modifier)
+message(STATUS "LONG_LONG_INT_MODIFIER ${LONG_LONG_INT_MODIFIER}")
\ No newline at end of file
diff --git a/cmake/CheckTypeAlignment.cmake b/cmake/CheckTypeAlignment.cmake
new file mode 100644
index 0000000000..37cbb580d3
--- /dev/null
+++ b/cmake/CheckTypeAlignment.cmake
@@ -0,0 +1,29 @@
+macro(CHECK_TYPE_ALIGNMENT TYPE NAME)
+ if(NOT ${NAME})
+ message(STATUS "Check alignment of ${TYPE}")
+
+ set(INCLUDE_HEADERS "#include <stddef.h>
+ #include <stdio.h>
+ #include <stdlib.h>")
+
+ if(HAVE_STDINT_H)
+ set(INCLUDE_HEADERS "${INCLUDE_HEADERS}\n#include <stdint.h>\n")
+ endif(HAVE_STDINT_H)
+
+ file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/check_${NAME}_alignment.c"
+ "${INCLUDE_HEADERS}
+ int main(){
+ char diff;
+ struct foo {char a; ${TYPE} b;};
+ struct foo *p = (struct foo *) malloc(sizeof(struct foo));
+ diff = ((char *)&p->b) - ((char *)&p->a);
+ return diff;}
+ ")
+
+ try_run(${NAME} COMPILE_RESULT "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/"
+ "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/check_${NAME}_alignment.c")
+
+ message(STATUS "Check alignment of ${TYPE} - ${${NAME}}")
+
+ endif(NOT ${NAME})
+endmacro(CHECK_TYPE_ALIGNMENT TYPE NAME ALIGNOF_TYPE)
\ No newline at end of file
diff --git a/cmake/FindICU.cmake b/cmake/FindICU.cmake
new file mode 100644
index 0000000000..59dd891afa
--- /dev/null
+++ b/cmake/FindICU.cmake
@@ -0,0 +1,690 @@
+# This module can find the International Components for Unicode (ICU) libraries
+#
+# Requirements:
+# - CMake >= 2.8.3 (for new version of find_package_handle_standard_args)
+#
+# The following variables will be defined for your use:
+# - ICU_FOUND : were all of your specified components found?
+# - ICU_INCLUDE_DIRS : ICU include directory
+# - ICU_LIBRARIES : ICU libraries
+# - ICU_VERSION : complete version of ICU (x.y.z)
+# - ICU_VERSION_MAJOR : major version of ICU
+# - ICU_VERSION_MINOR : minor version of ICU
+# - ICU_VERSION_PATCH : patch version of ICU
+# - ICU_<COMPONENT>_FOUND : were <COMPONENT> found? (FALSE for non specified component if it is not a dependency)
+#
+# For windows or non standard installation, define ICU_ROOT_DIR variable to point to the root installation of ICU. Two ways:
+# - run cmake with -DICU_ROOT_DIR=<PATH>
+# - define an environment variable with the same name before running cmake
+# With cmake-gui, before pressing "Configure":
+# 1) Press "Add Entry" button
+# 2) Add a new entry defined as:
+# - Name: ICU_ROOT_DIR
+# - Type: choose PATH in the selection list
+# - Press "..." button and select the root installation of ICU
+#
+# Example Usage:
+#
+# 1. Copy this file in the root of your project source directory
+# 2. Then, tell CMake to search this non-standard module in your project directory by adding to your CMakeLists.txt:
+# set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR})
+# 3. Finally call find_package() once, here are some examples to pick from
+#
+# Require ICU 4.4 or later
+# find_package(ICU 4.4 REQUIRED)
+#
+# if(ICU_FOUND)
+# add_executable(myapp myapp.c)
+# include_directories(${ICU_INCLUDE_DIRS})
+# target_link_libraries(myapp ${ICU_LIBRARIES})
+# # with CMake >= 3.0.0, the last two lines can be replaced by the following
+# target_link_libraries(myapp ICU::ICU)
+# endif(ICU_FOUND)
+
+########## <ICU finding> ##########
+
+find_package(PkgConfig QUIET)
+
+########## Private ##########
+if(NOT DEFINED ICU_PUBLIC_VAR_NS)
+ set(ICU_PUBLIC_VAR_NS "ICU") # Prefix for all ICU relative public variables
+endif(NOT DEFINED ICU_PUBLIC_VAR_NS)
+if(NOT DEFINED ICU_PRIVATE_VAR_NS)
+ set(ICU_PRIVATE_VAR_NS "_${ICU_PUBLIC_VAR_NS}") # Prefix for all ICU relative internal variables
+endif(NOT DEFINED ICU_PRIVATE_VAR_NS)
+if(NOT DEFINED PC_ICU_PRIVATE_VAR_NS)
+ set(PC_ICU_PRIVATE_VAR_NS "_PC${ICU_PRIVATE_VAR_NS}") # Prefix for all pkg-config relative internal variables
+endif(NOT DEFINED PC_ICU_PRIVATE_VAR_NS)
+
+set(${ICU_PRIVATE_VAR_NS}_HINTS )
+# <deprecated>
+# for future removal
+if(DEFINED ENV{ICU_ROOT})
+ list(APPEND ${ICU_PRIVATE_VAR_NS}_HINTS "$ENV{ICU_ROOT}")
+ message(AUTHOR_WARNING "ENV{ICU_ROOT} is deprecated in favor of ENV{ICU_ROOT_DIR}")
+endif(DEFINED ENV{ICU_ROOT})
+if (DEFINED ICU_ROOT)
+ list(APPEND ${ICU_PRIVATE_VAR_NS}_HINTS "${ICU_ROOT}")
+ message(AUTHOR_WARNING "ICU_ROOT is deprecated in favor of ICU_ROOT_DIR")
+endif(DEFINED ICU_ROOT)
+# </deprecated>
+if(DEFINED ENV{ICU_ROOT_DIR})
+ list(APPEND ${ICU_PRIVATE_VAR_NS}_HINTS "$ENV{ICU_ROOT_DIR}")
+endif(DEFINED ENV{ICU_ROOT_DIR})
+if (DEFINED ICU_ROOT_DIR)
+ list(APPEND ${ICU_PRIVATE_VAR_NS}_HINTS "${ICU_ROOT_DIR}")
+endif(DEFINED ICU_ROOT_DIR)
+
+set(${ICU_PRIVATE_VAR_NS}_COMPONENTS )
+# <icu component name> <library name 1> ... <library name N>
+macro(_icu_declare_component _NAME)
+ list(APPEND ${ICU_PRIVATE_VAR_NS}_COMPONENTS ${_NAME})
+ set("${ICU_PRIVATE_VAR_NS}_COMPONENTS_${_NAME}" ${ARGN})
+endmacro(_icu_declare_component)
+
+_icu_declare_component(data icudata)
+_icu_declare_component(uc icuuc) # Common and Data libraries
+_icu_declare_component(i18n icui18n icuin) # Internationalization library
+_icu_declare_component(io icuio ustdio) # Stream and I/O Library
+_icu_declare_component(le icule) # Layout library
+_icu_declare_component(lx iculx) # Paragraph Layout library
+
+########## Public ##########
+set(${ICU_PUBLIC_VAR_NS}_FOUND FALSE)
+set(${ICU_PUBLIC_VAR_NS}_LIBRARIES )
+set(${ICU_PUBLIC_VAR_NS}_INCLUDE_DIRS )
+set(${ICU_PUBLIC_VAR_NS}_C_FLAGS "")
+set(${ICU_PUBLIC_VAR_NS}_CXX_FLAGS "")
+set(${ICU_PUBLIC_VAR_NS}_CPP_FLAGS "")
+set(${ICU_PUBLIC_VAR_NS}_C_SHARED_FLAGS "")
+set(${ICU_PUBLIC_VAR_NS}_CXX_SHARED_FLAGS "")
+set(${ICU_PUBLIC_VAR_NS}_CPP_SHARED_FLAGS "")
+
+foreach(${ICU_PRIVATE_VAR_NS}_COMPONENT ${${ICU_PRIVATE_VAR_NS}_COMPONENTS})
+ string(TOUPPER "${${ICU_PRIVATE_VAR_NS}_COMPONENT}" ${ICU_PRIVATE_VAR_NS}_UPPER_COMPONENT)
+ set("${ICU_PUBLIC_VAR_NS}_${${ICU_PRIVATE_VAR_NS}_UPPER_COMPONENT}_FOUND" FALSE) # may be done in the _icu_declare_component macro
+endforeach(${ICU_PRIVATE_VAR_NS}_COMPONENT)
+
+# Check components
+if(NOT ${ICU_PUBLIC_VAR_NS}_FIND_COMPONENTS) # uc required at least
+ set(${ICU_PUBLIC_VAR_NS}_FIND_COMPONENTS uc)
+else(NOT ${ICU_PUBLIC_VAR_NS}_FIND_COMPONENTS)
+ list(APPEND ${ICU_PUBLIC_VAR_NS}_FIND_COMPONENTS uc)
+ list(REMOVE_DUPLICATES ${ICU_PUBLIC_VAR_NS}_FIND_COMPONENTS)
+ foreach(${ICU_PRIVATE_VAR_NS}_COMPONENT ${${ICU_PUBLIC_VAR_NS}_FIND_COMPONENTS})
+ if(NOT DEFINED ${ICU_PRIVATE_VAR_NS}_COMPONENTS_${${ICU_PRIVATE_VAR_NS}_COMPONENT})
+ message(FATAL_ERROR "Unknown ICU component: ${${ICU_PRIVATE_VAR_NS}_COMPONENT}")
+ endif(NOT DEFINED ${ICU_PRIVATE_VAR_NS}_COMPONENTS_${${ICU_PRIVATE_VAR_NS}_COMPONENT})
+ endforeach(${ICU_PRIVATE_VAR_NS}_COMPONENT)
+endif(NOT ${ICU_PUBLIC_VAR_NS}_FIND_COMPONENTS)
+
+# if pkg-config is available check components dependencies and append `pkg-config icu-<component> --variable=prefix` to hints
+if(PKG_CONFIG_FOUND)
+ set(${ICU_PRIVATE_VAR_NS}_COMPONENTS_DUP ${${ICU_PUBLIC_VAR_NS}_FIND_COMPONENTS})
+ foreach(${ICU_PRIVATE_VAR_NS}_COMPONENT ${${ICU_PRIVATE_VAR_NS}_COMPONENTS_DUP})
+ pkg_check_modules(${PC_ICU_PRIVATE_VAR_NS} "icu-${${ICU_PRIVATE_VAR_NS}_COMPONENT}" QUIET)
+
+ if(${PC_ICU_PRIVATE_VAR_NS}_FOUND)
+ list(APPEND ${ICU_PRIVATE_VAR_NS}_HINTS ${${PC_ICU_PRIVATE_VAR_NS}_PREFIX})
+ foreach(${PC_ICU_PRIVATE_VAR_NS}_LIBRARY ${${PC_ICU_PRIVATE_VAR_NS}_LIBRARIES})
+ string(REGEX REPLACE "^icu" "" ${PC_ICU_PRIVATE_VAR_NS}_STRIPPED_LIBRARY ${${PC_ICU_PRIVATE_VAR_NS}_LIBRARY})
+ if(NOT ${PC_ICU_PRIVATE_VAR_NS}_STRIPPED_LIBRARY STREQUAL "data")
+ list(FIND ${ICU_PUBLIC_VAR_NS}_FIND_COMPONENTS ${${PC_ICU_PRIVATE_VAR_NS}_STRIPPED_LIBRARY} ${ICU_PRIVATE_VAR_NS}_COMPONENT_INDEX)
+ if(${ICU_PRIVATE_VAR_NS}_COMPONENT_INDEX EQUAL -1)
+ message(WARNING "Missing component dependency: ${${PC_ICU_PRIVATE_VAR_NS}_STRIPPED_LIBRARY}. Add it to your find_package(ICU) line as COMPONENTS to fix this warning.")
+ list(APPEND ${ICU_PUBLIC_VAR_NS}_FIND_COMPONENTS ${${PC_ICU_PRIVATE_VAR_NS}_STRIPPED_LIBRARY})
+ endif(${ICU_PRIVATE_VAR_NS}_COMPONENT_INDEX EQUAL -1)
+ endif(NOT ${PC_ICU_PRIVATE_VAR_NS}_STRIPPED_LIBRARY STREQUAL "data")
+ endforeach(${PC_ICU_PRIVATE_VAR_NS}_LIBRARY)
+ endif(${PC_ICU_PRIVATE_VAR_NS}_FOUND)
+ endforeach(${ICU_PRIVATE_VAR_NS}_COMPONENT)
+endif(PKG_CONFIG_FOUND)
+# list(APPEND ${ICU_PRIVATE_VAR_NS}_HINTS ENV ICU_ROOT_DIR)
+# message("${ICU_PRIVATE_VAR_NS}_HINTS = ${${ICU_PRIVATE_VAR_NS}_HINTS}")
+
+# Includes
+find_path(
+ ${ICU_PUBLIC_VAR_NS}_INCLUDE_DIR
+ NAMES unicode/utypes.h utypes.h
+ HINTS ${${ICU_PRIVATE_VAR_NS}_HINTS}
+ PATH_SUFFIXES "include"
+ DOC "Include directories for ICU"
+)
+
+if(${ICU_PUBLIC_VAR_NS}_INCLUDE_DIR)
+ ########## <part to keep synced with tests/version/CMakeLists.txt> ##########
+ if(EXISTS "${${ICU_PUBLIC_VAR_NS}_INCLUDE_DIR}/unicode/uvernum.h") # ICU >= 4.4
+ file(READ "${${ICU_PUBLIC_VAR_NS}_INCLUDE_DIR}/unicode/uvernum.h" ${ICU_PRIVATE_VAR_NS}_VERSION_HEADER_CONTENTS)
+ elseif(EXISTS "${${ICU_PUBLIC_VAR_NS}_INCLUDE_DIR}/unicode/uversion.h") # ICU [2;4.4[
+ file(READ "${${ICU_PUBLIC_VAR_NS}_INCLUDE_DIR}/unicode/uversion.h" ${ICU_PRIVATE_VAR_NS}_VERSION_HEADER_CONTENTS)
+ elseif(EXISTS "${${ICU_PUBLIC_VAR_NS}_INCLUDE_DIR}/unicode/utypes.h") # ICU [1.4;2[
+ file(READ "${${ICU_PUBLIC_VAR_NS}_INCLUDE_DIR}/unicode/utypes.h" ${ICU_PRIVATE_VAR_NS}_VERSION_HEADER_CONTENTS)
+ elseif(EXISTS "${${ICU_PUBLIC_VAR_NS}_INCLUDE_DIR}/utypes.h") # ICU 1.3
+ file(READ "${${ICU_PUBLIC_VAR_NS}_INCLUDE_DIR}/utypes.h" ${ICU_PRIVATE_VAR_NS}_VERSION_HEADER_CONTENTS)
+ else()
+ message(FATAL_ERROR "ICU version header not found")
+ endif()
+
+ if(${ICU_PRIVATE_VAR_NS}_VERSION_HEADER_CONTENTS MATCHES ".*# *define *ICU_VERSION *\"([0-9]+)\".*") # ICU 1.3
+ # [1.3;1.4[ as #define ICU_VERSION "3" (no patch version, ie all 1.3.X versions will be detected as 1.3.0)
+ set(${ICU_PUBLIC_VAR_NS}_VERSION_MAJOR "1")
+ set(${ICU_PUBLIC_VAR_NS}_VERSION_MINOR "${CMAKE_MATCH_1}")
+ set(${ICU_PUBLIC_VAR_NS}_VERSION_PATCH "0")
+ elseif(${ICU_PRIVATE_VAR_NS}_VERSION_HEADER_CONTENTS MATCHES ".*# *define *U_ICU_VERSION_MAJOR_NUM *([0-9]+).*")
+ #
+ # Since version 4.9.1, ICU release version numbering was totaly changed, see:
+ # - http://site.icu-project.org/download/49
+ # - http://userguide.icu-project.org/design#TOC-Version-Numbers-in-ICU
+ #
+ set(${ICU_PUBLIC_VAR_NS}_VERSION_MAJOR "${CMAKE_MATCH_1}")
+ string(REGEX REPLACE ".*# *define *U_ICU_VERSION_MINOR_NUM *([0-9]+).*" "\\1" ${ICU_PUBLIC_VAR_NS}_VERSION_MINOR "${${ICU_PRIVATE_VAR_NS}_VERSION_HEADER_CONTENTS}")
+ string(REGEX REPLACE ".*# *define *U_ICU_VERSION_PATCHLEVEL_NUM *([0-9]+).*" "\\1" ${ICU_PUBLIC_VAR_NS}_VERSION_PATCH "${${ICU_PRIVATE_VAR_NS}_VERSION_HEADER_CONTENTS}")
+ elseif(${ICU_PRIVATE_VAR_NS}_VERSION_HEADER_CONTENTS MATCHES ".*# *define *U_ICU_VERSION *\"(([0-9]+)(\\.[0-9]+)*)\".*") # ICU [1.4;1.8[
+ # [1.4;1.8[ as #define U_ICU_VERSION "1.4.1.2" but it seems that some 1.4.[12](?:\.\d)? have releasing error and appears as 1.4.0
+ set(${ICU_PRIVATE_VAR_NS}_FULL_VERSION "${CMAKE_MATCH_1}") # copy CMAKE_MATCH_1, no longer valid on the following if
+ if(${ICU_PRIVATE_VAR_NS}_FULL_VERSION MATCHES "^([0-9]+)\\.([0-9]+)$")
+ set(${ICU_PUBLIC_VAR_NS}_VERSION_MAJOR "${CMAKE_MATCH_1}")
+ set(${ICU_PUBLIC_VAR_NS}_VERSION_MINOR "${CMAKE_MATCH_2}")
+ set(${ICU_PUBLIC_VAR_NS}_VERSION_PATCH "0")
+ elseif(${ICU_PRIVATE_VAR_NS}_FULL_VERSION MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)")
+ set(${ICU_PUBLIC_VAR_NS}_VERSION_MAJOR "${CMAKE_MATCH_1}")
+ set(${ICU_PUBLIC_VAR_NS}_VERSION_MINOR "${CMAKE_MATCH_2}")
+ set(${ICU_PUBLIC_VAR_NS}_VERSION_PATCH "${CMAKE_MATCH_3}")
+ endif()
+ else()
+ message(FATAL_ERROR "failed to detect ICU version")
+ endif()
+ set(${ICU_PUBLIC_VAR_NS}_VERSION "${${ICU_PUBLIC_VAR_NS}_VERSION_MAJOR}.${${ICU_PUBLIC_VAR_NS}_VERSION_MINOR}.${${ICU_PUBLIC_VAR_NS}_VERSION_PATCH}")
+ ########## </part to keep synced with tests/version/CMakeLists.txt> ##########
+endif(${ICU_PUBLIC_VAR_NS}_INCLUDE_DIR)
+
+# Check libraries
+if(MSVC)
+ include(SelectLibraryConfigurations)
+endif(MSVC)
+foreach(${ICU_PRIVATE_VAR_NS}_COMPONENT ${${ICU_PUBLIC_VAR_NS}_FIND_COMPONENTS})
+ string(TOUPPER "${${ICU_PRIVATE_VAR_NS}_COMPONENT}" ${ICU_PRIVATE_VAR_NS}_UPPER_COMPONENT)
+ if(MSVC)
+ set(${ICU_PRIVATE_VAR_NS}_POSSIBLE_RELEASE_NAMES )
+ set(${ICU_PRIVATE_VAR_NS}_POSSIBLE_DEBUG_NAMES )
+ foreach(${ICU_PRIVATE_VAR_NS}_BASE_NAME ${${ICU_PRIVATE_VAR_NS}_COMPONENTS_${${ICU_PRIVATE_VAR_NS}_COMPONENT}})
+ list(APPEND ${ICU_PRIVATE_VAR_NS}_POSSIBLE_RELEASE_NAMES "${${ICU_PRIVATE_VAR_NS}_BASE_NAME}")
+ list(APPEND ${ICU_PRIVATE_VAR_NS}_POSSIBLE_DEBUG_NAMES "${${ICU_PRIVATE_VAR_NS}_BASE_NAME}d")
+ list(APPEND ${ICU_PRIVATE_VAR_NS}_POSSIBLE_RELEASE_NAMES "${${ICU_PRIVATE_VAR_NS}_BASE_NAME}${${ICU_PUBLIC_VAR_NS}_VERSION_MAJOR}${${ICU_PUBLIC_VAR_NS}_VERSION_MINOR}")
+ list(APPEND ${ICU_PRIVATE_VAR_NS}_POSSIBLE_DEBUG_NAMES "${${ICU_PRIVATE_VAR_NS}_BASE_NAME}${${ICU_PUBLIC_VAR_NS}_VERSION_MAJOR}${${ICU_PUBLIC_VAR_NS}_VERSION_MINOR}d")
+ endforeach(${ICU_PRIVATE_VAR_NS}_BASE_NAME)
+
+ find_library(
+ ${ICU_PUBLIC_VAR_NS}_${${ICU_PRIVATE_VAR_NS}_UPPER_COMPONENT}_LIBRARY_RELEASE
+ NAMES ${${ICU_PRIVATE_VAR_NS}_POSSIBLE_RELEASE_NAMES}
+ HINTS ${${ICU_PRIVATE_VAR_NS}_HINTS}
+ DOC "Release library for ICU ${${ICU_PRIVATE_VAR_NS}_COMPONENT} component"
+ )
+ find_library(
+ ${ICU_PUBLIC_VAR_NS}_${${ICU_PRIVATE_VAR_NS}_UPPER_COMPONENT}_LIBRARY_DEBUG
+ NAMES ${${ICU_PRIVATE_VAR_NS}_POSSIBLE_DEBUG_NAMES}
+ HINTS ${${ICU_PRIVATE_VAR_NS}_HINTS}
+ DOC "Debug library for ICU ${${ICU_PRIVATE_VAR_NS}_COMPONENT} component"
+ )
+
+ select_library_configurations("${ICU_PUBLIC_VAR_NS}_${${ICU_PRIVATE_VAR_NS}_UPPER_COMPONENT}")
+ list(APPEND ${ICU_PUBLIC_VAR_NS}_LIBRARY ${${ICU_PUBLIC_VAR_NS}_${${ICU_PRIVATE_VAR_NS}_UPPER_COMPONENT}_LIBRARY})
+ else(MSVC)
+ find_library(
+ ${ICU_PUBLIC_VAR_NS}_${${ICU_PRIVATE_VAR_NS}_UPPER_COMPONENT}_LIBRARY
+ NAMES ${${ICU_PRIVATE_VAR_NS}_COMPONENTS_${${ICU_PRIVATE_VAR_NS}_COMPONENT}}
+ PATHS ${${ICU_PRIVATE_VAR_NS}_HINTS}
+ DOC "Library for ICU ${${ICU_PRIVATE_VAR_NS}_COMPONENT} component"
+ )
+
+ if(${ICU_PUBLIC_VAR_NS}_${${ICU_PRIVATE_VAR_NS}_UPPER_COMPONENT}_LIBRARY)
+ set("${ICU_PUBLIC_VAR_NS}_${${ICU_PRIVATE_VAR_NS}_UPPER_COMPONENT}_FOUND" TRUE)
+ list(APPEND ${ICU_PUBLIC_VAR_NS}_LIBRARY ${${ICU_PUBLIC_VAR_NS}_${${ICU_PRIVATE_VAR_NS}_UPPER_COMPONENT}_LIBRARY})
+ endif(${ICU_PUBLIC_VAR_NS}_${${ICU_PRIVATE_VAR_NS}_UPPER_COMPONENT}_LIBRARY)
+ endif(MSVC)
+endforeach(${ICU_PRIVATE_VAR_NS}_COMPONENT)
+
+# Try to find out compiler flags
+find_program(${ICU_PUBLIC_VAR_NS}_CONFIG_EXECUTABLE icu-config HINTS ${${ICU_PRIVATE_VAR_NS}_HINTS})
+if(${ICU_PUBLIC_VAR_NS}_CONFIG_EXECUTABLE)
+ execute_process(COMMAND ${${ICU_PUBLIC_VAR_NS}_CONFIG_EXECUTABLE} --cflags OUTPUT_VARIABLE ${ICU_PUBLIC_VAR_NS}_C_FLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
+ execute_process(COMMAND ${${ICU_PUBLIC_VAR_NS}_CONFIG_EXECUTABLE} --cxxflags OUTPUT_VARIABLE ${ICU_PUBLIC_VAR_NS}_CXX_FLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
+ execute_process(COMMAND ${${ICU_PUBLIC_VAR_NS}_CONFIG_EXECUTABLE} --cppflags OUTPUT_VARIABLE ${ICU_PUBLIC_VAR_NS}_CPP_FLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ execute_process(COMMAND ${${ICU_PUBLIC_VAR_NS}_CONFIG_EXECUTABLE} --cflags-dynamic OUTPUT_VARIABLE ${ICU_PUBLIC_VAR_NS}_C_SHARED_FLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
+ execute_process(COMMAND ${${ICU_PUBLIC_VAR_NS}_CONFIG_EXECUTABLE} --cxxflags-dynamic OUTPUT_VARIABLE ${ICU_PUBLIC_VAR_NS}_CXX_SHARED_FLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
+ execute_process(COMMAND ${${ICU_PUBLIC_VAR_NS}_CONFIG_EXECUTABLE} --cppflags-dynamic OUTPUT_VARIABLE ${ICU_PUBLIC_VAR_NS}_CPP_SHARED_FLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
+endif(${ICU_PUBLIC_VAR_NS}_CONFIG_EXECUTABLE)
+
+# Check find_package arguments
+include(FindPackageHandleStandardArgs)
+if(${ICU_PUBLIC_VAR_NS}_FIND_REQUIRED AND NOT ${ICU_PUBLIC_VAR_NS}_FIND_QUIETLY)
+ find_package_handle_standard_args(
+ ${ICU_PUBLIC_VAR_NS}
+ REQUIRED_VARS ${ICU_PUBLIC_VAR_NS}_LIBRARY ${ICU_PUBLIC_VAR_NS}_INCLUDE_DIR
+ VERSION_VAR ${ICU_PUBLIC_VAR_NS}_VERSION
+ )
+else(${ICU_PUBLIC_VAR_NS}_FIND_REQUIRED AND NOT ${ICU_PUBLIC_VAR_NS}_FIND_QUIETLY)
+ find_package_handle_standard_args(${ICU_PUBLIC_VAR_NS} "Could NOT find ICU" ${ICU_PUBLIC_VAR_NS}_LIBRARY ${ICU_PUBLIC_VAR_NS}_INCLUDE_DIR)
+endif(${ICU_PUBLIC_VAR_NS}_FIND_REQUIRED AND NOT ${ICU_PUBLIC_VAR_NS}_FIND_QUIETLY)
+
+if(${ICU_PUBLIC_VAR_NS}_FOUND)
+ # <deprecated>
+ # for compatibility with previous versions, alias old ICU_(MAJOR|MINOR|PATCH)_VERSION to ICU_VERSION_$1
+ set(${ICU_PUBLIC_VAR_NS}_MAJOR_VERSION ${${ICU_PUBLIC_VAR_NS}_VERSION_MAJOR})
+ set(${ICU_PUBLIC_VAR_NS}_MINOR_VERSION ${${ICU_PUBLIC_VAR_NS}_VERSION_MINOR})
+ set(${ICU_PUBLIC_VAR_NS}_PATCH_VERSION ${${ICU_PUBLIC_VAR_NS}_VERSION_PATCH})
+ # </deprecated>
+ set(${ICU_PUBLIC_VAR_NS}_LIBRARIES ${${ICU_PUBLIC_VAR_NS}_LIBRARY})
+ set(${ICU_PUBLIC_VAR_NS}_INCLUDE_DIRS ${${ICU_PUBLIC_VAR_NS}_INCLUDE_DIR})
+
+ if(NOT CMAKE_VERSION VERSION_LESS "3.0.0")
+ if(NOT TARGET ICU::ICU)
+ add_library(ICU::ICU INTERFACE IMPORTED)
+ endif(NOT TARGET ICU::ICU)
+ set_target_properties(ICU::ICU PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${${ICU_PUBLIC_VAR_NS}_INCLUDE_DIR}")
+ foreach(${ICU_PRIVATE_VAR_NS}_COMPONENT ${${ICU_PUBLIC_VAR_NS}_FIND_COMPONENTS})
+ string(TOUPPER "${${ICU_PRIVATE_VAR_NS}_COMPONENT}" ${ICU_PRIVATE_VAR_NS}_UPPER_COMPONENT)
+ add_library("ICU::${${ICU_PRIVATE_VAR_NS}_UPPER_COMPONENT}" UNKNOWN IMPORTED)
+ if(${ICU_PUBLIC_VAR_NS}_${${ICU_PRIVATE_VAR_NS}_UPPER_COMPONENT}_LIBRARY_RELEASE)
+ set_property(TARGET "ICU::${${ICU_PRIVATE_VAR_NS}_UPPER_COMPONENT}" APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
+ set_target_properties("ICU::${${ICU_PRIVATE_VAR_NS}_UPPER_COMPONENT}" PROPERTIES IMPORTED_LOCATION_RELEASE "${${ICU_PUBLIC_VAR_NS}_${${ICU_PRIVATE_VAR_NS}_UPPER_COMPONENT}_LIBRARY_RELEASE}")
+ endif(${ICU_PUBLIC_VAR_NS}_${${ICU_PRIVATE_VAR_NS}_UPPER_COMPONENT}_LIBRARY_RELEASE)
+ if(${ICU_PUBLIC_VAR_NS}_${${ICU_PRIVATE_VAR_NS}_UPPER_COMPONENT}_LIBRARY_DEBUG)
+ set_property(TARGET "ICU::${${ICU_PRIVATE_VAR_NS}_UPPER_COMPONENT}" APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
+ set_target_properties("ICU::${${ICU_PRIVATE_VAR_NS}_UPPER_COMPONENT}" PROPERTIES IMPORTED_LOCATION_DEBUG "${${ICU_PUBLIC_VAR_NS}_${${ICU_PRIVATE_VAR_NS}_UPPER_COMPONENT}_LIBRARY_DEBUG}")
+ endif(${ICU_PUBLIC_VAR_NS}_${${ICU_PRIVATE_VAR_NS}_UPPER_COMPONENT}_LIBRARY_DEBUG)
+ if(${ICU_PUBLIC_VAR_NS}_${${ICU_PRIVATE_VAR_NS}_UPPER_COMPONENT}_LIBRARY)
+ set_target_properties("ICU::${${ICU_PRIVATE_VAR_NS}_UPPER_COMPONENT}" PROPERTIES IMPORTED_LOCATION "${${ICU_PUBLIC_VAR_NS}_${${ICU_PRIVATE_VAR_NS}_UPPER_COMPONENT}_LIBRARY}")
+ endif(${ICU_PUBLIC_VAR_NS}_${${ICU_PRIVATE_VAR_NS}_UPPER_COMPONENT}_LIBRARY)
+ set_property(TARGET ICU::ICU APPEND PROPERTY INTERFACE_LINK_LIBRARIES "ICU::${${ICU_PRIVATE_VAR_NS}_UPPER_COMPONENT}")
+# set_target_properties("ICU::${${ICU_PRIVATE_VAR_NS}_UPPER_COMPONENT}" PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${${ICU_PUBLIC_VAR_NS}_INCLUDE_DIR}")
+ endforeach(${ICU_PRIVATE_VAR_NS}_COMPONENT)
+ endif(NOT CMAKE_VERSION VERSION_LESS "3.0.0")
+endif(${ICU_PUBLIC_VAR_NS}_FOUND)
+
+mark_as_advanced(
+ ${ICU_PUBLIC_VAR_NS}_INCLUDE_DIR
+ ${ICU_PUBLIC_VAR_NS}_LIBRARY
+)
+
+########## </ICU finding> ##########
+
+########## <resource bundle support> ##########
+
+########## Private ##########
+function(_icu_extract_locale_from_rb _BUNDLE_SOURCE _RETURN_VAR_NAME)
+ file(READ "${_BUNDLE_SOURCE}" _BUNDLE_CONTENTS)
+ string(REGEX REPLACE "//[^\n]*\n" "" _BUNDLE_CONTENTS_WITHOUT_COMMENTS ${_BUNDLE_CONTENTS})
+ string(REGEX REPLACE "[ \t\n]" "" _BUNDLE_CONTENTS_WITHOUT_COMMENTS_AND_SPACES ${_BUNDLE_CONTENTS_WITHOUT_COMMENTS})
+ string(REGEX MATCH "^([a-zA-Z_-]+)(:table)?{" LOCALE_FOUND ${_BUNDLE_CONTENTS_WITHOUT_COMMENTS_AND_SPACES})
+ set("${_RETURN_VAR_NAME}" "${CMAKE_MATCH_1}" PARENT_SCOPE)
+endfunction(_icu_extract_locale_from_rb)
+
+########## Public ##########
+
+#
+# Prototype:
+# icu_generate_resource_bundle([NAME <name>] [PACKAGE] [DESTINATION <location>] [FILES <list of files>])
+#
+# Common arguments:
+# - NAME <name> : name of output package and to create dummy targets
+# - FILES <file 1> ... <file N> : list of resource bundles sources
+# - DEPENDS <target1> ... <target N> : required to package as library (shared or static), a list of cmake parent targets to link to
+# Note: only (PREVIOUSLY DECLARED) add_executable and add_library as dependencies
+# - DESTINATION <location> : optional, directory where to install final binary file(s)
+# - FORMAT <name> : optional, one of none (ICU4C binary format, default), java (plain java) or xliff (XML), see below
+#
+# Arguments depending on FORMAT:
+# - none (default):
+# * PACKAGE : if present, package all resource bundles together. Default is to stop after building individual *.res files
+# * TYPE <name> : one of :
+# + common or archive (default) : archive all ressource bundles into a single .dat file
+# + library or dll : assemble all ressource bundles into a separate and loadable library (.dll/.so)
+# + static : integrate all ressource bundles to targets designed by DEPENDS parameter (as a static library)
+# * NO_SHARED_FLAGS : only with TYPE in ['library', 'dll', 'static'], do not append ICU_C(XX)_SHARED_FLAGS to targets given as DEPENDS argument
+# - JAVA:
+# * BUNDLE <name> : required, prefix for generated classnames
+# - XLIFF:
+# (none)
+#
+
+#
+# For an archive, the idea is to generate the following dependencies:
+#
+# root.txt => root.res \
+# |
+# en.txt => en.res |
+# | => pkglist.txt => application.dat
+# fr.txt => fr.res |
+# |
+# and so on /
+#
+# Lengend: 'A => B' means B depends on A
+#
+# Steps (correspond to arrows):
+# 1) genrb (from .txt to .res)
+# 2) generate a file text (pkglist.txt) with all .res files to put together
+# 3) build final archive (from *.res/pkglist.txt to .dat)
+#
+
+function(icu_generate_resource_bundle)
+
+ ##### <check for pkgdata/genrb availability> #####
+ find_program(${ICU_PUBLIC_VAR_NS}_GENRB_EXECUTABLE genrb HINTS ${${ICU_PRIVATE_VAR_NS}_HINTS})
+ find_program(${ICU_PUBLIC_VAR_NS}_PKGDATA_EXECUTABLE pkgdata HINTS ${${ICU_PRIVATE_VAR_NS}_HINTS})
+
+ if(NOT ${ICU_PUBLIC_VAR_NS}_GENRB_EXECUTABLE)
+ message(FATAL_ERROR "genrb not found")
+ endif(NOT ${ICU_PUBLIC_VAR_NS}_GENRB_EXECUTABLE)
+ if(NOT ${ICU_PUBLIC_VAR_NS}_PKGDATA_EXECUTABLE)
+ message(FATAL_ERROR "pkgdata not found")
+ endif(NOT ${ICU_PUBLIC_VAR_NS}_PKGDATA_EXECUTABLE)
+ ##### </check for pkgdata/genrb availability> #####
+
+ ##### <constants> #####
+ set(TARGET_SEPARATOR "+")
+ set(__FUNCTION__ "icu_generate_resource_bundle")
+ set(PACKAGE_TARGET_PREFIX "ICU${TARGET_SEPARATOR}PKG")
+ set(RESOURCE_TARGET_PREFIX "ICU${TARGET_SEPARATOR}RB")
+ ##### </constants> #####
+
+ ##### <hash constants> #####
+ # filename extension of built resource bundle (without dot)
+ set(BUNDLES__SUFFIX "res")
+ set(BUNDLES_JAVA_SUFFIX "java")
+ set(BUNDLES_XLIFF_SUFFIX "xlf")
+ # alias: none (default) = common = archive ; dll = library ; static
+ set(PKGDATA__ALIAS "")
+ set(PKGDATA_COMMON_ALIAS "")
+ set(PKGDATA_ARCHIVE_ALIAS "")
+ set(PKGDATA_DLL_ALIAS "LIBRARY")
+ set(PKGDATA_LIBRARY_ALIAS "LIBRARY")
+ set(PKGDATA_STATIC_ALIAS "STATIC")
+ # filename prefix of built package
+ set(PKGDATA__PREFIX "")
+ set(PKGDATA_LIBRARY_PREFIX "${CMAKE_SHARED_LIBRARY_PREFIX}")
+ set(PKGDATA_STATIC_PREFIX "${CMAKE_STATIC_LIBRARY_PREFIX}")
+ # filename extension of built package (with dot)
+ set(PKGDATA__SUFFIX ".dat")
+ set(PKGDATA_LIBRARY_SUFFIX "${CMAKE_SHARED_LIBRARY_SUFFIX}")
+ set(PKGDATA_STATIC_SUFFIX "${CMAKE_STATIC_LIBRARY_SUFFIX}")
+ # pkgdata option mode specific
+ set(PKGDATA__OPTIONS "-m" "common")
+ set(PKGDATA_STATIC_OPTIONS "-m" "static")
+ set(PKGDATA_LIBRARY_OPTIONS "-m" "library")
+ # cmake library type for output package
+ set(PKGDATA_LIBRARY__TYPE "")
+ set(PKGDATA_LIBRARY_STATIC_TYPE STATIC)
+ set(PKGDATA_LIBRARY_LIBRARY_TYPE SHARED)
+ ##### </hash constants> #####
+
+ include(CMakeParseArguments)
+ cmake_parse_arguments(
+ PARSED_ARGS # output variable name
+ # options (true/false) (default value: false)
+ "PACKAGE;NO_SHARED_FLAGS"
+ # univalued parameters (default value: "")
+ "NAME;DESTINATION;TYPE;FORMAT;BUNDLE"
+ # multivalued parameters (default value: "")
+ "FILES;DEPENDS"
+ ${ARGN}
+ )
+
+ # assert(${PARSED_ARGS_NAME} != "")
+ if(NOT PARSED_ARGS_NAME)
+ message(FATAL_ERROR "${__FUNCTION__}(): no name given, NAME parameter missing")
+ endif(NOT PARSED_ARGS_NAME)
+
+ # assert(length(PARSED_ARGS_FILES) > 0)
+ list(LENGTH PARSED_ARGS_FILES PARSED_ARGS_FILES_LEN)
+ if(PARSED_ARGS_FILES_LEN LESS 1)
+ message(FATAL_ERROR "${__FUNCTION__}() expects at least 1 resource bundle as FILES argument, 0 given")
+ endif(PARSED_ARGS_FILES_LEN LESS 1)
+
+ string(TOUPPER "${PARSED_ARGS_FORMAT}" UPPER_FORMAT)
+ # assert(${UPPER_FORMAT} in ['', 'java', 'xlif'])
+ if(NOT DEFINED BUNDLES_${UPPER_FORMAT}_SUFFIX)
+ message(FATAL_ERROR "${__FUNCTION__}(): unknown FORMAT '${PARSED_ARGS_FORMAT}'")
+ endif(NOT DEFINED BUNDLES_${UPPER_FORMAT}_SUFFIX)
+
+ if(UPPER_FORMAT STREQUAL "JAVA")
+ # assert(${PARSED_ARGS_BUNDLE} != "")
+ if(NOT PARSED_ARGS_BUNDLE)
+ message(FATAL_ERROR "${__FUNCTION__}(): java bundle name expected, BUNDLE parameter missing")
+ endif(NOT PARSED_ARGS_BUNDLE)
+ endif(UPPER_FORMAT STREQUAL "JAVA")
+
+ if(PARSED_ARGS_PACKAGE)
+ # assert(${PARSED_ARGS_FORMAT} == "")
+ if(PARSED_ARGS_FORMAT)
+ message(FATAL_ERROR "${__FUNCTION__}(): packaging is only supported for binary format, not xlif neither java outputs")
+ endif(PARSED_ARGS_FORMAT)
+
+ string(TOUPPER "${PARSED_ARGS_TYPE}" UPPER_MODE)
+ # assert(${UPPER_MODE} in ['', 'common', 'archive', 'dll', library'])
+ if(NOT DEFINED PKGDATA_${UPPER_MODE}_ALIAS)
+ message(FATAL_ERROR "${__FUNCTION__}(): unknown TYPE '${PARSED_ARGS_TYPE}'")
+ else(NOT DEFINED PKGDATA_${UPPER_MODE}_ALIAS)
+ set(TYPE "${PKGDATA_${UPPER_MODE}_ALIAS}")
+ endif(NOT DEFINED PKGDATA_${UPPER_MODE}_ALIAS)
+
+ # Package name: strip file extension if present
+ get_filename_component(PACKAGE_NAME_WE ${PARSED_ARGS_NAME} NAME_WE)
+ # Target name to build package
+ set(PACKAGE_TARGET_NAME "${PACKAGE_TARGET_PREFIX}${TARGET_SEPARATOR}${PACKAGE_NAME_WE}")
+ # Target name to build intermediate list file
+ set(PACKAGE_LIST_TARGET_NAME "${PACKAGE_TARGET_NAME}${TARGET_SEPARATOR}PKGLIST")
+ # Directory (absolute) to set as "current directory" for genrb (does not include package directory, -p)
+ # We make our "cook" there to prevent any conflict
+ if(DEFINED CMAKE_PLATFORM_ROOT_BIN) # CMake < 2.8.10
+ set(RESOURCE_GENRB_CHDIR_DIR "${CMAKE_PLATFORM_ROOT_BIN}/${PACKAGE_TARGET_NAME}.dir/")
+ else(DEFINED CMAKE_PLATFORM_ROOT_BIN) # CMake >= 2.8.10
+ set(RESOURCE_GENRB_CHDIR_DIR "${CMAKE_PLATFORM_INFO_DIR}/${PACKAGE_TARGET_NAME}.dir/")
+ endif(DEFINED CMAKE_PLATFORM_ROOT_BIN)
+ # Directory (absolute) where resource bundles are built: concatenation of RESOURCE_GENRB_CHDIR_DIR and package name
+ set(RESOURCE_OUTPUT_DIR "${RESOURCE_GENRB_CHDIR_DIR}/${PACKAGE_NAME_WE}/")
+ # Output (relative) path for built package
+ if(MSVC AND TYPE STREQUAL PKGDATA_LIBRARY_ALIAS)
+ set(PACKAGE_OUTPUT_PATH "${RESOURCE_GENRB_CHDIR_DIR}/${PACKAGE_NAME_WE}/${PKGDATA_${TYPE}_PREFIX}${PACKAGE_NAME_WE}${PKGDATA_${TYPE}_SUFFIX}")
+ else(MSVC AND TYPE STREQUAL PKGDATA_LIBRARY_ALIAS)
+ set(PACKAGE_OUTPUT_PATH "${RESOURCE_GENRB_CHDIR_DIR}/${PKGDATA_${TYPE}_PREFIX}${PACKAGE_NAME_WE}${PKGDATA_${TYPE}_SUFFIX}")
+ endif(MSVC AND TYPE STREQUAL PKGDATA_LIBRARY_ALIAS)
+ # Output (absolute) path for the list file
+ set(PACKAGE_LIST_OUTPUT_PATH "${RESOURCE_GENRB_CHDIR_DIR}/pkglist.txt")
+
+ file(MAKE_DIRECTORY "${RESOURCE_OUTPUT_DIR}")
+ else(PARSED_ARGS_PACKAGE)
+ set(RESOURCE_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/")
+# set(RESOURCE_GENRB_CHDIR_DIR "UNUSED")
+ endif(PARSED_ARGS_PACKAGE)
+
+ set(TARGET_RESOURCES )
+ set(COMPILED_RESOURCES_PATH )
+ set(COMPILED_RESOURCES_BASENAME )
+ foreach(RESOURCE_SOURCE ${PARSED_ARGS_FILES})
+ _icu_extract_locale_from_rb(${RESOURCE_SOURCE} RESOURCE_NAME_WE)
+ get_filename_component(SOURCE_BASENAME ${RESOURCE_SOURCE} NAME)
+ get_filename_component(ABSOLUTE_SOURCE ${RESOURCE_SOURCE} ABSOLUTE)
+
+ if(UPPER_FORMAT STREQUAL "XLIFF")
+ if(RESOURCE_NAME_WE STREQUAL "root")
+ set(XLIFF_LANGUAGE "en")
+ else(RESOURCE_NAME_WE STREQUAL "root")
+ string(REGEX REPLACE "[^a-z].*$" "" XLIFF_LANGUAGE "${RESOURCE_NAME_WE}")
+ endif(RESOURCE_NAME_WE STREQUAL "root")
+ endif(UPPER_FORMAT STREQUAL "XLIFF")
+
+ ##### <templates> #####
+ set(RESOURCE_TARGET_NAME "${RESOURCE_TARGET_PREFIX}${TARGET_SEPARATOR}${PARSED_ARGS_NAME}${TARGET_SEPARATOR}${RESOURCE_NAME_WE}")
+
+ set(RESOURCE_OUTPUT__PATH "${RESOURCE_NAME_WE}.res")
+ if(RESOURCE_NAME_WE STREQUAL "root")
+ set(RESOURCE_OUTPUT_JAVA_PATH "${PARSED_ARGS_BUNDLE}.java")
+ else(RESOURCE_NAME_WE STREQUAL "root")
+ set(RESOURCE_OUTPUT_JAVA_PATH "${PARSED_ARGS_BUNDLE}_${RESOURCE_NAME_WE}.java")
+ endif(RESOURCE_NAME_WE STREQUAL "root")
+ set(RESOURCE_OUTPUT_XLIFF_PATH "${RESOURCE_NAME_WE}.xlf")
+
+ set(GENRB__OPTIONS "")
+ set(GENRB_JAVA_OPTIONS "-j" "-b" "${PARSED_ARGS_BUNDLE}")
+ set(GENRB_XLIFF_OPTIONS "-x" "-l" "${XLIFF_LANGUAGE}")
+ ##### </templates> #####
+
+ # build <locale>.txt from <locale>.res
+ if(PARSED_ARGS_PACKAGE)
+ add_custom_command(
+ OUTPUT "${RESOURCE_OUTPUT_DIR}${RESOURCE_OUTPUT_${UPPER_FORMAT}_PATH}"
+ COMMAND ${CMAKE_COMMAND} -E chdir ${RESOURCE_GENRB_CHDIR_DIR} ${${ICU_PUBLIC_VAR_NS}_GENRB_EXECUTABLE} ${GENRB_${UPPER_FORMAT}_OPTIONS} -d ${PACKAGE_NAME_WE} ${ABSOLUTE_SOURCE}
+ DEPENDS ${RESOURCE_SOURCE}
+ )
+ else(PARSED_ARGS_PACKAGE)
+ add_custom_command(
+ OUTPUT "${RESOURCE_OUTPUT_DIR}${RESOURCE_OUTPUT_${UPPER_FORMAT}_PATH}"
+ COMMAND ${${ICU_PUBLIC_VAR_NS}_GENRB_EXECUTABLE} ${GENRB_${UPPER_FORMAT}_OPTIONS} -d ${RESOURCE_OUTPUT_DIR} ${ABSOLUTE_SOURCE}
+ DEPENDS ${RESOURCE_SOURCE}
+ )
+ endif(PARSED_ARGS_PACKAGE)
+ # dummy target (ICU+RB+<name>+<locale>) for each locale to build the <locale>.res file from its <locale>.txt by the add_custom_command above
+ add_custom_target(
+ "${RESOURCE_TARGET_NAME}" ALL
+ COMMENT ""
+ DEPENDS "${RESOURCE_OUTPUT_DIR}${RESOURCE_OUTPUT_${UPPER_FORMAT}_PATH}"
+ SOURCES ${RESOURCE_SOURCE}
+ )
+
+ if(PARSED_ARGS_DESTINATION AND NOT PARSED_ARGS_PACKAGE)
+ install(FILES "${RESOURCE_OUTPUT_DIR}${RESOURCE_OUTPUT_${UPPER_FORMAT}_PATH}" DESTINATION ${PARSED_ARGS_DESTINATION} PERMISSIONS OWNER_READ GROUP_READ WORLD_READ)
+ endif(PARSED_ARGS_DESTINATION AND NOT PARSED_ARGS_PACKAGE)
+
+ list(APPEND TARGET_RESOURCES "${RESOURCE_TARGET_NAME}")
+ list(APPEND COMPILED_RESOURCES_PATH "${RESOURCE_OUTPUT_DIR}${RESOURCE_OUTPUT_${UPPER_FORMAT}_PATH}")
+ list(APPEND COMPILED_RESOURCES_BASENAME "${RESOURCE_NAME_WE}.${BUNDLES_${UPPER_FORMAT}_SUFFIX}")
+ endforeach(RESOURCE_SOURCE)
+ # convert semicolon separated list to a space separated list
+ # NOTE: if the pkglist.txt file starts (or ends?) with a whitespace, pkgdata add an undefined symbol (named <package>_) for it
+ string(REPLACE ";" " " COMPILED_RESOURCES_BASENAME "${COMPILED_RESOURCES_BASENAME}")
+
+ if(PARSED_ARGS_PACKAGE)
+ # create a text file (pkglist.txt) with the list of the *.res to package together
+ add_custom_command(
+ OUTPUT "${PACKAGE_LIST_OUTPUT_PATH}"
+ COMMAND ${CMAKE_COMMAND} -E echo "${COMPILED_RESOURCES_BASENAME}" > "${PACKAGE_LIST_OUTPUT_PATH}"
+ DEPENDS ${COMPILED_RESOURCES_PATH}
+ )
+ # run pkgdata from pkglist.txt
+ add_custom_command(
+ OUTPUT "${PACKAGE_OUTPUT_PATH}"
+ COMMAND ${CMAKE_COMMAND} -E chdir ${RESOURCE_GENRB_CHDIR_DIR} ${${ICU_PUBLIC_VAR_NS}_PKGDATA_EXECUTABLE} -F ${PKGDATA_${TYPE}_OPTIONS} -s ${PACKAGE_NAME_WE} -p ${PACKAGE_NAME_WE} ${PACKAGE_LIST_OUTPUT_PATH}
+ DEPENDS "${PACKAGE_LIST_OUTPUT_PATH}"
+ VERBATIM
+ )
+ if(PKGDATA_LIBRARY_${TYPE}_TYPE)
+ # assert(${PARSED_ARGS_DEPENDS} != "")
+ if(NOT PARSED_ARGS_DEPENDS)
+ message(FATAL_ERROR "${__FUNCTION__}(): static and library mode imply a list of targets to link to, DEPENDS parameter missing")
+ endif(NOT PARSED_ARGS_DEPENDS)
+ add_library(${PACKAGE_TARGET_NAME} ${PKGDATA_LIBRARY_${TYPE}_TYPE} IMPORTED)
+ if(MSVC)
+ string(REGEX REPLACE "${PKGDATA_LIBRARY_SUFFIX}\$" "${CMAKE_IMPORT_LIBRARY_SUFFIX}" PACKAGE_OUTPUT_LIB "${PACKAGE_OUTPUT_PATH}")
+ set_target_properties(${PACKAGE_TARGET_NAME} PROPERTIES IMPORTED_LOCATION ${PACKAGE_OUTPUT_PATH} IMPORTED_IMPLIB ${PACKAGE_OUTPUT_LIB})
+ else(MSVC)
+ set_target_properties(${PACKAGE_TARGET_NAME} PROPERTIES IMPORTED_LOCATION ${PACKAGE_OUTPUT_PATH})
+ endif(MSVC)
+ foreach(DEPENDENCY ${PARSED_ARGS_DEPENDS})
+ target_link_libraries(${DEPENDENCY} ${PACKAGE_TARGET_NAME})
+ if(NOT PARSED_ARGS_NO_SHARED_FLAGS)
+ get_property(ENABLED_LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES)
+ list(LENGTH "${ENABLED_LANGUAGES}" ENABLED_LANGUAGES_LENGTH)
+ if(ENABLED_LANGUAGES_LENGTH GREATER 1)
+ message(WARNING "Project has more than one language enabled, skip automatic shared flags appending")
+ else(ENABLED_LANGUAGES_LENGTH GREATER 1)
+ set_property(TARGET "${DEPENDENCY}" APPEND PROPERTY COMPILE_FLAGS "${${ICU_PUBLIC_VAR_NS}_${ENABLED_LANGUAGES}_SHARED_FLAGS}")
+ endif(ENABLED_LANGUAGES_LENGTH GREATER 1)
+ endif(NOT PARSED_ARGS_NO_SHARED_FLAGS)
+ endforeach(DEPENDENCY)
+ # http://www.mail-archive.com/cmake-commits@cmake.org/msg01135.html
+ set(PACKAGE_INTERMEDIATE_TARGET_NAME "${PACKAGE_TARGET_NAME}${TARGET_SEPARATOR}DUMMY")
+ # dummy intermediate target (ICU+PKG+<name>+DUMMY) to link the package to the produced library by running pkgdata (see add_custom_command above)
+ add_custom_target(
+ ${PACKAGE_INTERMEDIATE_TARGET_NAME}
+ COMMENT ""
+ DEPENDS "${PACKAGE_OUTPUT_PATH}"
+ )
+ add_dependencies("${PACKAGE_TARGET_NAME}" "${PACKAGE_INTERMEDIATE_TARGET_NAME}")
+ else(PKGDATA_LIBRARY_${TYPE}_TYPE)
+ # dummy target (ICU+PKG+<name>) to run pkgdata (see add_custom_command above)
+ add_custom_target(
+ "${PACKAGE_TARGET_NAME}" ALL
+ COMMENT ""
+ DEPENDS "${PACKAGE_OUTPUT_PATH}"
+ )
+ endif(PKGDATA_LIBRARY_${TYPE}_TYPE)
+ # dummy target (ICU+PKG+<name>+PKGLIST) to build the file pkglist.txt
+ add_custom_target(
+ "${PACKAGE_LIST_TARGET_NAME}" ALL
+ COMMENT ""
+ DEPENDS "${PACKAGE_LIST_OUTPUT_PATH}"
+ )
+ # package => pkglist.txt
+ add_dependencies("${PACKAGE_TARGET_NAME}" "${PACKAGE_LIST_TARGET_NAME}")
+ # pkglist.txt => *.res
+ add_dependencies("${PACKAGE_LIST_TARGET_NAME}" ${TARGET_RESOURCES})
+
+ if(PARSED_ARGS_DESTINATION)
+ install(FILES "${PACKAGE_OUTPUT_PATH}" DESTINATION ${PARSED_ARGS_DESTINATION} PERMISSIONS OWNER_READ GROUP_READ WORLD_READ)
+ endif(PARSED_ARGS_DESTINATION)
+ endif(PARSED_ARGS_PACKAGE)
+
+endfunction(icu_generate_resource_bundle)
+
+########## </resource bundle support> ##########
+
+########## <debug> ##########
+
+if(${ICU_PUBLIC_VAR_NS}_DEBUG)
+
+ function(icudebug _VARNAME)
+ if(DEFINED ${ICU_PUBLIC_VAR_NS}_${_VARNAME})
+ message("${ICU_PUBLIC_VAR_NS}_${_VARNAME} = ${${ICU_PUBLIC_VAR_NS}_${_VARNAME}}")
+ else(DEFINED ${ICU_PUBLIC_VAR_NS}_${_VARNAME})
+ message("${ICU_PUBLIC_VAR_NS}_${_VARNAME} = <UNDEFINED>")
+ endif(DEFINED ${ICU_PUBLIC_VAR_NS}_${_VARNAME})
+ endfunction(icudebug)
+
+ # IN (args)
+ icudebug("FIND_COMPONENTS")
+ icudebug("FIND_REQUIRED")
+ icudebug("FIND_QUIETLY")
+ icudebug("FIND_VERSION")
+
+ # OUT
+ # Found
+ icudebug("FOUND")
+ # Flags
+ icudebug("C_FLAGS")
+ icudebug("CPP_FLAGS")
+ icudebug("CXX_FLAGS")
+ icudebug("C_SHARED_FLAGS")
+ icudebug("CPP_SHARED_FLAGS")
+ icudebug("CXX_SHARED_FLAGS")
+ # Linking
+ icudebug("INCLUDE_DIRS")
+ icudebug("LIBRARIES")
+ # Version
+ icudebug("VERSION_MAJOR")
+ icudebug("VERSION_MINOR")
+ icudebug("VERSION_PATCH")
+ icudebug("VERSION")
+ # <COMPONENT>_(FOUND|LIBRARY)
+ set(${ICU_PRIVATE_VAR_NS}_COMPONENT_VARIABLES "FOUND" "LIBRARY" "LIBRARY_RELEASE" "LIBRARY_DEBUG")
+ foreach(${ICU_PRIVATE_VAR_NS}_COMPONENT ${${ICU_PRIVATE_VAR_NS}_COMPONENTS})
+ string(TOUPPER "${${ICU_PRIVATE_VAR_NS}_COMPONENT}" ${ICU_PRIVATE_VAR_NS}_UPPER_COMPONENT)
+ foreach(${ICU_PRIVATE_VAR_NS}_COMPONENT_VARIABLE ${${ICU_PRIVATE_VAR_NS}_COMPONENT_VARIABLES})
+ icudebug("${${ICU_PRIVATE_VAR_NS}_UPPER_COMPONENT}_${${ICU_PRIVATE_VAR_NS}_COMPONENT_VARIABLE}")
+ endforeach(${ICU_PRIVATE_VAR_NS}_COMPONENT_VARIABLE)
+ endforeach(${ICU_PRIVATE_VAR_NS}_COMPONENT)
+
+endif(${ICU_PUBLIC_VAR_NS}_DEBUG)
+
+########## </debug> ##########
diff --git a/cmake/FindLDAP.cmake b/cmake/FindLDAP.cmake
new file mode 100644
index 0000000000..8a5bc6315f
--- /dev/null
+++ b/cmake/FindLDAP.cmake
@@ -0,0 +1,41 @@
+# - Try to find the LDAP client libraries
+# Once done this will define
+#
+# LDAP_FOUND - system has libldap
+# LDAP_INCLUDE_DIR - the ldap include directory
+# LDAP_LIBRARIES - libldap + liblber (if found) library
+# LBER_LIBRARIES - liblber library
+
+if(LDAP_INCLUDE_DIR AND LDAP_LIBRARIES)
+ # Already in cache, be silent
+ set(Ldap_FIND_QUIETLY TRUE)
+endif(LDAP_INCLUDE_DIR AND LDAP_LIBRARIES)
+
+if(UNIX)
+ FIND_PATH(LDAP_INCLUDE_DIR ldap.h)
+ FIND_LIBRARY(LDAP_LIBRARIES NAMES ldap)
+ FIND_LIBRARY(LBER_LIBRARIES NAMES lber)
+
+else(UNIX)
+ FIND_PATH(LDAP_INCLUDE_DIR winldap.h)
+ FIND_LIBRARY(LDAP_LIBRARIES NAMES wldap32)
+endif(UNIX)
+
+if(LDAP_INCLUDE_DIR AND LDAP_LIBRARIES)
+ set(LDAP_FOUND TRUE)
+ if(LBER_LIBRARIES)
+ set(LDAP_LIBRARIES ${LDAP_LIBRARIES} ${LBER_LIBRARIES})
+ endif(LBER_LIBRARIES)
+endif(LDAP_INCLUDE_DIR AND LDAP_LIBRARIES)
+
+if(LDAP_FOUND)
+ if(NOT Ldap_FIND_QUIETLY)
+ message(STATUS "Found ldap: ${LDAP_LIBRARIES}")
+ endif(NOT Ldap_FIND_QUIETLY)
+else(LDAP_FOUND)
+ if (Ldap_FIND_REQUIRED)
+ message(FATAL_ERROR "Could NOT find ldap")
+ endif (Ldap_FIND_REQUIRED)
+endif(LDAP_FOUND)
+
+MARK_AS_ADVANCED(LDAP_INCLUDE_DIR LDAP_LIBRARIES LBER_LIBRARIES)
diff --git a/cmake/FindLibSocket.cmake b/cmake/FindLibSocket.cmake
new file mode 100644
index 0000000000..148f4ec296
--- /dev/null
+++ b/cmake/FindLibSocket.cmake
@@ -0,0 +1,11 @@
+find_library( LIBSOCKET_LIBRARY NAMES libsocket socket )
+mark_as_advanced( LIBSOCKET_LIBRARY )
+
+# handle the QUIETLY and REQUIRED arguments and set LIBSOCKET_FOUND to TRUE if
+# all listed variables are TRUE
+include( FindPackageHandleStandardArgs )
+FIND_PACKAGE_HANDLE_STANDARD_ARGS( LIBSOCKET DEFAULT_MSG LIBSOCKET_LIBRARY )
+
+if( LIBSOCKET_FOUND )
+ set( LIBSOCKET_LIBRARIES ${LIBSOCKET_LIBRARY} )
+endif( LIBSOCKET_FOUND )
diff --git a/cmake/FindLibUUID.cmake b/cmake/FindLibUUID.cmake
new file mode 100644
index 0000000000..10626c54b2
--- /dev/null
+++ b/cmake/FindLibUUID.cmake
@@ -0,0 +1,50 @@
+# - Try to find LIBUUID
+# Find LIBUUID headers, libraries and the answer to all questions.
+#
+# LIBUUID_FOUND True if libuuid got found
+# LIBUUID_INCLUDE_DIRS Location of libuuid headers
+# LIBUUID_LIBRARIES List of libraries to use libuuid
+#
+# Copyright (c) 2008 Bjoern Ricks <bjoern.ricks@googlemail.com>
+#
+# Redistribution and use is allowed according to the terms of the New
+# BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+#
+
+INCLUDE(FindPkgConfig)
+
+IF(LibUUID_FIND_REQUIRED)
+ SET(_pkgconfig_REQUIRED "REQUIRED")
+ELSE(LibUUID_FIND_REQUIRED)
+ SET(_pkgconfig_REQUIRED "")
+ENDIF (LibUUID_FIND_REQUIRED)
+
+IF(LIBUUID_MIN_VERSION)
+ PKG_SEARCH_MODULE(LIBUUID ${_pkgconfig_REQUIRED} uuid>=${LIBUUID_MIN_VERSION})
+ELSE(LIBUUID_MIN_VERSION)
+ PKG_SEARCH_MODULE(LIBUUID ${_pkgconfig_REQUIRED} uuid)
+ENDIF(LIBUUID_MIN_VERSION)
+
+IF(NOT LIBUUID_FOUND)
+ FIND_PATH(LIBUUID_INCLUDE_DIRS uuid/uuid.h)
+ FIND_LIBRARY(LIBUUID_LIBRARIES uuid)
+
+ # Report results
+ IF(LIBUUID_LIBRARIES AND LIBUUID_INCLUDE_DIRS)
+ SET(LIBUUID_FOUND 1)
+ IF(NOT LIBUUID_FIND_QUIETLY)
+ MESSAGE(STATUS "Found libuuid: ${LIBUUID_LIBRARIES}")
+ ENDIF(NOT LIBUUID_FIND_QUIETLY)
+ ELSE(LIBUUID_LIBRARIES AND LIBUUID_INCLUDE_DIRS)
+ IF(LIBUUID_FIND_REQUIRED)
+ MESSAGE(SEND_ERROR "Could NOT find libuuid")
+ ELSE(LIBUUID_FIND_REQUIRED)
+ IF(NOT LIBUUID_FIND_QUIETLY)
+ MESSAGE(STATUS "Could NOT find libuuid")
+ ENDIF(NOT LIBUUID_FIND_QUIETLY)
+ ENDIF (LIBUUID_FIND_REQUIRED)
+ ENDIF (LIBUUID_LIBRARIES AND LIBUUID_INCLUDE_DIRS)
+ENDIF(NOT LIBUUID_FOUND)
+
+MARK_AS_ADVANCED(LIBUUID_LIBRARIES LIBUUID_INCLUDE_DIRS)
diff --git a/cmake/FindReadline.cmake b/cmake/FindReadline.cmake
new file mode 100644
index 0000000000..6603dbeb97
--- /dev/null
+++ b/cmake/FindReadline.cmake
@@ -0,0 +1,22 @@
+# from http://websvn.kde.org/trunk/KDE/kdeedu/cmake/modules/FindReadline.cmake
+# http://websvn.kde.org/trunk/KDE/kdeedu/cmake/modules/COPYING-CMAKE-SCRIPTS
+# --> BSD licensed
+#
+# GNU Readline library finder
+
+
+if(READLINE_INCLUDE_DIR AND READLINE_LIBRARY)
+ set(READLINE_FOUND TRUE)
+else(READLINE_INCLUDE_DIR AND READLINE_LIBRARY)
+ FIND_PATH(READLINE_INCLUDE_DIR readline/readline.h
+ /usr/include/readline
+ )
+
+ FIND_LIBRARY(READLINE_LIBRARY NAMES readline PATHS
+ /opt/csw/lib/64/
+ )
+ include(FindPackageHandleStandardArgs)
+ FIND_PACKAGE_HANDLE_STANDARD_ARGS(Readline DEFAULT_MSG READLINE_INCLUDE_DIR READLINE_LIBRARY )
+
+ MARK_AS_ADVANCED(READLINE_INCLUDE_DIR READLINE_LIBRARY)
+endif(READLINE_INCLUDE_DIR AND READLINE_LIBRARY)
diff --git a/cmake/FindSELinux.cmake b/cmake/FindSELinux.cmake
new file mode 100644
index 0000000000..dd6e3ca425
--- /dev/null
+++ b/cmake/FindSELinux.cmake
@@ -0,0 +1,55 @@
+# - Try to find the SELinux library
+# Once done this will define
+#
+# SELINUX_FOUND - System has selinux
+# SELINUX_INCLUDE_DIR - The selinux include directory
+# SELINUX_LIBRARIES - The libraries needed to use selinux
+# SELINUX_DEFINITIONS - Compiler switches required for using selinux
+
+#=============================================================================
+# Copyright 2010 Michael Leupold <lemma@confuego.org>
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+
+IF (SELINUX_INCLUDE_DIR AND SELINUX_LIBRARIES)
+ # in cache already
+ SET (SELinux_FIND_QUIETLY TRUE)
+ENDIF (SELINUX_INCLUDE_DIR AND SELINUX_LIBRARIES)
+
+# TODO: This should be restricted to Linux only
+IF (NOT WIN32)
+ # use pkg-config to get the directories
+ FIND_PACKAGE (PkgConfig)
+ PKG_CHECK_MODULES (PC_SELINUX libselinux)
+ SET (SELINUX_DEFINITIONS ${PC_SELINUX_CFLAGS_OTHER})
+
+ FIND_PATH (SELINUX_INCLUDE_DIR selinux/selinux.h
+ HINTS
+ ${PC_SELINUX_INCLUDEDIR}
+ ${PC_SELINUX_INCLUDE_DIRS}
+ )
+
+ FIND_LIBRARY (SELINUX_LIBRARIES selinux libselinux
+ HINTS
+ ${PC_SELINUX_LIBDIR}
+ ${PC_SELINUX_LIBRARY_DIRS}
+ )
+
+ INCLUDE (FindPackageHandleStandardArgs)
+
+ # handle the QUIETLY and REQUIRED arguments and set SELINUX_FOUND
+ # to TRUE if all listed variables are TRUE
+ FIND_PACKAGE_HANDLE_STANDARD_ARGS (SELinux DEFAULT_MSG
+ SELINUX_INCLUDE_DIR
+ SELINUX_LIBRARIES
+ )
+
+ MARK_AS_ADVANCED (SELINUX_INCLUDE_DIR SELINUX_LIBRARIES)
+
+ENDIF (NOT WIN32)
diff --git a/cmake/FuncAcceptArgtypes.cmake b/cmake/FuncAcceptArgtypes.cmake
new file mode 100644
index 0000000000..e333d69aea
--- /dev/null
+++ b/cmake/FuncAcceptArgtypes.cmake
@@ -0,0 +1,52 @@
+if(HAVE_SYS_TYPES_H)
+ set(INCLUDE_SYS_TYPES_H "#include <sys/types.h>")
+endif(HAVE_SYS_TYPES_H)
+
+if(HAVE_SYS_SOCKET_H)
+ set(INCLUDE_SYS_SOCKET_H "#include <sys/socket.h>")
+endif(HAVE_SYS_SOCKET_H)
+
+
+message(STATUS "Looking for accept function args")
+set(CMAKE_REQUIRED_QUIET 1)
+foreach(ac_cv_func_accept_return "int" "unsigned int PASCAL" "SOCKET WSAAPI")
+ foreach(ac_cv_func_accept_arg1 "unsigned int" "int" "SOCKET")
+ foreach(ac_cv_func_accept_arg2 "struct sockaddr *" "const struct sockaddr *" "void *")
+ foreach(ac_cv_func_accept_arg3 "int" "size_t" "socklen_t" "unsigned int" "void")
+ unset(AC_FUNC_ACCEPT CACHE)
+ CHECK_C_SOURCE_COMPILES("
+ ${INCLUDE_SYS_TYPES_H}
+ ${INCLUDE_SYS_SOCKET_H}
+ extern ${ac_cv_func_accept_return} accept (${ac_cv_func_accept_arg1}, ${ac_cv_func_accept_arg2}, ${ac_cv_func_accept_arg3} *);
+ int main(void){return 0;}
+ " AC_FUNC_ACCEPT)
+ if(AC_FUNC_ACCEPT)
+ set(ACCEPT_TYPE_RETURN ${ac_cv_func_accept_return})
+ set(ACCEPT_TYPE_ARG1 ${ac_cv_func_accept_arg1})
+ set(ACCEPT_TYPE_ARG2 ${ac_cv_func_accept_arg2})
+ set(ACCEPT_TYPE_ARG3 ${ac_cv_func_accept_arg3})
+ break()
+ endif(AC_FUNC_ACCEPT)
+ endforeach(ac_cv_func_accept_arg3)
+ if(AC_FUNC_ACCEPT)
+ break()
+ endif(AC_FUNC_ACCEPT)
+ endforeach(ac_cv_func_accept_arg2)
+ if(AC_FUNC_ACCEPT)
+ break()
+ endif(AC_FUNC_ACCEPT)
+ endforeach(ac_cv_func_accept_arg1)
+ if(AC_FUNC_ACCEPT)
+ break()
+ endif(AC_FUNC_ACCEPT)
+endforeach(ac_cv_func_accept_return)
+unset(CMAKE_REQUIRED_QUIET)
+
+if(NOT AC_FUNC_ACCEPT)
+ message(ERROR "could not determine argument types")
+endif(NOT AC_FUNC_ACCEPT)
+if(ACCEPT_TYPE_ARG3 STREQUAL "void")
+ set(ACCEPT_TYPE_ARG3 "int")
+endif()
+
+message(STATUS "Looking for accept function args - found ${ACCEPT_TYPE_RETURN}, ${ACCEPT_TYPE_ARG1}, ${ACCEPT_TYPE_ARG2}, ${ACCEPT_TYPE_ARG3} *")
diff --git a/cmake/GenDef.cmake b/cmake/GenDef.cmake
new file mode 100644
index 0000000000..cacc4ceb21
--- /dev/null
+++ b/cmake/GenDef.cmake
@@ -0,0 +1,32 @@
+if(CMAKE_SYSTEM_NAME STREQUAL "AIX")
+ find_program(NM_EXECUTABLE nm)
+endif()
+
+macro(GEN_DEF NAME)
+ if(MSVC)
+ set_target_properties(${NAME} PROPERTIES ENABLE_EXPORTS 1)
+ set_target_properties(${NAME} PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
+ #SET_TARGET_PROPERTIES(${NAME} PROPERTIES LINK_FLAGS "/DEF:\"${CMAKE_CURRENT_BINARY_DIR}/${NAME}.def\" ")
+ #add_custom_command(
+ # TARGET ${NAME}
+ # PRE_LINK
+ # #COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.def
+ # #OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.def
+ # COMMAND ${PERL_EXECUTABLE} ${PROJECT_SOURCE_DIR}/src/tools/msvc/gendef.pl ${CMAKE_CURRENT_BINARY_DIR}/$<$<BOOL:${CMAKE_BUILD_TYPE}>:${CMAKE_FILES_DIRECTORY}>${NAME}.dir/${CMAKE_CFG_INTDIR} ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.def ${CMAKE_VS_PLATFORM_NAME}
+ # COMMENT " Gen defs "
+ #)
+ #set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.def)
+ elseif(CMAKE_SYSTEM_NAME STREQUAL "AIX" AND CMAKE_C_COMPILER_ID MATCHES "xlc")
+ # TODO for xls
+ SET_TARGET_PROPERTIES(${NAME} PROPERTIES LINK_FLAGS "-Wl,-bE:${CMAKE_CURRENT_BINARY_DIR}/${NAME}.exp")
+ if("${CMAKE_C_FLAGS}" MATCHES "aix64")
+ set(FLAG_64 "-X64")
+ endif()
+ add_custom_command(
+ TARGET ${NAME}
+ PRE_LINK
+ COMMAND ${NM_EXECUTABLE} ${FLAG_64} -BCg ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/${NAME}.dir/*.o | egrep ' [TDB] ' | sed -e 's/.* //' | egrep -v '\\$$' | sed -e 's/^[.]//' | sort | uniq > ${CMAKE_CURRENT_BINARY_DIR}/${NAME}.exp
+ COMMENT " Gen exports "
+ )
+ endif()
+endmacro(GEN_DEF NAME)
diff --git a/cmake/MakeNLS.cmake b/cmake/MakeNLS.cmake
new file mode 100644
index 0000000000..c6db90d85f
--- /dev/null
+++ b/cmake/MakeNLS.cmake
@@ -0,0 +1,21 @@
+macro(MAKE_MO BIN_NAME LANGUAGES)
+ set(gmo_files "")
+ foreach(lang ${LANGUAGES})
+ if (NOT ";${NLS_LANGUAGES};" MATCHES ";${lang};")
+ continue()
+ endif()
+ set(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/${lang}.gmo)
+ add_custom_command(OUTPUT ${_gmoFile}
+ COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${_gmoFile} po/${lang}.po
+ WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
+ DEPENDS po/${lang}.po
+ )
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${lang}.gmo DESTINATION share/locale/${lang}/LC_MESSAGES/ RENAME ${BIN_NAME}-${POSTGRES_MAJOR_VERSION}.${POSTGRES_MINOR_VERSION}.mo)
+ if(NOT TARGET pofiles)
+ add_custom_target(pofiles)
+ endif()
+ add_custom_target(${BIN_NAME}-mofile-${lang} ALL DEPENDS ${_gmoFile})
+ add_dependencies(pofiles ${BIN_NAME}-mofile-${lang})
+ set(gmo_files "${gmo_files};${_gmoFile}")
+ endforeach()
+endmacro()
diff --git a/cmake/RegressCheck.cmake b/cmake/RegressCheck.cmake
new file mode 100644
index 0000000000..0c16d2176d
--- /dev/null
+++ b/cmake/RegressCheck.cmake
@@ -0,0 +1,284 @@
+set(tmp_check_folder ${CMAKE_BINARY_DIR}/src/test/regress/tmp_install)
+
+if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
+ set(env_cmd
+ ${CMAKE_COMMAND} -E env
+ "DYLD_LIBRARY_PATH=$ENV{DESTDIR}${LIBDIR}:$$DYLD_LIBRARY_PATH"
+ "PATH=$ENV{DESTDIR}${PGBINDIR}:$$PATH"
+ )
+ set(tmp_env_cmd
+ ${CMAKE_COMMAND} -E env
+ "DYLD_LIBRARY_PATH=${tmp_check_folder}${LIBDIR}:$$DYLD_LIBRARY_PATH"
+ "PATH=${tmp_check_folder}${PGBINDIR}:$$PATH"
+ )
+elseif(CMAKE_SYSTEM_NAME STREQUAL "AIX")
+ set(env_cmd
+ ${CMAKE_COMMAND} -E env
+ "LIBPATH=$ENV{DESTDIR}${LIBDIR}:$LIBPATH"
+ "PATH=$ENV{DESTDIR}${PGBINDIR}:$$PATH"
+ )
+ set(tmp_env_cmd
+ ${CMAKE_COMMAND} -E env
+ "LIBPATH=${tmp_check_folder}${LIBDIR}:$LIBPATH"
+ "PATH=${tmp_check_folder}${PGBINDIR}:$$PATH"
+ )
+elseif(MSVC)
+ # We really need add PATH but only for ecpg
+ set(env_cmd "")
+else()
+ if (CMAKE_VERSION VERSION_GREATER "3.2.0")
+ set(env_cmd
+ ${CMAKE_COMMAND} -E env
+ "LD_LIBRARY_PATH=$ENV{DESTDIR}${LIBDIR}:$$LD_LIBRARY_PATH"
+ "PATH=$ENV{DESTDIR}${PGBINDIR}:$$PATH"
+ )
+ set(tmp_env_cmd
+ ${CMAKE_COMMAND} -E env
+ "LD_LIBRARY_PATH=${tmp_check_folder}${LIBDIR}:$$LD_LIBRARY_PATH"
+ "PATH=${tmp_check_folder}${PGBINDIR}:$$PATH"
+ )
+ else()
+ set(env_cmd
+ export "LD_LIBRARY_PATH=$ENV{DESTDIR}${LIBDIR}:$$LD_LIBRARY_PATH"
+ "PATH=$ENV{DESTDIR}${PGBINDIR}:$$PATH" &&
+ )
+ set(tmp_env_cmd
+ export "LD_LIBRARY_PATH=${tmp_check_folder}${LIBDIR}:$$LD_LIBRARY_PATH"
+ "PATH=${tmp_check_folder}${PGBINDIR}:$$PATH" &&
+ )
+ endif()
+endif()
+
+if(MSVC OR MSYS OR MINGW OR CMAKE_GENERATOR STREQUAL Xcode)
+ #Need rewrite
+ set(pre_pg_regress_check
+ ${PGBINDIR}/pg_regress${CMAKE_EXECUTABLE_SUFFIX}
+ --inputdir="${CMAKE_SOURCE_DIR}/src/test/regress"
+ --temp-instance="tmp_check"
+ --encoding=UTF8
+ --no-locale
+ )
+ set(pre_pg_isolation_regress_check
+ ${PGBINDIR}/pg_isolation_regress${CMAKE_EXECUTABLE_SUFFIX}
+ --inputdir="${CMAKE_SOURCE_DIR}/src/test/isolation"
+ --temp-instance="tmp_check"
+ --encoding=UTF8
+ --no-locale
+ )
+else()
+ set(pre_pg_regress_check
+ ${CMAKE_BINARY_DIR}/src/test/regress/${CMAKE_INSTALL_CONFIG_NAME}/pg_regress${CMAKE_EXECUTABLE_SUFFIX}
+ --inputdir="${CMAKE_SOURCE_DIR}/src/test/regress"
+ --temp-instance="tmp_check"
+ --encoding=UTF8
+ --no-locale
+ )
+ set(pre_pg_isolation_regress_check
+ ${CMAKE_BINARY_DIR}/src/test/isolation/${CMAKE_INSTALL_CONFIG_NAME}/pg_isolation_regress${CMAKE_EXECUTABLE_SUFFIX}
+ --inputdir="${CMAKE_SOURCE_DIR}/src/test/isolation"
+ --temp-instance="tmp_check"
+ --encoding=UTF8
+ --no-locale
+ )
+ set(pre_pg_ecpg_regress_check
+ ${CMAKE_BINARY_DIR}/src/interfaces/ecpg/test/${CMAKE_INSTALL_CONFIG_NAME}/pg_ecpg_regress${CMAKE_EXECUTABLE_SUFFIX}
+ --inputdir="${CMAKE_BINARY_DIR}/src/interfaces/ecpg/test"
+ --temp-instance="tmp_check"
+ --encoding=UTF8
+ --no-locale
+ )
+endif()
+
+set(pg_regress_check
+ ${env_cmd}
+ ${pre_pg_regress_check}
+ --bindir=$ENV{DESTDIR}${PGBINDIR}
+)
+
+set(pg_regress_check_tmp
+ ${tmp_env_cmd}
+ ${pre_pg_regress_check}
+ --bindir=${tmp_check_folder}${PGBINDIR}
+)
+
+set(pg_isolation_regress_check
+ ${env_cmd}
+ ${pre_pg_isolation_regress_check}
+ --bindir=$ENV{DESTDIR}${PGBINDIR}
+)
+
+set(pg_isolation_regress_check_tmp
+ ${tmp_env_cmd}
+ ${pre_pg_isolation_regress_check}
+ --bindir=${tmp_check_folder}${PGBINDIR}
+)
+
+set(pg_ecpg_regress_check
+ ${env_cmd}
+ ${pre_pg_ecpg_regress_check}
+ --bindir=$ENV{DESTDIR}${PGBINDIR}
+)
+
+set(pg_ecpg_regress_check_tmp
+ ${tmp_env_cmd}
+ ${pre_pg_ecpg_regress_check}
+ --bindir=${tmp_check_folder}${PGBINDIR}
+)
+
+if(MAX_CONNECTIONS)
+ set(MAXCONNOPT "${MAXCONNOPT} --max-connections=${MAX_CONNECTIONS}")
+endif()
+
+if(TEMP_CONFIG)
+ set(TEMP_CONF "${TEMP_CONF} --temp-config=${TEMP_CONFIG}")
+endif()
+
+
+set(TAP_FLAGS "-I;${CMAKE_SOURCE_DIR}/src/test/perl/;--verbose")
+
+if(CMAKE_GENERATOR STREQUAL "Ninja")
+ set(check_make_command "ninja")
+else()
+ set(check_make_command ${CMAKE_MAKE_PROGRAM})
+endif()
+
+macro(REGRESS_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
+ add_custom_target(${TARGET_NAME}_installcheck_tmp
+ COMMAND ${pg_regress_check_tmp} --inputdir="${CMAKE_CURRENT_SOURCE_DIR}" --dbname=${TARGET_NAME}_regress ${REGRESS_OPTS} --dlpath=${tmp_check_folder}${LIBDIR} ${MAXCONNOPT} ${TEMP_CONF} ${REGRESS_FILES}
+ DEPENDS tablespace-setup
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ )
+
+ add_custom_target(${TARGET_NAME}_installcheck
+ COMMAND ${pg_regress_check} --inputdir="${CMAKE_CURRENT_SOURCE_DIR}" --dbname=${TARGET_NAME}_regress ${REGRESS_OPTS} --dlpath=$ENV{DESTDIR}${LIBDIR} ${MAXCONNOPT} ${TEMP_CONF} ${REGRESS_FILES}
+ DEPENDS tablespace-setup
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ )
+
+ if(CMAKE_GENERATOR STREQUAL "Ninja")
+ add_custom_target(${TARGET_NAME}_check
+ COMMAND ${CMAKE_COMMAND} -E remove_directory ${tmp_check_folder}
+ COMMAND DESTDIR=${tmp_check_folder} ${check_make_command} install
+ COMMAND DESTDIR=${tmp_check_folder} ${check_make_command} ${TARGET_NAME}_installcheck_tmp
+ DEPENDS tablespace-setup
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+ )
+ else()
+ add_custom_target(${TARGET_NAME}_check
+ COMMAND ${CMAKE_COMMAND} -E remove_directory ${tmp_check_folder}
+ COMMAND ${check_make_command} install DESTDIR=${tmp_check_folder}
+ COMMAND ${check_make_command} ${TARGET_NAME}_installcheck_tmp DESTDIR=${tmp_check_folder}
+ DEPENDS tablespace-setup
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+ )
+ endif()
+
+ CMAKE_SET_TARGET_FOLDER(${TARGET_NAME}_installcheck_tmp tests/tmp)
+ CMAKE_SET_TARGET_FOLDER(${TARGET_NAME}_installcheck "tests/install")
+ CMAKE_SET_TARGET_FOLDER(${TARGET_NAME}_check tests)
+endmacro(REGRESS_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
+
+macro(ISOLATION_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
+ add_custom_target(${TARGET_NAME}_isolation_installcheck_tmp
+ COMMAND ${pg_isolation_regress_check_tmp} --inputdir="${CMAKE_CURRENT_SOURCE_DIR}" --dbname=${TARGET_NAME}_regress ${REGRESS_OPTS} --dlpath=${tmp_check_folder}${LIBDIR} ${MAXCONNOPT} ${TEMP_CONF} ${REGRESS_FILES}
+ DEPENDS pg_isolation_regress
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ )
+
+ add_custom_target(${TARGET_NAME}_isolation_installcheck
+ COMMAND ${pg_isolation_regress_check} --inputdir="${CMAKE_CURRENT_SOURCE_DIR}" --dbname=${TARGET_NAME}_regress ${REGRESS_OPTS} --dlpath==$ENV{DESTDIR}${LIBDIR} ${MAXCONNOPT} ${TEMP_CONF} ${REGRESS_FILES}
+ DEPENDS pg_isolation_regress
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ )
+
+ add_custom_target(${TARGET_NAME}_isolation_check
+ COMMAND ${CMAKE_COMMAND} -E remove_directory ${tmp_check_folder}
+ COMMAND ${check_make_command} install DESTDIR=${tmp_check_folder}
+ COMMAND ${check_make_command} ${TARGET_NAME}_isolation_installcheck_tmp DESTDIR=${tmp_check_folder}
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+ )
+ CMAKE_SET_TARGET_FOLDER(${TARGET_NAME}_isolation_installcheck_tmp tests/tmp)
+ CMAKE_SET_TARGET_FOLDER(${TARGET_NAME}_check tests)
+endmacro(ISOLATION_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
+
+macro(TAP_CHECK TARGET_NAME OPTS REGRESS_FILES)
+ set(TAP_TMP_CMD
+ ${CMAKE_COMMAND} -E env
+ TESTDIR="${CMAKE_CURRENT_SOURCE_DIR}" PGPORT="65432" PG_REGRESS="${CMAKE_BINARY_DIR}/src/test/regress/${CMAKE_INSTALL_CONFIG_NAME}/pg_regress${CMAKE_EXECUTABLE_SUFFIX}"
+ ${PROVE}
+ )
+ set(TAP_CMD
+ ${CMAKE_COMMAND} -E env
+ PATH="$ENV{DESTDIR}${BINDIR}:$$PATH" TESTDIR="${CMAKE_CURRENT_SOURCE_DIR}" PGPORT="65432" PG_REGRESS="${CMAKE_BINARY_DIR}/src/test/regress/${CMAKE_INSTALL_CONFIG_NAME}/pg_regress${CMAKE_EXECUTABLE_SUFFIX}"
+ ${PROVE}
+ )
+ add_custom_target(${TARGET_NAME}_installcheck_tmp
+ COMMAND ${tmp_env_cmd} ${TAP_TMP_CMD} ${OPTS} ${REGRESS_FILES}
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ )
+
+ add_custom_target(${TARGET_NAME}_installcheck
+ COMMAND ${env_cmd} ${TAP_CMD} ${OPTS} ${REGRESS_FILES}
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ )
+
+ if(CMAKE_GENERATOR STREQUAL "Ninja")
+ add_custom_target(${TARGET_NAME}_check
+ COMMAND ${CMAKE_COMMAND} -E remove_directory ${tmp_check_folder}
+ COMMAND DESTDIR=${tmp_check_folder} ${check_make_command} install
+ COMMAND DESTDIR=${tmp_check_folder} ${check_make_command} ${TARGET_NAME}_installcheck_tmp
+ DEPENDS tablespace-setup
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+ )
+ else()
+ add_custom_target(${TARGET_NAME}_check
+ COMMAND ${CMAKE_COMMAND} -E remove_directory ${tmp_check_folder}
+ COMMAND ${check_make_command} install DESTDIR=${tmp_check_folder}
+ COMMAND ${check_make_command} ${TARGET_NAME}_installcheck_tmp DESTDIR=${tmp_check_folder}
+ DEPENDS tablespace-setup
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+ )
+ endif()
+
+ CMAKE_SET_TARGET_FOLDER(${TARGET_NAME}_installcheck_tmp tests/tmp)
+ CMAKE_SET_TARGET_FOLDER(${TARGET_NAME}_check tests)
+endmacro(TAP_CHECK TARGET_NAME OPTS REGRESS_FILES)
+
+# Contrib macros
+macro(CONTRIB_REGRESS_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
+ set(contrib_check_targets ${contrib_check_targets} ${TARGET_NAME}_installcheck_tmp PARENT_SCOPE)
+ set(contrib_installcheck_targets ${contrib_installcheck_targets} ${TARGET_NAME}_installcheck PARENT_SCOPE)
+ REGRESS_CHECK("${TARGET_NAME}" "${REGRESS_OPTS}" "${REGRESS_FILES}")
+endmacro(CONTRIB_REGRESS_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
+
+macro(CONTRIB_ISOLATION_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
+ set(contrib_check_targets ${contrib_check_targets} ${TARGET_NAME}_isolation_installcheck_tmp PARENT_SCOPE)
+ set(contrib_installcheck_targets ${contrib_installcheck_targets} ${TARGET_NAME}_isolation_installcheck PARENT_SCOPE)
+ ISOLATION_CHECK("${TARGET_NAME}" "${REGRESS_OPTS}" "${REGRESS_FILES}")
+endmacro(CONTRIB_ISOLATION_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
+
+macro(CONTRIB_TAP_CHECK TARGET_NAME OPTS REGRESS_FILES)
+ set(contrib_check_targets ${contrib_check_targets} ${TARGET_NAME}_tap_installcheck_tmp PARENT_SCOPE)
+ set(contrib_installcheck_targets ${contrib_installcheck_targets} ${TARGET_NAME}_tap_installcheck PARENT_SCOPE)
+ TAP_CHECK("${TARGET_NAME}_tap" "${OPTS}" "${REGRESS_FILES}")
+endmacro(CONTRIB_TAP_CHECK TARGET_NAME OPTS REGRESS_FILES)
+
+
+# Modules macros
+macro(MODULES_REGRESS_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
+ set(modules_check_targets ${modules_check_targets} ${TARGET_NAME}_installcheck_tmp PARENT_SCOPE)
+ set(modules_installcheck_targets ${modules_installcheck_targets} ${TARGET_NAME}_installcheck PARENT_SCOPE)
+ REGRESS_CHECK("${TARGET_NAME}" "${REGRESS_OPTS}" "${REGRESS_FILES}")
+endmacro(MODULES_REGRESS_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
+
+macro(MODULES_ISOLATION_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
+ set(modules_check_targets ${modules_check_targets} ${TARGET_NAME}_isolation_installcheck_tmp PARENT_SCOPE)
+ set(modules_installcheck_targets ${modules_installcheck_targets} ${TARGET_NAME}_isolation_installcheck PARENT_SCOPE)
+ ISOLATION_CHECK("${TARGET_NAME}" "${REGRESS_OPTS}" "${REGRESS_FILES}")
+endmacro(MODULES_ISOLATION_CHECK TARGET_NAME REGRESS_OPTS REGRESS_FILES)
+
+macro(MODULES_TAP_CHECK TARGET_NAME OPTS REGRESS_FILES)
+ set(modules_check_targets ${modules_check_targets} ${TARGET_NAME}_tap_installcheck_tmp PARENT_SCOPE)
+ set(modules_installcheck_targets ${modules_installcheck_targets} ${TARGET_NAME}_tap_installcheck PARENT_SCOPE)
+ TAP_CHECK("${TARGET_NAME}_tap" "${OPTS}" "${REGRESS_FILES}")
+endmacro(MODULES_TAP_CHECK TARGET_NAME OPTS REGRESS_FILES)
diff --git a/cmake/ReplacePython.cmake b/cmake/ReplacePython.cmake
new file mode 100644
index 0000000000..f7683072f1
--- /dev/null
+++ b/cmake/ReplacePython.cmake
@@ -0,0 +1,79 @@
+macro(replace_python2 input_file output_file)
+ file(READ ${input_file} tmp_string)
+ string(REGEX REPLACE
+ "except \([a-zA-Z\\.]*\), *\([a-zA-Z]*\):"
+ "except \\1 as \\2:"
+ tmp_string
+ "${tmp_string}")
+ string(REGEX REPLACE
+ "<type 'exceptions\\.\([a-zA-Z]*\)'>" "<class '\\1'>"
+ tmp_string
+ "${tmp_string}")
+ string(REGEX REPLACE
+ "<type 'long'>" "<class 'int'>"
+ tmp_string
+ "${tmp_string}")
+ string(REGEX REPLACE
+ "\([0-9][0-9]*\)L" "\\1"
+ tmp_string
+ "${tmp_string}")
+ string(REGEX REPLACE
+ "\([ [{]\)u\"" "\\1\""
+ tmp_string
+ "${tmp_string}")
+ string(REGEX REPLACE
+ "\([ [{]\)u'" "\\1'"
+ tmp_string
+ "${tmp_string}")
+ string(REGEX REPLACE
+ "def next" "def __next__"
+ tmp_string
+ "${tmp_string}")
+ string(REGEX REPLACE
+ "LANGUAGE plpythonu" "LANGUAGE plpython3u"
+ tmp_string
+ "${tmp_string}")
+ string(REGEX REPLACE
+ "LANGUAGE plpython2u" "LANGUAGE plpython3u"
+ tmp_string
+ "${tmp_string}")
+ string(REGEX REPLACE
+ "EXTENSION \([^ ]*_\)+plpythonu" "EXTENSION \\1plpython3u"
+ tmp_string
+ "${tmp_string}")
+ string(REGEX REPLACE
+ "EXTENSION plpythonu" "EXTENSION plpython3u"
+ tmp_string
+ "${tmp_string}")
+ string(REGEX REPLACE
+ "EXTENSION \([^ ]*_\)+plpython2u" "EXTENSION \\1plpython3u"
+ tmp_string
+ "${tmp_string}")
+ string(REGEX REPLACE
+ "EXTENSION plpython2u" "EXTENSION plpython3u"
+ tmp_string
+ "${tmp_string}")
+ string(REGEX REPLACE
+ "installing required extension \"plpython2u\""
+ "installing required extension \"plpython3u\""
+ tmp_string
+ "${tmp_string}")
+ file(WRITE ${output_file} "${tmp_string}")
+endmacro()
+
+macro(replace_python_files r_regress_files)
+ file(MAKE_DIRECTORY sql/python3 expected/python3 results/python3)
+ set(adition_clean "")
+ set(regress_files3 "")
+ foreach(rfile ${r_regress_files})
+ replace_python2("sql/${rfile}.sql" "sql/python3/${rfile}.sql")
+ if(rfile STREQUAL "plpython_types")
+ replace_python2("expected/plpython_types_3.out" "expected/python3/${rfile}.out")