replace: Added cmake build system.
authorAndreas Schneider <asn@redhat.com>
Mon, 21 Dec 2009 19:48:51 +0000 (20:48 +0100)
committerAndreas Schneider <asn@redhat.com>
Fri, 15 Jan 2010 11:04:58 +0000 (12:04 +0100)
21 files changed:
lib/replace/CMakeLists.txt [new file with mode: 0644]
lib/replace/CPackConfig.cmake [new file with mode: 0644]
lib/replace/ConfigureChecks.cmake [new file with mode: 0644]
lib/replace/cmake/Modules/COPYING-CMAKE-SCRIPTS [new file with mode: 0644]
lib/replace/cmake/Modules/CheckPrototypeDefinition.c.in [new file with mode: 0644]
lib/replace/cmake/Modules/CheckPrototypeDefinition.cmake [new file with mode: 0644]
lib/replace/cmake/Modules/CheckSignalType.c.in [new file with mode: 0644]
lib/replace/cmake/Modules/CheckSignalType.cmake [new file with mode: 0644]
lib/replace/cmake/Modules/DefineCMakeDefaults.cmake [new file with mode: 0644]
lib/replace/cmake/Modules/DefineCompilerFlags.cmake [new file with mode: 0644]
lib/replace/cmake/Modules/DefineInstallationPaths.cmake [new file with mode: 0644]
lib/replace/cmake/Modules/MacroAddCompileFlags.cmake [new file with mode: 0644]
lib/replace/cmake/Modules/MacroAddLinkFlags.cmake [new file with mode: 0644]
lib/replace/cmake/Modules/MacroAddPlugin.cmake [new file with mode: 0644]
lib/replace/cmake/Modules/MacroCopyFile.cmake [new file with mode: 0644]
lib/replace/cmake/Modules/MacroEnsureOutOfSourceBuild.cmake [new file with mode: 0644]
lib/replace/cmake/Modules/UseDoxygen.cmake [new file with mode: 0644]
lib/replace/config.h.cmake [new file with mode: 0644]
lib/replace/test/CMakeLists.txt [new file with mode: 0644]
lib/replace/test/mkstemp.c [new file with mode: 0644]
lib/replace/test/vsnprintf.c [new file with mode: 0644]

diff --git a/lib/replace/CMakeLists.txt b/lib/replace/CMakeLists.txt
new file mode 100644 (file)
index 0000000..3ee7712
--- /dev/null
@@ -0,0 +1,102 @@
+project(LIBREPLACE C)
+# provides dirs and definec C only project
+#   LIBREPLACE_SOURCE_DIR
+#   LIBREPLACE_BINARY_DIR
+
+# BUILD_LIBREPLACE should be set if it is not built as a standalone project.
+if (NOT WITH_LIBREPLACE)
+    # Required cmake version
+    cmake_minimum_required(VERSION 2.6.0)
+
+    # global needed variables
+    set(APPLICATION_NAME libreplace)
+
+    # where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked
+    set(CMAKE_MODULE_PATH
+      ${LIBREPLACE_SOURCE_DIR}/cmake/Modules
+    )
+
+    # add definitions
+    include(DefineCMakeDefaults)
+    include(DefineCompilerFlags)
+    include(DefineInstallationPaths)
+    include(CPackConfig.cmake)
+
+    # disallow in-source build
+    include(MacroEnsureOutOfSourceBuild)
+    macro_ensure_out_of_source_build("${PROJECT_NAME} requires an out of source build. Please create a separate build directory and run 'cmake /path/to/${APPLICATION_NAME} [options]' there.")
+endif (NOT WITH_LIBREPLACE)
+
+# config.h checks
+include(ConfigureChecks.cmake)
+# shouldn't the file be renamed to replace_config.h?
+configure_file(${LIBREPLACE_SOURCE_DIR}/config.h.cmake ${LIBREPLACE_BINARY_DIR}/config.h)
+
+# build libreplace
+
+# define include dirs and the library for later use and cache it.
+set(LIBREPLACE_PUBLIC_INCLUDE_DIRS
+    ${LIBREPLACE_BINARY_DIR}
+    ${LIBREPLACE_SOURCE_DIR}
+    CACHE INTERNAL "libreplace public include directories"
+)
+
+set(LIBREPLACE_PRIVATE_INCLUDE_DIRS
+    ${LIBREPLACE_PUBLIC_INCLUDE_DIRS}
+)
+
+set(LIBREPLACE_LIBRARY
+    replace
+    CACHE INTERNAL "libreplace static library"
+)
+
+add_definitions(${CMAKE_PLATFORM_DEFINITIONS})
+include_directories(${LIBREPLACE_PRIVATE_INCLUDE_DIRS})
+
+set(replace_SRCS
+    replace.c
+    snprintf.c
+    socketpair.c
+    inet_ntop.c
+)
+
+if (WITH_GETPASS)
+    set(replace_SRCS
+        ${replace_SRCS}
+        getpass.c
+    )
+endif (WITH_GETPASS)
+
+if (WITH_STRPTIME)
+    set(replace_SRCS
+        ${replace_SRCS}
+        strptime.c
+    )
+endif (WITH_STRPTIME)
+
+if (NOT HAVE_INET_ATON)
+    set(replace_SRCS
+        ${replace_SRCS}
+        inet_aton.h
+    )
+endif (NOT HAVE_INET_ATON)
+
+if (NOT HAVE_INET_NTOP)
+    set(replace_SRCS
+        ${replace_SRCS}
+        inet_ntop.h
+    )
+endif (NOT HAVE_INET_NTOP)
+
+if (NOT HAVE_INET_PTON)
+    set(replace_SRCS
+        ${replace_SRCS}
+        inet_pton.h
+    )
+endif (NOT HAVE_INET_PTON)
+
+add_library(${LIBREPLACE_LIBRARY} STATIC ${replace_SRCS})
+target_link_libraries(${LIBREPLACE_LIBRARY} ${REPLACE_REQUIRED_SYSTEM_LIBRARIES})
+
+# build tests
+add_subdirectory(test)
diff --git a/lib/replace/CPackConfig.cmake b/lib/replace/CPackConfig.cmake
new file mode 100644 (file)
index 0000000..482a977
--- /dev/null
@@ -0,0 +1,25 @@
+# For help take a look at:
+# http://www.cmake.org/Wiki/CMake:CPackConfiguration
+
+### general settings
+set(CPACK_PACKAGE_NAME ${APPLICATION_NAME})
+set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "The relpace library")
+#set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/README")
+set(CPACK_PACKAGE_VENDOR "The Samba Team")
+set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME})
+#set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING")
+
+
+### versions
+set(CPACK_PACKAGE_VERSION_MAJOR "0")
+set(CPACK_PACKAGE_VERSION_MINOR "1")
+set(CPACK_PACKAGE_VERSION_PATCH "0")
+set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
+
+
+### source generator
+set(CPACK_SOURCE_GENERATOR "TGZ")
+set(CPACK_SOURCE_IGNORE_FILES "~$;[.]swp$;/[.]svn/;/[.]git/;.gitignore;/build/;tags;cscope.*")
+set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
+
+include(CPack)
diff --git a/lib/replace/ConfigureChecks.cmake b/lib/replace/ConfigureChecks.cmake
new file mode 100644 (file)
index 0000000..c4c0de0
--- /dev/null
@@ -0,0 +1,465 @@
+# http://www.cmake.org/Wiki/CMake_HowToDoPlatformChecks
+include(CheckIncludeFile)
+include(CheckIncludeFiles)
+include(CheckSymbolExists)
+include(CheckFunctionExists)
+include(CheckLibraryExists)
+include(CheckTypeSize)
+include(CheckCSourceRuns)
+include(CheckPrototypeDefinition)
+include(CheckSignalType)
+include(TestBigEndian)
+
+##### HEADER FILES
+check_include_file(acl/libacl.h HAVE_ACL_LIBACL_H)
+check_include_file(arpa/inet.h HAVE_ARPA_INET_H)
+check_include_file(compat.h HAVE_COMPAT_H)
+check_include_file(crypt.h HAVE_CRYPT_H)
+check_include_file(ctype.h HAVE_CTYPE_H)
+check_include_file(dirent.h HAVE_DIRENT_H)
+check_include_file(fcntl.h HAVE_FCNTL_H)
+check_include_file(fnmatch.h HAVE_FNMATCH_H)
+check_include_file(grp.h HAVE_GRP_H)
+check_include_file(inttypes.h HAVE_INTTYPES_H)
+check_include_file(langinfo.h HAVE_LANGINFO_H)
+check_include_file(limits.h HAVE_LIMITS_H)
+check_include_file(locale.h HAVE_LOCALE_H)
+check_include_file(mntent.h HAVE_MNTENT_H)
+check_include_file(mount.h HAVE_MOUNT_H)
+check_include_file(netdb.h HAVE_NETDB_H)
+check_include_file(netinet/in.h HAVE_NETINET_IN_H)
+check_include_file(netinet/in_ip.h HAVE_NETINET_IN_IP_H)
+check_include_file(netinet/in_systm.h HAVE_NETINET_IN_SYSTM_H)
+check_include_file(netinet/ip.h HAVE_NETINET_IP_H)
+check_include_file(netinet/tcp.h HAVE_NETINET_TCP_H)
+check_include_file(pwd.h HAVE_PWD_H)
+check_include_file(setjmp.h HAVE_SETJMP_H)
+check_include_file(shadow.h HAVE_SHADOW_H)
+check_include_file(stdbool.h HAVE_STDBOOL_H)
+check_include_file(stdint.h HAVE_STDINT_H)
+check_include_file(stdio.h HAVE_STDIO_H)
+check_include_file(string.h HAVE_STRING_H)
+check_include_file(strings.h HAVE_STRINGS_H)
+check_include_file(stropts.h HAVE_STROPTS_H)
+check_include_file(sys/acl.h HAVE_SYS_ACL_H)
+check_include_file(sys/capability.h HAVE_SYS_CAPABILITY_H)
+check_include_file(sys/fcntl.h HAVE_SYS_FCNTL_H)
+check_include_file(sys/filio.h HAVE_SYS_FILIO_H)
+check_include_file(sys/filsys.h HAVE_SYS_FILSYS_H)
+check_include_file(sys/fs/s5param.h HAVE_SYS_S5PARAM_H)
+check_include_file(sys/id.h HAVE_SYS_ID_H)
+check_include_file(sys/ioctl.h HAVE_SYS_IOCTL_H)
+check_include_file(sys/ipc.h HAVE_SYS_IPC_H)
+check_include_file(sys/mman.h HAVE_SYS_MMAN_H)
+check_include_file(sys/mode.h HAVE_SYS_MODE_H)
+check_include_file(sys/param.h HAVE_SYS_PARAM_H)
+check_include_file(sys/priv.h HAVE_SYS_PRIV_H)
+check_include_file(sys/resource.h HAVE_SYS_RESOURCE_H)
+check_include_file(sys/security.h HAVE_SYS_SECURITY_H)
+check_include_file(sys/select.h HAVE_SYS_SELECT_H)
+check_include_file(sys/shm.h HAVE_SYS_SHM_H)
+check_include_file(sys/socket.h HAVE_SYS_SOCKET_H)
+check_include_file(sys/sockio.h HAVE_SYS_SOCKIO_H)
+check_include_file(sys/syslog.h HAVE_SYS_SYSLOG_H)
+check_include_file(sys/termio.h HAVE_SYS_TERMIO_H)
+check_include_file(sys/time.h HAVE_SYS_TIME_H)
+check_include_file(sys/uio.h HAVE_SYS_UIO_H)
+check_include_file(sys/un.h HAVE_SYS_UN_H)
+check_include_file(sys/wait.h HAVE_SYS_WAIT_H)
+check_include_file(syslog.h HAVE_SYSLOG_H)
+check_include_file(termio.h HAVE_TERMIO_H)
+check_include_file(termios.h HAVE_TERMINOS_H)
+check_include_file(time.h HAVE_TIME_H)
+check_include_file(unistd.h HAVE_UNISTD_H)
+check_include_file(unix.h HAVE_UNIX_H)
+check_include_file(utime.h HAVE_UTIME_H)
+check_include_file(utimes.h HAVE_UTIMES_H)
+
+if (HAVE_NETINET_IP_H)
+    set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h)
+    if (HAVE_NETINET_IN_H)
+       set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};netinet/in.h")
+    endif (HAVE_NETINET_IN_H)
+
+    if (HAVE_NETINET_IN_SYSTM_H)
+        set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};netinet/in_systm.h")
+    endif (HAVE_NETINET_IN_SYSTM_H)
+
+    set(CMAKE_EXTRA_INCLUDE_FILES "${CMAKE_EXTRA_INCLUDE_FILES};netinet/ip.h")
+    check_type_size("struct iphdr" HAVE_IPHDR)
+
+    if (NOT HAVE_IPHDR)
+        set(HAVE_NETINET_IP_H FALSE INTERNAL)
+    endif (NOT HAVE_IPHDR)
+
+    set(CMAKE_EXTRA_INCLUDE_FILES) # reset
+endif (HAVE_NETINET_IP_H)
+
+##### FUNCTIONS
+check_function_exists(printf HAVE_PRINTF)
+if (NOT HAVE_PRINTF)
+    message(STATUS FATAL_ERROR "Required function printf not found")
+endif (NOT HAVE_PRINTF)
+
+check_function_exists(memset HAVE_MEMSET)
+if (NOT HAVE_MEMSET)
+    message(STATUS FATAL_ERROR "Required function memset not found")
+endif (NOT HAVE_MEMSET)
+
+check_function_exists(memcpy HAVE_MEMCPY)
+if (NOT HAVE_MEMCPY)
+    message(STATUS FATAL_ERROR "Required function memcpy not found")
+endif (NOT HAVE_MEMCPY)
+
+check_function_exists(__strtoll HAVE___STRTOLL)
+check_function_exists(__strtoull HAVE___STRTOULL)
+check_function_exists(asprintf HAVE_ASPRINTF)
+check_function_exists(bzero HAVE_BZERO)
+check_function_exists(chown HAVE_CHOWN)
+check_function_exists(chroot HAVE_CHROOT)
+check_function_exists(chsize HAVE_CHSIZE)
+check_function_exists(dup2 HAVE_DUP2)
+check_function_exists(ftruncate HAVE_FTRUNCATE)
+check_function_exists(getifaddrs HAVE_GETIFADDRS)
+check_function_exists(freeifaddrs HAVE_FREEIFADDRS)
+check_function_exists(inet_aton HAVE_INET_ATON)
+check_function_exists(inet_ntop HAVE_INET_NTOP)
+check_function_exists(inet_pton HAVE_INET_PTON)
+check_function_exists(initgroups HAVE_INITGROUPS)
+check_function_exists(isatty HAVE_ISATTY)
+check_function_exists(lchown HAVE_LCHOWN)
+check_function_exists(link HAVE_LINK)
+check_function_exists(localtime_r HAVE_LOCALTIME_R)
+check_function_exists(memmove HAVE_MEMMOVE)
+check_function_exists(mkdtemp HAVE_MKDTEMP)
+check_function_exists(mktime HAVE_MKTIME)
+check_function_exists(pread HAVE_PREAD)
+check_function_exists(pwrite HAVE_PWRITE)
+check_function_exists(readlink HAVE_READLINK)
+check_function_exists(realpath HAVE_REALPATH)
+check_function_exists(rename HAVE_RENAME)
+check_function_exists(setegid HAVE_SETEGID)
+check_function_exists(setenv HAVE_SETENV)
+check_function_exists(seteuid HAVE_SETEUID)
+check_function_exists(setgid HAVE_SETGID)
+check_function_exists(setlinebuf HAVE_SETLINEBUF)
+check_function_exists(setresgid HAVE_SETRESGID)
+check_function_exists(setresuid HAVE_SETRESUID)
+check_function_exists(setuid HAVE_SETUID)
+check_function_exists(snprintf HAVE_SNPRINTF)
+check_function_exists(strcasestr HAVE_STRCASESTR)
+check_function_exists(strdup HAVE_STRDUP)
+check_function_exists(strerror HAVE_STRERROR)
+check_function_exists(strlcat HAVE_STRLCAT)
+check_function_exists(strlcpy HAVE_STRLCPY)
+check_function_exists(strndup HAVE_STRNDUP)
+check_function_exists(strndup HAVE_STRNDUP)
+check_function_exists(strnlen HAVE_STRNLEN)
+check_function_exists(strtok_r HAVE_STRTOK_R)
+check_function_exists(strtoll HAVE_STRTOLL)
+check_function_exists(strtoq HAVE_STROQ)
+check_function_exists(strtoull HAVE_STRTOULL)
+check_function_exists(strtouq HAVE_STRTOUQ)
+check_function_exists(symlink HAVE_SYMLINK)
+check_function_exists(timegm HAVE_TIMEGM)
+check_function_exists(unsetenv HAVE_UNSETENV)
+check_function_exists(utime HAVE_UTIME)
+check_function_exists(utimes HAVE_UTIMES)
+check_function_exists(vasprintf HAVE_VASPRINTF)
+check_function_exists(vsnprintf HAVE_VSNPRINTF)
+check_function_exists(vsyslog HAVE_VSYSLOG)
+check_function_exists(wait4 HAVE_WAIT4)
+check_function_exists(waitpid HAVE_WAITPID)
+check_function_exists(getpwnam_r HAVE_GETPWNAM_R)
+check_function_exists(getpwuid_r HAVE_GETPWUID_R)
+check_function_exists(getpwent_r HAVE_GETPWENT_R)
+check_function_exists(getgrouplist HAVE_GETROUPLIST)
+check_function_exists(getpass HAVE_GETPASS)
+check_function_exists(getpassphrase HAVE_GETPASSPHRASE)
+
+# crypt
+find_library(CRYPT_LIBRARY NAMES crypt)
+if (CRYPT_LIBRARY)
+    set(CMAKE_REQUIRED_LIBRARIES ${CRYPT_LIBRARY})
+    check_function_exists(crypt HAVE_CRYPT)
+    set(LIBREPLACE_REQUIRED_SYSTEM_LIBRARIES
+        ${LIBREPLACE_REQUIRED_SYSTEM_LIBRARIES}
+        ${CRYPT_LIBRARY}
+    )
+endif (CRYPT_LIBRARY)
+
+# dlfn
+find_library(DLFN_LIBRARY NAMES dl dlopen)
+if (DLFN_LIBRARY)
+    set(CMAKE_REQUIRED_LIBRARIES ${DLFN_LIBRARY})
+    check_function_exists(dlopen HAVE_DLOPEN)
+    check_function_exists(dlsym HAVE_DLSYM)
+    check_function_exists(dlerror HAVE_DLERROR)
+    check_function_exists(dlclose HAVE_DLCLOSE)
+    set(LIBREPLACE_REQUIRED_SYSTEM_LIBRARIES
+        ${LIBREPLACE_REQUIRED_SYSTEM_LIBRARIES}
+        ${DLFN_LIBRARY}
+    )
+endif (DLFN_LIBRARY)
+
+# sl shl_load
+find_library(SL_LIBRARY NAMES sl shl_load)
+if (SL_LIBRARY)
+    set(CMAKE_REQUIRED_LIBRARIES ${SL_LIBRARY})
+    check_function_exists(shl_load HAVE_SHL_LOAD)
+    check_function_exists(shl_unload HAVE_SHL_UNLOAD)
+    check_function_exists(shl_findsym HAVE_SHL_FINDSYM)
+    set(LIBREPLACE_REQUIRED_SYSTEM_LIBRARIES
+        ${LIBREPLACE_REQUIRED_SYSTEM_LIBRARIES}
+        ${SL_LIBRARY}
+    )
+endif (SL_LIBRARY)
+
+set(CMAKE_REQUIRED_LIBRARIES)
+
+##### SYMBOLS
+if (HAVE_STDBOOL_H)
+  check_symbol_exists(bool stdbool.h HAVE_BOOL)
+  check_symbol_exists(_Bool stdbool.h HAVE__Bool)
+endif (HAVE_STDBOOL_H)
+
+check_symbol_exists(errno errno.h HAVE_ERRNO_DECL)
+check_symbol_exists(va_copy stdarg.h HAVE_VA_COPY)
+check_symbol_exists(__va_copy stdarg.h HAVE___VA_COPY)
+
+###### PROTOTYPES
+
+if (HAVE_DLOPEN)
+    set(CMAKE_REQUIRED_LIBRARIES ${DLFN_LIBRARY})
+    check_prototype_definition(dlopen
+        "void *dlopen(const char* filename, unsigned int flags)"
+        "NULL"
+        "dlfcn.h"
+        DLOPEN_TAKES_UNSIGNED_FLAGS)
+    set(CMAKE_REQUIRED_LIBRARIES)
+endif (HAVE_DLOPEN)
+
+# solaris/irix getpwent_r
+check_prototype_definition(getpwent_r
+    "struct passwd *getpwent_r(struct passwd *src, char *buf, int buflen)"
+    "NULL"
+    "unistd.h;pwd.h"
+    HAVE_SOLARIS_GETPWENT_R)
+
+if (NOT HAVE_SOLARIS_GETPWENT_R)
+    check_prototype_definition(getpwent_r
+        "struct passwd *getpwent_r(struct passwd *src, char *buf, size_t buflen)"
+        "NULL"
+        "unistd.h;pwd.h"
+        HAVE_SOLARIS_IRIX_GETPWENT_R)
+endif (NOT HAVE_SOLARIS_GETPWENT_R)
+
+if (HAVE_SOLARIS_GETPWENT_R OR HAVE_SOLARIS_IRIX_GETPWENT_R)
+    set(SOLARIS_GETPWENT_R 1 CACHE INTERNAL "Have Solaris getpwent_r")
+endif (HAVE_SOLARIS_GETPWENT_R OR HAVE_SOLARIS_IRIX_GETPWENT_R)
+
+# solaris/irix getgrent_r
+check_prototype_definition(getgrent_r
+    "struct group *getgrent_r(struct group *src, char *buf, int buflen)"
+    "NULL"
+    "unistd.h;pwd.h"
+    HAVE_SOLARIS_GETGRENT_R)
+
+if (NOT HAVE_SOLARIS_GETGRENT_R)
+    check_prototype_definition(getgrent_r
+        "struct group *getgrent_r(struct group *src, char *buf, size_t buflen)"
+        "NULL"
+        "unistd.h;pwd.h"
+        HAVE_SOLARIS_IRIX_GETGRENT_R)
+endif (NOT HAVE_SOLARIS_GETGRENT_R)
+
+if (HAVE_SOLARIS_GETGRENT_R OR HAVE_SOLARIS_IRIX_GETGRENT_R)
+    set(SOLARIS_GETPGRNT_R 1 CACHE INTERNAL "Have Solaris getpwent_r")
+endif (HAVE_SOLARIS_GETGRENT_R OR HAVE_SOLARIS_IRIX_GETGRENT_R)
+
+###### COMPILES
+# check for function macro
+set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_PLATFORM_DEFINITIONS})
+check_c_source_compiles("#include <stdio.h>
+  int main(void) {
+  printf(\"%s\", __FUNCTION__);
+  }" HAVE_FUNCTION_MACRO)
+
+# check for func macro
+if (NOT HAVE_FUNCTION_MACRO)
+  check_c_source_compiles("#include <stdio.h>
+    int main(void) {
+    printf(\"%s\", __func__);
+  }" HAVE_func_MACRO)
+endif (NOT HAVE_FUNCTION_MACRO)
+
+# check if open support DIRECT flag
+if (HAVE_FCNTL_H)
+  set(CMAKE_REQUIRED_DEFINITIONS -DHAVE_FCNTL_H=1 ${CMAKE_PLATFORM_DEFINITIONS})
+endif (HAVE_FCNTL_H)
+check_c_source_compiles("#include <unistd.h>
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
+int main(void) {
+int fd = open(\"/dev/null\", O_DIRECT);
+}" HAVE_OPEN_O_DIRECT)
+
+# check for volatile
+check_c_source_compiles("#include <sys/types.h>
+int main(void) {
+volatile int i = 0;
+}" HAVE_VOLATILE)
+
+check_c_source_compiles("#include <sys/time.h>
+#include <time.h>
+int main(void) {}" TIME_WITH_SYS_TIME)
+
+set(CMAKE_REQUIRED_DEFINITIONS) # reset
+
+##### SYSTEM CHECKS
+if (CMAKE_SYSTEM_NAME MATCHES Linux)
+    # check for broken Red Hat 7 system headers
+    set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_PLATFORM_DEFINITIONS})
+    if (HAVE_SYS_VFS_H)
+        set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} -DHAVE_SYS_VFS_H=1)
+    endif (HAVE_SYS_VFS_H)
+    if (HAVE_SYS_CAPABILITY_H)
+        set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} -DHAVE_SYS_CAPABILITY_H=1)
+    endif (HAVE_SYS_CAPABILITY_H)
+    check_c_source_compiles("#ifdef HAVE_SYS_VFS_H
+        #include <sys/vfs.h>
+        #endif
+        #ifdef HAVE_SYS_CAPABILITY_H
+        #include <sys/capability.h>
+        #endif
+        int main(void) {
+          int i;
+        }" CHECK_RH7_SYSTEM_HEADERS)
+    set(BROKEN_REDHAT_7_SYSTEM_HEADERS TRUE)
+    if (CHECK_RH7_SYSTEM_HEADERS)
+       set(BROKEN_REDHAT_7_SYSTEM_HEADERS FALSE)
+    endif (CHECK_RH7_SYSTEM_HEADERS)
+
+    # check for broken RHEL5 capability header
+    check_c_source_compiles("#ifdef HAVE_SYS_CAPABILITY_H
+        #include <sys/capability.h>
+        #endif
+        #include <linux/types.h>
+        int main(void) {
+          __s8 i;
+        }" CHECK_RHEL5_CAP_HEADER)
+    set(BROKEN_RHEL5_SYS_CAP_HEADER TRUE)
+    if (CHECK_RHEL5_CAP_HEADER)
+        set(BROKEN_RHEL5_SYS_CAP_HEADER FALSE)
+    endif (CHECK_RHEL5_CAP_HEADER)
+    set(CMAKE_REQUIRED_DEFINITIONS) # reset
+endif (CMAKE_SYSTEM_NAME MATCHES Linux)
+
+###### RUNS
+set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_PLATFORM_DEFINITIONS})
+
+# check for secure mkstemp
+file(READ ${LIBREPLACE_SOURCE_DIR}/test/mkstemp.c MKSTEMP_SOURCE)
+check_c_source_runs("${MKSTEMP_SOURCE}" HAVE_SECURE_MKSTEMP)
+
+# check for c99 vsnprintf
+file(READ ${LIBREPLACE_SOURCE_DIR}/test/vsnprintf.c VSNPRINTF_SOURCE)
+check_c_source_runs("${VSNPRINTF_SOURCE}" HAVE_C99_VSNPRINTF)
+
+# check for correct mmap
+if (HAVE_UNISTD_H)
+  set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_PLATFORM_DEFINITIONS} -DHAVE_UNISTD_H=1)
+endif (HAVE_UNISTD_H)
+file(READ ${LIBREPLACE_SOURCE_DIR}/test/shared_mmap.c MMAP_SOURCE)
+check_c_source_runs("${MMAP_SOURCE}" HAVE_MMAP)
+
+check_c_source_runs("
+#define HAVE_IFACE_GETIFADDRS 1
+#define NO_CONFIG_H 1
+#define AUTOCONF_TEST 1
+#define SOCKET_WRAPPER_NOT_REPLACE
+#include \"${LIBREPLACE_SOURCE_DIR}/replace.c\"
+#include \"${LIBREPLACE_SOURCE_DIR}/inet_ntop.c\"
+#include \"${LIBREPLACE_SOURCE_DIR}/snprintf.c\"
+#include \"${LIBREPLACE_SOURCE_DIR}/getifaddrs.c\"
+#define getifaddrs_test main
+#include \"${LIBREPLACE_SOURCE_DIR}/test/getifaddrs.c\"" HAVE_IFACE_GETIFADDRS)
+
+set(CMAKE_REQUIRED_DEFINITIONS) #reset
+
+##### TYPES
+set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_PLATFORM_DEFINITIONS})
+
+check_type_size(intptr_t HAVE_INTPTR_T)
+check_type_size(uintptr_t HAVE_UINTPTR_T)
+check_type_size(ptrdiff_t HAVE_PTRDIFF_T)
+
+set(CMAKE_EXTRA_INCLUDE_FILES stdlib.h)
+check_type_size(comparison_fn_t HAVE_COMPARISON_FN_T)
+
+set(CMAKE_EXTRA_INCLUDE_FILES signal.h)
+check_type_size(sig_atomic_t HAVE_SIG_ATOMIC_T_TYPE)
+check_type_size(sigaction HAVE_SIGACTION)
+
+# TODO: this is obsolete in c99 and void should be used ...
+check_signal_type(RETSIGTYPE)
+
+set(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
+check_type_size(socklen_t HAVE_SOCKLEN_T)
+check_type_size(sa_family_t HAVE_FAMILY_T)
+
+set(CMAKE_EXTRA_INCLUDE_FILES netdb.h)
+check_type_size("struct addrinfo" HAVE_STRUCT_ADDRINFO)
+
+set(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
+check_type_size("struct sockaddr" HAVE_STRUCT_SOCKADDR)
+
+set(CMAKE_EXTRA_INCLUDE_FILES "sys/socket.h;sys/types.h;netinet/in.h")
+check_type_size("struct sockaddr_storage" HAVE_STRUCT_SOCKADDR_STORAGE)
+check_type_size("struct sockaddr_in6" HAVE_STRUCT_SOCKADDR_IN6)
+
+set(CMAKE_REQUIRED_DEFINITIONS) #reset
+set(CMAKE_EXTRA_INCLUDE_FILES) # reset
+
+##### STRUCT MEMBERS
+
+# TODO: all network tests
+
+##### ENDIAN
+test_big_endian(WORDS_BIGENDIAN)
+
+##### GETPASS
+
+configure_file(${LIBREPLACE_SOURCE_DIR}/config.h.cmake ${LIBREPLACE_BINARY_DIR}/conftest.h)
+
+set(CMAKE_REQUIRED_INCLUDES ${LIBREPLACE_BINARY_DIR})
+
+if (HAVE_GETPASS AND HAVE_GETPASSPHRASE)
+    # getpass returns <9 chars where getpassphrase returns <265 chars
+    set(REPLACE_GETPASS_BY_GETPASSPHRASE 1)
+    # Whether getpass should be replaced
+    set(REPLACE_GETPASS 1)
+    set(WITH_GETPASS 1)
+else (HAVE_GETPASS AND HAVE_GETPASSPHRASE)
+    # test if getpass should be replaced.
+    # configure_file()
+    check_c_source_compiles("#include \"conftest.h\"
+    #define NO_CONFIG_H
+    #include \"${LIBREPLACE_SOURCE_DIR}/getpass.c\"
+    int main(void) { return 0;}" REPLACE_GETPASS)
+    if (REPLACE_GETPASS)
+      set(WITH_GETPASS 1)
+    endif (REPLACE_GETPASS)
+endif (HAVE_GETPASS AND HAVE_GETPASSPHRASE)
+
+##### STRPTIME
+# test if stptime should be replaced.
+check_c_source_compiles("#include \"conftest.h\"
+#define NO_CONFIG_H
+#define LIBREPLACE_CONFIGURE_TEST_STRPTIME
+#include \"${LIBREPLACE_SOURCE_DIR}/strptime.c\"
+int main(void) { return 0;}" REPLACE_STRPTIME)
+if (REPLACE_STRPTIME)
+  set(WITH_STRPTIME 1)
+endif (REPLACE_STRPTIME)
diff --git a/lib/replace/cmake/Modules/COPYING-CMAKE-SCRIPTS b/lib/replace/cmake/Modules/COPYING-CMAKE-SCRIPTS
new file mode 100644 (file)
index 0000000..53b6b71
--- /dev/null
@@ -0,0 +1,22 @@
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+1. Redistributions of source code must retain the copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+3. The name of the author may not be used to endorse or promote products
+   derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/lib/replace/cmake/Modules/CheckPrototypeDefinition.c.in b/lib/replace/cmake/Modules/CheckPrototypeDefinition.c.in
new file mode 100644 (file)
index 0000000..a97344a
--- /dev/null
@@ -0,0 +1,29 @@
+@CHECK_PROTOTYPE_DEFINITION_HEADER@
+
+static void cmakeRequireSymbol(int dummy, ...) {
+  (void) dummy;
+}
+
+static void checkSymbol(void) {
+#ifndef @CHECK_PROTOTYPE_DEFINITION_SYMBOL@
+  cmakeRequireSymbol(0, &@CHECK_PROTOTYPE_DEFINITION_SYMBOL@);
+#endif
+}
+
+@CHECK_PROTOTYPE_DEFINITION_PROTO@ {
+  return @CHECK_PROTOTYPE_DEFINITION_RETURN@;
+}
+
+#ifdef __CLASSIC_C__
+int main() {
+  int ac;
+  char*av[];
+#else
+int main(int ac, char *av[]) {
+#endif
+  checkSymbol();
+  if (ac > 1000) {
+    return *av[0];
+  }
+  return 0;
+}
diff --git a/lib/replace/cmake/Modules/CheckPrototypeDefinition.cmake b/lib/replace/cmake/Modules/CheckPrototypeDefinition.cmake
new file mode 100644 (file)
index 0000000..3a53f66
--- /dev/null
@@ -0,0 +1,86 @@
+# - Check if the protoype we expect is correct.
+# check_prototype_definition(FUNCTION PROTOTYPE RETURN HEADER VARIABLE)
+#
+#  FUNCTION - The name of the function (used to check if prototype exists)
+#  PROTOTYPE- The prototype to check.
+#  RETURN - The return value of the function.
+#  HEADER - The header files required.
+#  VARIABLE - The variable to store the result.
+#
+# Example:
+#
+# check_prototype_definition(getpwent_r
+#     "struct passwd *getpwent_r(struct passwd *src, char *buf, int buflen)"
+#     "NULL"
+#     "unistd.h;pwd.h"
+#     SOLARIS_GETPWENT_R)
+#
+# The following variables may be set before calling this macro to
+# modify the way the check is run:
+#
+#  CMAKE_REQUIRED_FLAGS = string of compile command line flags
+#  CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
+#  CMAKE_REQUIRED_INCLUDES = list of include directories
+#  CMAKE_REQUIRED_LIBRARIES = list of libraries to link
+
+
+function(CHECK_PROTOTYPE_DEFINITION _FUNCTION _PROTOTYPE _RETURN _HEADER _VARIABLE)
+
+    if ("${_VARIABLE}" MATCHES "^${_VARIABLE}$")
+        set(CHECK_PROTOTYPE_DEFINITION_CONTENT "/* */\n")
+
+        set(CHECK_PROTOTYPE_DEFINITION_FLAGS ${CMAKE_REQUIRED_FLAGS})
+        if (CMAKE_REQUIRED_LIBRARIES)
+          set(CHECK_PROTOTYPE_DEFINITION_LIBS
+              "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
+        else(CMAKE_REQUIRED_LIBRARIES)
+            set(CHECK_PROTOTYPE_DEFINITION_LIBS)
+        endif(CMAKE_REQUIRED_LIBRARIES)
+        if (CMAKE_REQUIRED_INCLUDES)
+            set(CMAKE_SYMBOL_EXISTS_INCLUDES
+                "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}")
+        else(CMAKE_REQUIRED_INCLUDES)
+            set(CMAKE_SYMBOL_EXISTS_INCLUDES)
+        endif(CMAKE_REQUIRED_INCLUDES)
+
+        foreach(_FILE ${_HEADER})
+          set(CHECK_PROTOTYPE_DEFINITION_HEADER
+            "${CHECK_PROTOTYPE_DEFINITION_HEADER}#include <${_FILE}>\n")
+        endforeach(_FILE)
+
+        set(CHECK_PROTOTYPE_DEFINITION_SYMBOL ${_FUNCTION})
+        set(CHECK_PROTOTYPE_DEFINITION_PROTO ${_PROTOTYPE})
+        set(CHECK_PROTOTYPE_DEFINITION_RETURN ${_RETURN})
+
+        #configure_file("${CMAKE_ROOT}/Modules/CheckPrototypeDefinition.c.in"
+        #  "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckPrototypeDefinition.c" @ONLY)
+        configure_file("${CMAKE_MODULE_PATH}/CheckPrototypeDefinition.c.in"
+            "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckPrototypeDefinition.c" @ONLY)
+
+        file(READ ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckPrototypeDefinition.c _SOURCE)
+
+        try_compile(${_VARIABLE}
+          ${CMAKE_BINARY_DIR}
+          ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckPrototypeDefinition.c
+          COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+          CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${CHECK_PROTOTYPE_DEFINITION_FLAGS}
+          "${CHECK_PROTOTYPE_DEFINITION_LIBS}"
+          "${CMAKE_SYMBOL_EXISTS_INCLUDES}"
+          OUTPUT_VARIABLE OUTPUT)
+
+        if (${_VARIABLE})
+            set(${_VARIABLE} 1 CACHE INTERNAL "Have correct prototype for ${_FUNCTION}")
+            message(STATUS "Checking prototype ${_FUNCTION} for ${_VARIABLE} - True")
+            file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+                "Determining if the prototype ${_FUNCTION} exists for ${_VARIABLE} passed with the following output:\n"
+                "${OUTPUT}\n\n")
+        else (${_VARIABLE})
+            message(STATUS "Checking prototype ${_FUNCTION} for ${_VARIABLE} - False")
+            set(${_VARIABLE} 0 CACHE INTERNAL "Have correct prototype for ${_FUNCTION}")
+            file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+                "Determining if the prototype ${_FUNCTION} exists for ${_VARIABLE} failed with the following output:\n"
+                "${OUTPUT}\n\n${_SOURCE}\n\n")
+        endif (${_VARIABLE})
+    endif("${_VARIABLE}" MATCHES "^${_VARIABLE}$")
+
+endfunction(CHECK_PROTOTYPE_DEFINITION)
diff --git a/lib/replace/cmake/Modules/CheckSignalType.c.in b/lib/replace/cmake/Modules/CheckSignalType.c.in
new file mode 100644 (file)
index 0000000..657376c
--- /dev/null
@@ -0,0 +1,20 @@
+#include <sys/types.h>
+#include <signal.h>
+
+#ifdef signal
+# undef signal
+#endif
+
+#ifdef __cplusplus
+extern "C" void (*signal (int, void (*)(int)))(int);
+#else
+void (*signal ()) ();
+#endif
+
+#ifdef __CLASSIC_C__
+int main() {
+#else
+int main(void) {
+#endif
+  return 0;
+}
diff --git a/lib/replace/cmake/Modules/CheckSignalType.cmake b/lib/replace/cmake/Modules/CheckSignalType.cmake
new file mode 100644 (file)
index 0000000..09d9f04
--- /dev/null
@@ -0,0 +1,54 @@
+# - Check for the signal handler return type.
+# CHECK_SIGNAL_TYPE(VARIABLE)
+# Test for the return type of the signal handler defined in <signal.h>
+#
+#  VARIABLE - variable to return result
+#
+# The following variables may be set before calling this macro to
+# modify the way the check is run:
+#
+#  CMAKE_REQUIRED_FLAGS = string of compile command line flags
+#
+
+#=============================================================================
+# Copyright 2010 Andreas Schneider <mail@cynapses.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.
+#=============================================================================
+
+function(CHECK_SIGNAL_TYPE _VARIABLE)
+  if ("${_VARIABLE}" MATCHES "^${_VARIABLE}$")
+      message(STATUS "Check for signal return type in <signal.h>")
+
+      #configure_file(${CMAKE_ROOT}/Module/CheckSignalType.c.in
+      #    ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSignalType.c @ONLY)
+      configure_file(${CMAKE_MODULE_PATH}/CheckSignalType.c.in
+          ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSignalType.c @ONLY)
+      try_compile(CMAKE_TEST_SIGNAL_TYPE
+        ${CMAKE_BINARY_DIR}
+        ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckSignalType.c
+        CMAKE_FLAGS
+          -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILE_FLAGS}
+        OUTPUT_VARIABLE
+          OUTPUT)
+      if (CMAKE_TEST_SIGNAL_TYPE)
+        message(STATUS "Check for signal handler return type 'void' - found")
+        set(${_VARIABLE} void CACHE INTERNAL "signal handler return type")
+
+        file(APPEND ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeOutput.log
+            "Determining if signal handler return type is void passed with "
+            "the following output:\n${OUTPUT}\n\n")
+      else (CMAKE_TEST_SIGNAL_TYPE)
+        message(STATUS "Check for signal handler return type 'void' - not found")
+        set (_VARIABLE int CACHE INTERNAL "signal handler return type")
+        file(APPEND ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeError.log
+            "Determining if signal handler return type is void failed with "
+            "the following output:\n${OUTPUT}\n\n")
+      endif (CMAKE_TEST_SIGNAL_TYPE)
+  endif ("${_VARIABLE}" MATCHES "^${_VARIABLE}$")
+endfunction(CHECK_SIGNAL_TYPE)
diff --git a/lib/replace/cmake/Modules/DefineCMakeDefaults.cmake b/lib/replace/cmake/Modules/DefineCMakeDefaults.cmake
new file mode 100644 (file)
index 0000000..72893c3
--- /dev/null
@@ -0,0 +1,27 @@
+# Always include srcdir and builddir in include path
+# This saves typing ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY} in
+# about every subdir
+# since cmake 2.4.0
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+# Put the include dirs which are in the source or build tree
+# before all other include dirs, so the headers in the sources
+# are prefered over the already installed ones
+# since cmake 2.4.1
+set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON)
+
+# Use colored output
+# since cmake 2.4.0
+set(CMAKE_COLOR_MAKEFILE ON)
+
+# Define the generic version of the libraries here
+set(GENERIC_LIB_VERSION "0.1.0")
+set(GENERIC_LIB_SOVERSION "0")
+
+# Set the default build type to release with debug info
+if (NOT CMAKE_BUILD_TYPE)
+  set(CMAKE_BUILD_TYPE RelWithDebInfo
+    CACHE STRING
+      "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
+  )
+endif (NOT CMAKE_BUILD_TYPE)
diff --git a/lib/replace/cmake/Modules/DefineCompilerFlags.cmake b/lib/replace/cmake/Modules/DefineCompilerFlags.cmake
new file mode 100644 (file)
index 0000000..554b22a
--- /dev/null
@@ -0,0 +1,67 @@
+# define system dependent compiler flags
+
+include(CheckCCompilerFlag)
+
+if (UNIX AND NOT WIN32)
+  if (CMAKE_SYSTEM_NAME MATCHES Linux)
+    set(CMAKE_PLATFORM_DEFINITIONS "-D_XOPEN_SOURCE=500 -D_BSD_SOURCE -D_GNU_SOURCE")
+  endif (CMAKE_SYSTEM_NAME MATCHES Linux)
+
+  if (CMAKE_SYSTEM_NAME MATCHES BSD)
+    set(CMAKE_PLATFORM_DEFINITIONS "-D_GNU_SOURCE")
+  endif (CMAKE_SYSTEM_NAME MATCHES BSD)
+
+  if (CMAKE_COMPILER_IS_GNUCC)
+    # add -Wconversion ?
+    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -pedantic -Wall -Wextra -Wshadow -Wmissing-prototypes -Wdeclaration-after-statement -Wunused -Wfloat-equal -Wpointer-arith -Wwrite-strings -Wformat-security -Wmissing-format-attribute")
+
+    # with -fPIC
+    check_c_compiler_flag("-fPIC" WITH_FPIC)
+    if (WITH_FPIC)
+      add_definitions(-fPIC)
+    endif (WITH_FPIC)
+
+    check_c_compiler_flag("-fstack-protector" WITH_STACK_PROTECTOR)
+    if (WITH_STACK_PROTECTOR)
+      add_definitions(-fstack-protector)
+    endif (WITH_STACK_PROTECTOR)
+
+    check_c_compiler_flag("-D_FORTIFY_SOURCE=2" WITH_FORTIFY_SOURCE)
+    if (WITH_FORTIFY_SOURCE)
+      add_definitions(-D_FORTIFY_SOURCE=2)
+    endif (WITH_FORTIFY_SOURCE)
+
+  endif (CMAKE_COMPILER_IS_GNUCC)
+
+  if (CMAKE_SIZEOF_VOID_P MATCHES "8")
+   # with large file support
+   execute_process(
+     COMMAND
+       getconf LFS64_CFLAGS
+     OUTPUT_VARIABLE
+       _lfs_CFLAGS
+     ERROR_QUIET
+     OUTPUT_STRIP_TRAILING_WHITESPACE
+   )
+ else (CMAKE_SIZEOF_VOID_P MATCHES "8")
+   # with large file support
+   execute_process(
+     COMMAND
+       getconf LFS_CFLAGS
+     OUTPUT_VARIABLE
+       _lfs_CFLAGS
+     ERROR_QUIET
+     OUTPUT_STRIP_TRAILING_WHITESPACE
+   )
+ endif (CMAKE_SIZEOF_VOID_P MATCHES "8")
+ if (_lfs_CFLAGS)
+   string(REGEX REPLACE "[\r\n]" " " "${_lfs_CFLAGS}" "${${_lfs_CFLAGS}}")
+   add_definitions(${_lfs_CFLAGS})
+ endif (_lfs_CFLAGS)
+
+endif (UNIX AND NOT WIN32)
+
+# suppress warning about "deprecated" functions
+if (MSVC)
+  add_definitions(-D_CRT_SECURE_NO_WARNINGS)
+endif (MSVC)
diff --git a/lib/replace/cmake/Modules/DefineInstallationPaths.cmake b/lib/replace/cmake/Modules/DefineInstallationPaths.cmake
new file mode 100644 (file)
index 0000000..e85f4f3
--- /dev/null
@@ -0,0 +1,106 @@
+if (UNIX)
+  IF (NOT APPLICATION_NAME)
+    MESSAGE(STATUS "${PROJECT_NAME} is used as APPLICATION_NAME")
+    SET(APPLICATION_NAME ${PROJECT_NAME})
+  ENDIF (NOT APPLICATION_NAME)
+
+  # Suffix for Linux
+  SET(LIB_SUFFIX
+    CACHE STRING "Define suffix of directory name (32/64)"
+  )
+
+  SET(EXEC_INSTALL_PREFIX
+    "${CMAKE_INSTALL_PREFIX}"
+    CACHE PATH  "Base directory for executables and libraries"
+  )
+  SET(SHARE_INSTALL_PREFIX
+    "${CMAKE_INSTALL_PREFIX}/share"
+    CACHE PATH "Base directory for files which go to share/"
+  )
+  SET(DATA_INSTALL_PREFIX
+    "${SHARE_INSTALL_PREFIX}/${APPLICATION_NAME}"
+    CACHE PATH "The parent directory where applications can install their data")
+
+  # The following are directories where stuff will be installed to
+  SET(BIN_INSTALL_DIR
+    "${EXEC_INSTALL_PREFIX}/bin"
+    CACHE PATH "The ${APPLICATION_NAME} binary install dir (default prefix/bin)"
+  )
+  SET(SBIN_INSTALL_DIR
+    "${EXEC_INSTALL_PREFIX}/sbin"
+    CACHE PATH "The ${APPLICATION_NAME} sbin install dir (default prefix/sbin)"
+  )
+  SET(LIB_INSTALL_DIR
+    "${EXEC_INSTALL_PREFIX}/lib${LIB_SUFFIX}"
+    CACHE PATH "The subdirectory relative to the install prefix where libraries will be installed (default is prefix/lib)"
+  )
+  SET(LIBEXEC_INSTALL_DIR
+    "${EXEC_INSTALL_PREFIX}/libexec"
+    CACHE PATH "The subdirectory relative to the install prefix where libraries will be installed (default is prefix/libexec)"
+  )
+  SET(PLUGIN_INSTALL_DIR
+    "${LIB_INSTALL_DIR}/${APPLICATION_NAME}"
+    CACHE PATH "The subdirectory relative to the install prefix where plugins will be installed (default is prefix/lib/${APPLICATION_NAME})"
+  )
+  SET(INCLUDE_INSTALL_DIR
+    "${CMAKE_INSTALL_PREFIX}/include"
+    CACHE PATH "The subdirectory to the header prefix (default prefix/include)"
+  )
+
+  SET(DATA_INSTALL_DIR
+    "${DATA_INSTALL_PREFIX}"
+    CACHE PATH "The parent directory where applications can install their data (default prefix/share/${APPLICATION_NAME})"
+  )
+  SET(HTML_INSTALL_DIR
+    "${DATA_INSTALL_PREFIX}/doc/HTML"
+    CACHE PATH "The HTML install dir for documentation (default data/doc/html)"
+  )
+  SET(ICON_INSTALL_DIR
+    "${DATA_INSTALL_PREFIX}/icons"
+    CACHE PATH "The icon install dir (default data/icons/)"
+  )
+  SET(SOUND_INSTALL_DIR
+    "${DATA_INSTALL_PREFIX}/sounds"
+    CACHE PATH "The install dir for sound files (default data/sounds)"
+  )
+
+  SET(LOCALE_INSTALL_DIR
+    "${SHARE_INSTALL_PREFIX}/locale"
+    CACHE PATH "The install dir for translations (default prefix/share/locale)"
+  )
+
+  SET(XDG_APPS_DIR
+    "${SHARE_INSTALL_PREFIX}/applications/"
+    CACHE PATH "The XDG apps dir"
+  )
+  SET(XDG_DIRECTORY_DIR
+    "${SHARE_INSTALL_PREFIX}/desktop-directories"
+    CACHE PATH "The XDG directory"
+  )
+
+  SET(SYSCONF_INSTALL_DIR
+    "${EXEC_INSTALL_PREFIX}/etc"
+    CACHE PATH "The ${APPLICATION_NAME} sysconfig install dir (default prefix/etc)"
+  )
+  SET(MAN_INSTALL_DIR
+    "${SHARE_INSTALL_PREFIX}/man"
+    CACHE PATH "The ${APPLICATION_NAME} man install dir (default prefix/man)"
+  )
+  SET(INFO_INSTALL_DIR
+    "${SHARE_INSTALL_PREFIX}/info"
+    CACHE PATH "The ${APPLICATION_NAME} info install dir (default prefix/info)"
+  )
+endif (UNIX)
+
+if (WIN32)
+  # Same same
+  set(BIN_INSTALL_DIR "bin" CACHE PATH "-")
+  set(SBIN_INSTALL_DIR "." CACHE PATH "-")
+  set(LIB_INSTALL_DIR "lib" CACHE PATH "-")
+  set(INCLUDE_INSTALL_DIR "include" CACHE PATH "-")
+  set(PLUGIN_INSTALL_DIR "plugins" CACHE PATH "-")
+  set(HTML_INSTALL_DIR "doc/HTML" CACHE PATH "-")
+  set(ICON_INSTALL_DIR "." CACHE PATH "-")
+  set(SOUND_INSTALL_DIR "." CACHE PATH "-")
+  set(LOCALE_INSTALL_DIR "lang" CACHE PATH "-")
+endif (WIN32)
diff --git a/lib/replace/cmake/Modules/MacroAddCompileFlags.cmake b/lib/replace/cmake/Modules/MacroAddCompileFlags.cmake
new file mode 100644 (file)
index 0000000..a866689
--- /dev/null
@@ -0,0 +1,21 @@
+# - MACRO_ADD_COMPILE_FLAGS(target_name flag1 ... flagN)
+
+# Copyright (c) 2006, Oswald Buddenhagen, <ossi@kde.org>
+# Copyright (c) 2006, Andreas Schneider, <mail@cynapses.org>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+
+macro (MACRO_ADD_COMPILE_FLAGS _target)
+
+  get_target_property(_flags ${_target} COMPILE_FLAGS)
+  if (_flags)
+    set(_flags ${_flags} ${ARGN})
+  else (_flags)
+    set(_flags ${ARGN})
+  endif (_flags)
+
+  set_target_properties(${_target} PROPERTIES COMPILE_FLAGS ${_flags})
+
+endmacro (MACRO_ADD_COMPILE_FLAGS)
diff --git a/lib/replace/cmake/Modules/MacroAddLinkFlags.cmake b/lib/replace/cmake/Modules/MacroAddLinkFlags.cmake
new file mode 100644 (file)
index 0000000..91cad30
--- /dev/null
@@ -0,0 +1,20 @@
+# - MACRO_ADD_LINK_FLAGS(target_name flag1 ... flagN)
+
+# Copyright (c) 2006, Oswald Buddenhagen, <ossi@kde.org>
+# Copyright (c) 2006, Andreas Schneider, <mail@cynapses.org>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+macro (MACRO_ADD_LINK_FLAGS _target)
+
+  get_target_property(_flags ${_target} LINK_FLAGS)
+  if (_flags)
+    set(_flags "${_flags} ${ARGN}")
+  else (_flags)
+    set(_flags "${ARGN}")
+  endif (_flags)
+
+  set_target_properties(${_target} PROPERTIES LINK_FLAGS "${_flags}")
+
+endmacro (MACRO_ADD_LINK_FLAGS)
diff --git a/lib/replace/cmake/Modules/MacroAddPlugin.cmake b/lib/replace/cmake/Modules/MacroAddPlugin.cmake
new file mode 100644 (file)
index 0000000..54f94b4
--- /dev/null
@@ -0,0 +1,29 @@
+#  - MACRO_ADD_PLUGIN(name [WITH_PREFIX] file1 .. fileN)
+#
+#  Create a plugin from the given source files.
+#  If WITH_PREFIX is given, the resulting plugin will have the
+#  prefix "lib", otherwise it won't.
+#
+# Copyright (c) 2006, Alexander Neundorf, <neundorf@kde.org>
+# Copyright (c) 2006, Laurent Montel, <montel@kde.org>
+# Copyright (c) 2006, Andreas Schneider, <mail@cynapses.org>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+
+macro (MACRO_ADD_PLUGIN _target_NAME _with_PREFIX)
+
+  if (${_with_PREFIX} STREQUAL "WITH_PREFIX")
+    set(_first_SRC)
+  else (${_with_PREFIX} STREQUAL "WITH_PREFIX")
+    set(_first_SRC ${_with_PREFIX})
+  endif (${_with_PREFIX} STREQUAL "WITH_PREFIX")
+
+  add_library(${_target_NAME} MODULE ${_first_SRC} ${ARGN})
+
+  if (_first_SRC)
+    set_target_properties(${_target_NAME} PROPERTIES PREFIX "")
+  endif (_first_SRC)
+
+endmacro (MACRO_ADD_PLUGIN _name _sources)
diff --git a/lib/replace/cmake/Modules/MacroCopyFile.cmake b/lib/replace/cmake/Modules/MacroCopyFile.cmake
new file mode 100644 (file)
index 0000000..cee1cae
--- /dev/null
@@ -0,0 +1,33 @@
+# - macro_copy_file(_src _dst)
+# Copies a file to ${_dst} only if ${_src} is different (newer) than ${_dst}
+#
+# Example:
+# macro_copy_file(${CMAKE_CURRENT_SOURCE_DIR}/icon.png ${CMAKE_CURRENT_BINARY_DIR}/.)
+# Copies file icon.png to ${CMAKE_CURRENT_BINARY_DIR} directory
+#
+# Copyright (c) 2006-2007  Wengo
+# Copyright (c) 2006-2008  Andreas Schneider <mail@cynapses.org>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING file.
+
+
+macro (macro_copy_file _src _dst)
+  # Removes all path containing .svn or CVS or CMakeLists.txt during the copy
+  if (NOT ${_src} MATCHES ".*\\.svn|CVS|CMakeLists\\.txt.*")
+
+    if (CMAKE_VERBOSE_MAKEFILE)
+      message(STATUS "Copy file from ${_src} to ${_dst}")
+    endif (CMAKE_VERBOSE_MAKEFILE)
+
+    # Creates directory if necessary
+    get_filename_component(_path ${_dst} PATH)
+    file(MAKE_DIRECTORY ${_path})
+
+    execute_process(
+      COMMAND
+        ${CMAKE_COMMAND} -E copy_if_different ${_src} ${_dst}
+      OUTPUT_QUIET
+    )
+  endif (NOT ${_src} MATCHES ".*\\.svn|CVS|CMakeLists\\.txt.*")
+endmacro (macro_copy_file)
diff --git a/lib/replace/cmake/Modules/MacroEnsureOutOfSourceBuild.cmake b/lib/replace/cmake/Modules/MacroEnsureOutOfSourceBuild.cmake
new file mode 100644 (file)
index 0000000..a2e9480
--- /dev/null
@@ -0,0 +1,17 @@
+# - MACRO_ENSURE_OUT_OF_SOURCE_BUILD(<errorMessage>)
+# MACRO_ENSURE_OUT_OF_SOURCE_BUILD(<errorMessage>)
+
+# Copyright (c) 2006, Alexander Neundorf, <neundorf@kde.org>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+macro (MACRO_ENSURE_OUT_OF_SOURCE_BUILD _errorMessage)
+
+   string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" _insource)
+   if (_insource)
+     message(SEND_ERROR "${_errorMessage}")
+     message(FATAL_ERROR "Remove the file CMakeCache.txt in ${CMAKE_SOURCE_DIR} first.")
+   endif (_insource)
+
+endmacro (MACRO_ENSURE_OUT_OF_SOURCE_BUILD)
diff --git a/lib/replace/cmake/Modules/UseDoxygen.cmake b/lib/replace/cmake/Modules/UseDoxygen.cmake
new file mode 100644 (file)
index 0000000..f6c8220
--- /dev/null
@@ -0,0 +1,133 @@
+# -helper macro to add a "doc" target with CMake build system.
+# and configure doxy.config.in to doxy.config
+#
+# target "doc" allows building the documentation with doxygen/dot on WIN32 and Linux
+# Creates .chm windows help file if MS HTML help workshop
+# (available from http://msdn.microsoft.com/workshop/author/htmlhelp)
+# is installed with its DLLs in PATH.
+#
+#
+# Please note, that the tools, e.g.:
+# doxygen, dot, latex, dvips, makeindex, gswin32, etc.
+# must be in path.
+#
+# Note about Visual Studio Projects:
+# MSVS has its own path environment which may differ from the shell.
+# See "Menu Tools/Options/Projects/VC++ Directories" in VS 7.1
+#
+# author Jan Woetzel 2004-2006
+# www.mip.informatik.uni-kiel.de/~jw
+
+
+FIND_PACKAGE(Doxygen)
+
+IF (DOXYGEN_FOUND)
+
+  # click+jump in Emacs and Visual Studio (for doxy.config) (jw)
+  IF    (CMAKE_BUILD_TOOL MATCHES "(msdev|devenv)")
+    SET(DOXY_WARN_FORMAT "\"$file($line) : $text \"")
+  ELSE  (CMAKE_BUILD_TOOL MATCHES "(msdev|devenv)")
+    SET(DOXY_WARN_FORMAT "\"$file:$line: $text \"")
+  ENDIF (CMAKE_BUILD_TOOL MATCHES "(msdev|devenv)")
+
+  #Build the documentation for libssh developpers if asked
+  IF (WITH_INTERNAL_DOC)
+    SET(CMAKE_INTERNAL_DOC "Yes")
+  ELSE (WITH_INTERNAL_DOC)
+    SET(CMAKE_INTERNAL_DOC "No")
+  ENDIF (WITH_INTERNAL_DOC)
+
+  # we need latex for doxygen because of the formulas
+  FIND_PACKAGE(LATEX)
+  IF    (NOT LATEX_COMPILER)
+    MESSAGE(STATUS "latex command LATEX_COMPILER not found but usually required. You will probably get warnings and user inetraction on doxy run.")
+  ENDIF (NOT LATEX_COMPILER)
+  IF    (NOT MAKEINDEX_COMPILER)
+    MESSAGE(STATUS "makeindex command MAKEINDEX_COMPILER not found but usually required.")
+  ENDIF (NOT MAKEINDEX_COMPILER)
+  IF    (NOT DVIPS_CONVERTER)
+    MESSAGE(STATUS "dvips command DVIPS_CONVERTER not found but usually required.")
+  ENDIF (NOT DVIPS_CONVERTER)
+  FIND_PROGRAM(DOXYGEN_DOT_EXECUTABLE_PATH NAMES dot)
+  IF (DOXYGEN_DOT_EXECUTABLE_PATH)
+    SET(DOXYGEN_DOT_FOUND "YES")
+  ENDIF (DOXYGEN_DOT_EXECUTABLE_PATH)
+
+  IF   (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/doxy.config.in")
+    MESSAGE(STATUS "Generate ${CMAKE_CURRENT_BINARY_DIR}/doxy.config from doxy.config.in")
+    CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/doxy.config.in
+      ${CMAKE_CURRENT_BINARY_DIR}/doxy.config
+      @ONLY )
+    # use (configured) doxy.config from (out of place) BUILD tree:
+    SET(DOXY_CONFIG "${CMAKE_CURRENT_BINARY_DIR}/doxy.config")
+  ELSE (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/doxy.config.in")
+    # use static hand-edited doxy.config from SOURCE tree:
+    SET(DOXY_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/doxy.config")
+    IF   (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/doxy.config")
+      MESSAGE(STATUS "WARNING: using existing ${CMAKE_CURRENT_SOURCE_DIR}/doxy.config instead of configuring from doxy.config.in file.")
+    ELSE (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/doxy.config")
+      IF   (EXISTS "${CMAKE_MODULE_PATH}/doxy.config.in")
+        # using template doxy.config.in
+        MESSAGE(STATUS "Generate ${CMAKE_CURRENT_BINARY_DIR}/doxy.config from doxy.config.in")
+        CONFIGURE_FILE(${CMAKE_MODULE_PATH}/doxy.config.in
+          ${CMAKE_CURRENT_BINARY_DIR}/doxy.config
+          @ONLY )
+        SET(DOXY_CONFIG "${CMAKE_CURRENT_BINARY_DIR}/doxy.config")
+      ELSE (EXISTS "${CMAKE_MODULE_PATH}/doxy.config.in")
+        # failed completely...
+        MESSAGE(SEND_ERROR "Please create ${CMAKE_CURRENT_SOURCE_DIR}/doxy.config.in (or doxy.config as fallback)")
+      ENDIF(EXISTS "${CMAKE_MODULE_PATH}/doxy.config.in")
+
+    ENDIF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/doxy.config")
+  ENDIF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/doxy.config.in")
+
+  ADD_CUSTOM_TARGET(doc ${DOXYGEN_EXECUTABLE} ${DOXY_CONFIG} DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/doxy.config)
+
+  # create a windows help .chm file using hhc.exe
+  # HTMLHelp DLL must be in path!
+  # fallback: use hhw.exe interactively
+  IF    (WIN32)
+    FIND_PACKAGE(HTMLHelp)
+    IF   (HTML_HELP_COMPILER)
+      SET (TMP "${CMAKE_CURRENT_BINARY_DIR}\\doc\\html\\index.hhp")
+      STRING(REGEX REPLACE "[/]" "\\\\" HHP_FILE ${TMP} )
+      # MESSAGE(SEND_ERROR "DBG  HHP_FILE=${HHP_FILE}")
+      ADD_CUSTOM_TARGET(winhelp ${HTML_HELP_COMPILER} ${HHP_FILE})
+      ADD_DEPENDENCIES (winhelp doc)
+
+      IF (NOT TARGET_DOC_SKIP_INSTALL)
+      # install windows help?
+      # determine useful name for output file
+      # should be project and version unique to allow installing
+      # multiple projects into one global directory
+      IF   (EXISTS "${PROJECT_BINARY_DIR}/doc/html/index.chm")
+        IF   (PROJECT_NAME)
+          SET(OUT "${PROJECT_NAME}")
+        ELSE (PROJECT_NAME)
+          SET(OUT "Documentation") # default
+        ENDIF(PROJECT_NAME)
+        IF   (${PROJECT_NAME}_VERSION_MAJOR)
+          SET(OUT "${OUT}-${${PROJECT_NAME}_VERSION_MAJOR}")
+          IF   (${PROJECT_NAME}_VERSION_MINOR)
+            SET(OUT  "${OUT}.${${PROJECT_NAME}_VERSION_MINOR}")
+            IF   (${PROJECT_NAME}_VERSION_PATCH)
+              SET(OUT "${OUT}.${${PROJECT_NAME}_VERSION_PATCH}")
+            ENDIF(${PROJECT_NAME}_VERSION_PATCH)
+          ENDIF(${PROJECT_NAME}_VERSION_MINOR)
+        ENDIF(${PROJECT_NAME}_VERSION_MAJOR)
+        # keep suffix
+        SET(OUT  "${OUT}.chm")
+
+        #MESSAGE("DBG ${PROJECT_BINARY_DIR}/doc/html/index.chm \n${OUT}")
+        # create target used by install and package commands
+        INSTALL(FILES "${PROJECT_BINARY_DIR}/doc/html/index.chm"
+          DESTINATION "doc"
+          RENAME "${OUT}"
+        )
+      ENDIF(EXISTS "${PROJECT_BINARY_DIR}/doc/html/index.chm")
+      ENDIF(NOT TARGET_DOC_SKIP_INSTALL)
+
+    ENDIF(HTML_HELP_COMPILER)
+    # MESSAGE(SEND_ERROR "HTML_HELP_COMPILER=${HTML_HELP_COMPILER}")
+  ENDIF (WIN32)
+ENDIF(DOXYGEN_FOUND)
diff --git a/lib/replace/config.h.cmake b/lib/replace/config.h.cmake
new file mode 100644 (file)
index 0000000..45253a4
--- /dev/null
@@ -0,0 +1,205 @@
+/************************** HEADER FILES *************************/
+
+#cmakedefine HAVE_ACL_LIBACL_H 1
+#cmakedefine HAVE_ARPA_INET_H 1
+#cmakedefine HAVE_COMPAT_H 1
+#cmakedefine HAVE_CRYPT_H 1
+#cmakedefine HAVE_CTYPE_H 1
+#cmakedefine HAVE_DIRENT_H 1
+#cmakedefine HAVE_FCNTL_H 1
+#cmakedefine HAVE_FNMATCH_H 1
+#cmakedefine HAVE_GRP_H 1
+#cmakedefine HAVE_INTTYPES_H 1
+#cmakedefine HAVE_LANGINFO_H 1
+#cmakedefine HAVE_LIMITS_H 1
+#cmakedefine HAVE_LOCALE_H 1
+#cmakedefine HAVE_MNTENT_H 1
+#cmakedefine HAVE_MOUNT_H 1
+#cmakedefine HAVE_NETDB_H 1
+#cmakedefine HAVE_NETINET_IN_H 1
+#cmakedefine HAVE_NETINET_IN_IP_H 1
+#cmakedefine HAVE_NETINET_IN_SYSTM_H 1
+#cmakedefine HAVE_NETINET_IP_H 1
+#cmakedefine HAVE_NETINET_TCP_H 1
+#cmakedefine HAVE_PWD_H 1
+#cmakedefine HAVE_SETJMP_H 1
+#cmakedefine HAVE_SHADOW_H 1
+#cmakedefine HAVE_STDBOOL_H 1
+#cmakedefine HAVE_STDINT_H 1
+#cmakedefine HAVE_STDIO_H 1
+#cmakedefine HAVE_STRING_H 1
+#cmakedefine HAVE_STRINGS_H 1
+#cmakedefine HAVE_STROPTS_H 1
+#cmakedefine HAVE_SYS_ACL_H 1
+#cmakedefine HAVE_SYS_CAPABILITY_H 1
+#cmakedefine HAVE_SYS_FCNTL_H 1
+#cmakedefine HAVE_SYS_FILIO_H 1
+#cmakedefine HAVE_SYS_FILSYS_H 1
+#cmakedefine HAVE_SYS_S5PARAM_H 1
+#cmakedefine HAVE_SYS_ID_H 1
+#cmakedefine HAVE_SYS_IOCTL_H 1
+#cmakedefine HAVE_SYS_IPC_H 1
+#cmakedefine HAVE_SYS_MMAN_H 1
+#cmakedefine HAVE_SYS_MODE_H 1
+#cmakedefine HAVE_SYS_PARAM_H 1
+#cmakedefine HAVE_SYS_PRIV_H 1
+#cmakedefine HAVE_SYS_RESOURCE_H 1
+#cmakedefine HAVE_SYS_SECURITY_H 1
+#cmakedefine HAVE_SYS_SELECT_H 1
+#cmakedefine HAVE_SYS_SHM_H 1
+#cmakedefine HAVE_SYS_SOCKET_H 1
+#cmakedefine HAVE_SYS_SOCKIO_H 1
+#cmakedefine HAVE_SYS_SYSLOG_H 1
+#cmakedefine HAVE_SYS_TERMIO_H 1
+#cmakedefine HAVE_SYS_TIME_H 1
+#cmakedefine HAVE_SYS_UIO_H 1
+#cmakedefine HAVE_SYS_UN_H 1
+#cmakedefine HAVE_SYS_WAIT_H 1
+#cmakedefine HAVE_SYSLOG_H 1
+#cmakedefine HAVE_TERMIO_H 1
+#cmakedefine HAVE_TERMINOS_H 1
+#cmakedefine HAVE_TIME_H 1
+#cmakedefine HAVE_UNISTD_H 1
+#cmakedefine HAVE_UNIX_H 1
+#cmakedefine HAVE_UTIME_H 1
+#cmakedefine HAVE_UTIMES_H 1
+
+/*************************** FUNCTIONS ***************************/
+
+#cmakedefine HAVE___STRTOLL 1
+#cmakedefine HAVE___STRTOULL 1
+#cmakedefine HAVE_ASPRINTF 1
+#cmakedefine HAVE_BZERO 1
+#cmakedefine HAVE_CHOWN 1
+#cmakedefine HAVE_CHROOT 1
+#cmakedefine HAVE_CHSIZE 1
+#cmakedefine HAVE_DUP2 1
+#cmakedefine HAVE_GETIFADDRS 1
+#cmakedefine HAVE_FREEIFADDRS 1
+#cmakedefine HAVE_FTRUNCATE 1
+#cmakedefine HAVE_INET_ATON 1
+#cmakedefine HAVE_INET_NTOP 1
+#cmakedefine HAVE_INET_PTON 1
+#cmakedefine HAVE_INITGROUPS 1
+#cmakedefine HAVE_ISATTY 1
+#cmakedefine HAVE_LCHOWN 1
+#cmakedefine HAVE_LINK 1
+#cmakedefine HAVE_LOCALTIME_R 1
+#cmakedefine HAVE_MEMMOVE 1
+#cmakedefine HAVE_MKDTEMP 1
+#cmakedefine HAVE_MKTIME 1
+#cmakedefine HAVE_PREAD 1
+#cmakedefine HAVE_PWRITE 1
+#cmakedefine HAVE_READLINK 1
+#cmakedefine HAVE_REALPATH 1
+#cmakedefine HAVE_RENAME 1
+#cmakedefine HAVE_SETEGID 1
+#cmakedefine HAVE_SETENV 1
+#cmakedefine HAVE_SETEUID 1
+#cmakedefine HAVE_SETGID 1
+#cmakedefine HAVE_SETLINEBUF 1
+#cmakedefine HAVE_SETRESGID 1
+#cmakedefine HAVE_SETRESUID 1
+#cmakedefine HAVE_SETUID 1
+#cmakedefine HAVE_SNPRINTF 1
+#cmakedefine HAVE_STRCASESTR 1
+#cmakedefine HAVE_STRDUP 1
+#cmakedefine HAVE_STRERROR 1
+#cmakedefine HAVE_STRLCAT 1
+#cmakedefine HAVE_STRLCPY 1
+#cmakedefine HAVE_STRNDUP 1
+#cmakedefine HAVE_STRNDUP 1
+#cmakedefine HAVE_STRNLEN 1
+#cmakedefine HAVE_STRTOK_R 1
+#cmakedefine HAVE_STRTOLL 1
+#cmakedefine HAVE_STROQ 1
+#cmakedefine HAVE_STRTOULL 1
+#cmakedefine HAVE_STRTOUQ 1
+#cmakedefine HAVE_SYMLINK 1
+#cmakedefine HAVE_TIMEGM 1
+#cmakedefine HAVE_UNSETENV 1
+#cmakedefine HAVE_UTIME 1
+#cmakedefine HAVE_UTIMES 1
+#cmakedefine HAVE_VASPRINTF 1
+#cmakedefine HAVE_VSNPRINTF 1
+#cmakedefine HAVE_VSYSLOG 1
+#cmakedefine HAVE_WAIT4 1
+#cmakedefine HAVE_WAITPID 1
+#cmakedefine HAVE_GETPWNAM_R 1
+#cmakedefine HAVE_GETPWUID_R 1
+#cmakedefine HAVE_GETPWENT_R 1
+#cmakedefine HAVE_GETROUPLIST 1
+#cmakedefine HAVE_GETPASS 1
+#cmakedefine HAVE_GETPASSPHRASE 1
+#cmakedefine HAVE_CRYPT 1
+#cmakedefine HAVE_DLOPEN 1
+#cmakedefine HAVE_DLSYM 1
+#cmakedefine HAVE_DLERROR 1
+#cmakedefine HAVE_DLCLOSE 1
+#cmakedefine HAVE_SHL_LOAD 1
+#cmakedefine HAVE_SHL_UNLOAD 1
+#cmakedefine HAVE_SHL_FINDSYM 1
+
+/**************************** SYMBOLS ****************************/
+
+#cmakedefine HAVE_BOOL 1
+#cmakedefine HAVE__Bool 1
+#cmakedefine HAVE_ERRNO_DECL 1
+#cmakedefine HAVE_VA_COPY 1
+#cmakedefine HAVE___VA_COPY 1
+
+/***************************** TYPES *****************************/
+
+#cmakedefine HAVE_INTPTR_T 1
+#cmakedefine HAVE_UINTPTR_T 1
+#cmakedefine HAVE_PTRDIFF_T 1
+
+#cmakedefine HAVE_COMPARISON_FN_T 1
+#cmakedefine HAVE_SIG_ATOMIC_T_TYPE 1
+#cmakedefine HAVE_SIGACTION 1
+
+#cmakedefine RETSIGTYPE @RETSIGTYPE@
+
+#define LIBREPLACE_NETWORK_CHECKS 1
+
+#cmakedefine HAVE_SOCKLEN_T 1
+#cmakedefine HAVE_FAMILY_T 1
+#cmakedefine HAVE_STRUCT_ADDRINFO 1
+#cmakedefine HAVE_STRUCT_SOCKADDR 1
+#cmakedefine HAVE_STRUCT_SOCKADDR_STORAGE 1
+#cmakedefine HAVE_STRUCT_SOCKADDR_IN6 1
+
+/************************** PROTOTYPES ***************************/
+
+#cmakedefine DLOPEN_TAKES_UNSIGNED_FLAGS 1
+#cmakedefine SOLARIS_GETPWENT_R 1
+#cmakedefine SOLARIS_GETPGRNT_R 1
+
+/************************** SPECIALS *****************************/
+
+#cmakedefine HAVE_FUNCTION_MACRO 1
+#cmakedefine HAVE_func_MACRO 1
+#cmakedefine HAVE_OPEN_O_DIRECT 1
+#cmakedefine HAVE_VOLATILE 1
+
+/* system check */
+#cmakedefine BROKEN_REDHAT_7_SYSTEM_HEADERS 1
+#cmakedefine CHECK_RHEL5_CAP_HEADER 1
+
+/* compile checks */
+#cmakedefine HAVE_SECURE_MKSTEMP 1
+#cmakedefine HAVE_C99_VSNPRINTF 1
+#cmakedefine HAVE_MMAP 1
+
+#cmakedefine TIME_WITH_SYS_TIME 1
+
+/*************************** REPLACE *****************************/
+
+#cmakedefine REPLACE_GETPASS 1
+#cmakedefine REPLACE_STRPTIME 1
+
+/*************************** ENDIAN ******************************/
+
+/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
+   significant byte first (like Motorola and SPARC, unlike Intel). */
+#cmakedefine WORDS_BIGENDIAN 1
diff --git a/lib/replace/test/CMakeLists.txt b/lib/replace/test/CMakeLists.txt
new file mode 100644 (file)
index 0000000..37ffb9e
--- /dev/null
@@ -0,0 +1,13 @@
+
+set(replace_test_SRCS
+    main.c
+    testsuite.c
+    os2_delete.c
+    strptime.c
+    getifaddrs.c
+)
+
+include_directories(${LIBREPLACE_PRIVATE_INCLUDE_DIRS})
+
+add_executable(replace_testsuite ${replace_test_SRCS})
+target_link_libraries(replace_testsuite ${LIBREPLACE_LIBRARY})
diff --git a/lib/replace/test/mkstemp.c b/lib/replace/test/mkstemp.c
new file mode 100644 (file)
index 0000000..6917b6a
--- /dev/null
@@ -0,0 +1,15 @@
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+main() {
+  struct stat st;
+  char tpl[20]="/tmp/test.XXXXXX";
+  int fd = mkstemp(tpl);
+  if (fd == -1) exit(1);
+  unlink(tpl);
+  if (fstat(fd, &st) != 0) exit(1);
+  if ((st.st_mode & 0777) != 0600) exit(1);
+  exit(0);
+}
diff --git a/lib/replace/test/vsnprintf.c b/lib/replace/test/vsnprintf.c
new file mode 100644 (file)
index 0000000..0dde737
--- /dev/null
@@ -0,0 +1,31 @@
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+void foo(const char *format, ...) {
+       va_list ap;
+       int len;
+       char buf[20];
+       long long l = 1234567890;
+       l *= 100;
+
+       va_start(ap, format);
+       len = vsnprintf(buf, 0, format, ap);
+       va_end(ap);
+       if (len != 5) exit(1);
+
+       va_start(ap, format);
+       len = vsnprintf(0, 0, format, ap);
+       va_end(ap);
+       if (len != 5) exit(2);
+
+       if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(3);
+
+       if (snprintf(buf, 20, "%lld", l) != 12 || strcmp(buf, "123456789000") != 0) exit(4);
+       if (snprintf(buf, 20, "%zu", 123456789) != 9 || strcmp(buf, "123456789") != 0) exit(5);
+       if (snprintf(buf, 20, "%2\$d %1\$d", 3, 4) != 3 || strcmp(buf, "4 3") != 0) exit(6);
+       if (snprintf(buf, 20, "%s", 0) < 3) exit(7);
+
+       exit(0);
+}
+main() { foo("hello"); }